knife-windows 4.0.0 → 4.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '00669322920507bee3df2da47e879305c6bce383935885fd36975738ea83e50b'
4
- data.tar.gz: 8663a57c66f81c31d9664e3c4345adea612db89ca876f8b951f3d75391861a45
3
+ metadata.gz: 6f7b54f5b7e7859cd0964f315d6665981b2e7fb78776683b52b81a73bacc51e4
4
+ data.tar.gz: e69fe477779128138dca7e45c6839e096f45ebee16861860538d10056ead1c1d
5
5
  SHA512:
6
- metadata.gz: 2eabd372f0cf3fb8b82dcebef93fbaa51fae7b6417bbf3eb2d6b2d76a00c1dc25e1bb9c0f3242cc280c55fb20c6b1bb2a9ab32e0f16468f39ae88b3974ae3439
7
- data.tar.gz: f5e0794d88d5e57bb0aee87212959fe3944b3d124cea70871693b2ccabdf7b980ac3ac5a8ca0c3ea1ecf1160e848de3e22ff0af113dc9e2caee6c4ffb46a3b52
6
+ metadata.gz: 235a3c423f774569de51509ed0f8d717c01afbc66a58a4825091b16ab35987870757860baa35e3ec8767879fb42adea4964a2c11f45ccc6a5509ea116a30dccb
7
+ data.tar.gz: ef2598ce31d29f0bfc5ed933005f1d2b3fbb669d964d3eac5306435c3b3ca59ba9cda9d25e75e256846bc2a91b142a0fa1ff6dce7ce8864584fa3f7f42b28d02
@@ -17,15 +17,11 @@
17
17
  #
18
18
 
19
19
  require "chef/knife"
20
- require_relative "knife_windows_base"
21
20
  require "chef/util/path_helper"
22
21
 
23
22
  class Chef
24
23
  class Knife
25
24
  module BootstrapWindowsBase
26
-
27
- include Chef::Knife::KnifeWindowsBase
28
-
29
25
  # :nodoc:
30
26
  # Would prefer to do this in a rational way, but can't be done b/c of
31
27
  # Mixlib::CLI's design :(
@@ -18,8 +18,7 @@
18
18
 
19
19
  require "chef/knife"
20
20
  require "chef/application"
21
- require "winrm"
22
- require "winrm-elevated"
21
+ autoload :WinRM, "winrm-elevated"
23
22
 
24
23
  class Chef
25
24
  class Knife
@@ -27,8 +27,8 @@ class Chef
27
27
  banner "knife windows cert generate FILE_PATH (options)"
28
28
 
29
29
  deps do
30
- require "openssl"
31
- require "socket"
30
+ require "openssl" unless defined?(OpenSSL)
31
+ require "socket" unless defined?(Socket)
32
32
  end
33
33
 
34
34
  option :hostname,
@@ -98,7 +98,7 @@ class Chef
98
98
  cert.add_extension(ef.create_extension("subjectKeyIdentifier", "hash", false))
99
99
  cert.add_extension(ef.create_extension("authorityKeyIdentifier", "keyid:always", false))
100
100
  cert.add_extension(ef.create_extension("extendedKeyUsage", "1.3.6.1.5.5.7.3.1", false))
101
- cert.sign(rsa_key, OpenSSL::Digest::SHA1.new)
101
+ cert.sign(rsa_key, OpenSSL::Digest.new("SHA1"))
102
102
  @thumbprint = OpenSSL::Digest::SHA1.new(cert.to_der)
103
103
  cert
104
104
  end
@@ -1,5 +1,5 @@
1
1
  # Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
2
- # Copyright:: Copyright (c) 2014-2016 Chef Software, Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,7 @@ class Chef
22
22
  class Knife
23
23
  class WindowsListenerCreate < Knife
24
24
  deps do
25
- require "openssl"
25
+ require "openssl" unless defined?(OpenSSL)
26
26
  end
27
27
 
28
28
  banner "knife windows listener create (options)"
@@ -60,6 +60,10 @@ class Chef
60
60
  passphrase.strip
61
61
  end
62
62
 
63
+ def exitstatus
64
+ $?.exitstatus
65
+ end
66
+
63
67
  def run
64
68
  STDOUT.sync = STDERR.sync = true
65
69
 
@@ -68,7 +72,7 @@ class Chef
68
72
  if config[:cert_install]
69
73
  config[:cert_passphrase] = get_cert_passphrase unless config[:cert_passphrase]
70
74
  result = `powershell.exe -Command " '#{config[:cert_passphrase]}' | certutil -importPFX '#{config[:cert_install]}' AT_KEYEXCHANGE"`
71
- if $?.exitstatus
75
+ if exitstatus
72
76
  ui.info "Certificate installed to Certificate Store"
73
77
  result = `powershell.exe -Command " echo (Get-PfxCertificate #{config[:cert_install]}).thumbprint "`
74
78
  ui.info "Certificate Thumbprint: #{result}"
@@ -88,7 +92,7 @@ class Chef
88
92
  result = `winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname="#{config[:hostname]}";CertificateThumbprint="#{config[:cert_thumbprint]}";Port="#{config[:port]}"}`
89
93
  Chef::Log.debug result
90
94
 
91
- if $?.exitstatus == 0
95
+ if exitstatus == 0
92
96
  ui.info "WinRM listener created with Port: #{config[:port]} and CertificateThumbprint: #{config[:cert_thumbprint]}"
93
97
  else
94
98
  ui.error "Error creating WinRM listener. use -VV for more details."
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module Windows
3
- VERSION = "4.0.0".freeze
3
+ VERSION = "4.0.7".freeze
4
4
  MAJOR, MINOR, TINY = VERSION.split(".")
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Mukta Aphale <mukta.aphale@clogeny.com>
3
- # Copyright:: Copyright (c) 2014-2016 Chef Software, Inc.
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,7 +41,7 @@ describe Chef::Knife::WindowsListenerCreate do
41
41
  @listener.config[:port] = "5986"
42
42
  @listener.config[:basic_auth] = true
43
43
  expect(@listener).to receive(:`).with("winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname=\"host\";CertificateThumbprint=\"CERT-THUMBPRINT\";Port=\"5986\"}")
44
- expect($?).to receive(:exitstatus).and_return(100)
44
+ expect(@listener).to receive(:exitstatus).and_return(100)
45
45
  expect(@listener.ui).to receive(:error).with("Error creating WinRM listener. use -VV for more details.")
46
46
  expect(@listener.ui).to_not receive(:info).with("WinRM listener created with Port: 5986 and CertificateThumbprint: CERT-THUMBPRINT")
47
47
  expect { @listener.run }.to raise_error(SystemExit)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-windows
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Chisamore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -93,12 +93,6 @@ files:
93
93
  - spec/assets/fake_trusted_certs/github.pem
94
94
  - spec/assets/fake_trusted_certs/google.crt
95
95
  - spec/assets/win_fake_trusted_cert_script.txt
96
- - spec/assets/win_template_rendered_with_bootstrap_install_command.txt
97
- - spec/assets/win_template_rendered_with_bootstrap_install_command_on_13_client.txt
98
- - spec/assets/win_template_rendered_without_bootstrap_install_command.txt
99
- - spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt
100
- - spec/assets/win_template_rendered_without_bootstrap_install_command_on_13_client.txt
101
- - spec/assets/win_template_unrendered.txt
102
96
  - spec/data/client.d_00/00-foo.rb
103
97
  - spec/data/client.d_00/foo/bar.rb
104
98
  - spec/data/client.d_01/foo/bar.rb
@@ -129,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
123
  - !ruby/object:Gem::Version
130
124
  version: '0'
131
125
  requirements: []
132
- rubygems_version: 3.0.3
126
+ rubygems_version: 3.1.4
133
127
  signing_key:
134
128
  specification_version: 4
135
129
  summary: Plugin that adds functionality to Chef's Knife CLI for configuring/interacting
@@ -139,12 +133,6 @@ test_files:
139
133
  - spec/assets/fake_trusted_certs/github.pem
140
134
  - spec/assets/fake_trusted_certs/google.crt
141
135
  - spec/assets/win_fake_trusted_cert_script.txt
142
- - spec/assets/win_template_rendered_with_bootstrap_install_command.txt
143
- - spec/assets/win_template_rendered_with_bootstrap_install_command_on_13_client.txt
144
- - spec/assets/win_template_rendered_without_bootstrap_install_command.txt
145
- - spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt
146
- - spec/assets/win_template_rendered_without_bootstrap_install_command_on_13_client.txt
147
- - spec/assets/win_template_unrendered.txt
148
136
  - spec/data/client.d_00/00-foo.rb
149
137
  - spec/data/client.d_00/foo/bar.rb
150
138
  - spec/data/client.d_01/foo/bar.rb
@@ -1,220 +0,0 @@
1
- @rem
2
- @rem Author:: Seth Chisamore (<schisamo@opscode.com>)
3
- @rem Copyright:: Copyright (c) 2011 Opscode, Inc.
4
- @rem License:: Apache License, Version 2.0
5
- @rem
6
- @rem Licensed under the Apache License, Version 2.0 (the "License");
7
- @rem you may not use this file except in compliance with the License.
8
- @rem You may obtain a copy of the License at
9
- @rem
10
- @rem http://www.apache.org/licenses/LICENSE-2.0
11
- @rem
12
- @rem Unless required by applicable law or agreed to in writing, software
13
- @rem distributed under the License is distributed on an "AS IS" BASIS,
14
- @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- @rem See the License for the specific language governing permissions and
16
- @rem limitations under the License.
17
- @rem
18
-
19
- @rem Use delayed environment expansion so that ERRORLEVEL can be evaluated with the
20
- @rem !ERRORLEVEL! syntax which evaluates at execution of the line of script, not when
21
- @rem the line is read. See help for the /E switch from cmd.exe /? .
22
- @setlocal ENABLEDELAYEDEXPANSION
23
-
24
-
25
-
26
- @set BOOTSTRAP_DIRECTORY=C:\chef
27
- @echo Checking for existing directory "%BOOTSTRAP_DIRECTORY%"...
28
- @if NOT EXIST %BOOTSTRAP_DIRECTORY% (
29
- @echo Existing directory not found, creating.
30
- @mkdir %BOOTSTRAP_DIRECTORY%
31
- ) else (
32
- @echo Existing directory found, skipping creation.
33
- )
34
-
35
- > C:\chef\wget.vbs (
36
- echo.url = WScript.Arguments.Named^("url"^)
37
- echo.path = WScript.Arguments.Named^("path"^)
38
- echo.proxy = null
39
- echo.'* Vaguely attempt to handle file:// scheme urls by url unescaping and switching all
40
- echo.'* / into . Also assume that file:/// is a local absolute path and that file://^<foo^>
41
- echo.'* is possibly a network file path.
42
- echo.If InStr^(url, "file://"^) = 1 Then
43
- echo.url = Unescape^(url^)
44
- echo.If InStr^(url, "file:///"^) = 1 Then
45
- echo.sourcePath = Mid^(url, Len^("file:///"^) + 1^)
46
- echo.Else
47
- echo.sourcePath = Mid^(url, Len^("file:"^) + 1^)
48
- echo.End If
49
- echo.sourcePath = Replace^(sourcePath, "/", "\"^)
50
- echo.
51
- echo.Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
52
- echo.If objFSO.Fileexists^(path^) Then objFSO.DeleteFile path
53
- echo.objFSO.CopyFile sourcePath, path, true
54
- echo.Set objFSO = Nothing
55
- echo.
56
- echo.Else
57
- echo.Set objXMLHTTP = CreateObject^("MSXML2.ServerXMLHTTP"^)
58
- echo.Set wshShell = CreateObject^( "WScript.Shell" ^)
59
- echo.Set objUserVariables = wshShell.Environment^("USER"^)
60
- echo.
61
- echo.rem http proxy is optional
62
- echo.rem attempt to read from HTTP_PROXY env var first
63
- echo.On Error Resume Next
64
- echo.
65
- echo.If NOT ^(objUserVariables^("HTTP_PROXY"^) = ""^) Then
66
- echo.proxy = objUserVariables^("HTTP_PROXY"^)
67
- echo.
68
- echo.rem fall back to named arg
69
- echo.ElseIf NOT ^(WScript.Arguments.Named^("proxy"^) = ""^) Then
70
- echo.proxy = WScript.Arguments.Named^("proxy"^)
71
- echo.End If
72
- echo.
73
- echo.If NOT isNull^(proxy^) Then
74
- echo.rem setProxy method is only available on ServerXMLHTTP 6.0+
75
- echo.Set objXMLHTTP = CreateObject^("MSXML2.ServerXMLHTTP.6.0"^)
76
- echo.objXMLHTTP.setProxy 2, proxy
77
- echo.End If
78
- echo.
79
- echo.On Error Goto 0
80
- echo.
81
- echo.objXMLHTTP.open "GET", url, false
82
- echo.objXMLHTTP.send^(^)
83
- echo.If objXMLHTTP.Status = 200 Then
84
- echo.Set objADOStream = CreateObject^("ADODB.Stream"^)
85
- echo.objADOStream.Open
86
- echo.objADOStream.Type = 1
87
- echo.objADOStream.Write objXMLHTTP.ResponseBody
88
- echo.objADOStream.Position = 0
89
- echo.Set objFSO = Createobject^("Scripting.FileSystemObject"^)
90
- echo.If objFSO.Fileexists^(path^) Then objFSO.DeleteFile path
91
- echo.Set objFSO = Nothing
92
- echo.objADOStream.SaveToFile path
93
- echo.objADOStream.Close
94
- echo.Set objADOStream = Nothing
95
- echo.End If
96
- echo.Set objXMLHTTP = Nothing
97
- echo.End If
98
-
99
- )
100
-
101
- > C:\chef\wget.ps1 (
102
- echo.param^(
103
- echo. [String] $remoteUrl,
104
- echo. [String] $localPath
105
- echo.^)
106
- echo.
107
- echo.$ProxyUrl = $env:http_proxy;
108
- echo.$webClient = new-object System.Net.WebClient;
109
- echo.
110
- echo.if ^($ProxyUrl -ne ''^) {
111
- echo. $WebProxy = New-Object System.Net.WebProxy^($ProxyUrl,$true^)
112
- echo. $WebClient.Proxy = $WebProxy
113
- echo.}
114
- echo.
115
- echo.$webClient.DownloadFile^($remoteUrl, $localPath^);
116
-
117
- )
118
-
119
- @rem Determine the version and the architecture
120
-
121
- @FOR /F "usebackq tokens=1-8 delims=.[] " %%A IN (`ver`) DO (
122
- @set WinMajor=%%D
123
- @set WinMinor=%%E
124
- @set WinBuild=%%F
125
- )
126
-
127
- @echo Detected Windows Version %WinMajor%.%WinMinor% Build %WinBuild%
128
-
129
- @set LATEST_OS_VERSION_MAJOR=6
130
- @set LATEST_OS_VERSION_MINOR=3
131
-
132
- @if /i %WinMajor% GTR %LATEST_OS_VERSION_MAJOR% goto VersionUnknown
133
- @if /i %WinMajor% EQU %LATEST_OS_VERSION_MAJOR% (
134
- @if /i %WinMinor% GTR %LATEST_OS_VERSION_MINOR% goto VersionUnknown
135
- )
136
-
137
- goto Version%WinMajor%.%WinMinor%
138
-
139
- :VersionUnknown
140
- @rem If this is an unknown version of windows set the default
141
- @set MACHINE_OS=2008r2
142
- @echo Warning: Unknown version of Windows, assuming default of Windows %MACHINE_OS%
143
- goto architecture_select
144
-
145
- :Version6.0
146
- @set MACHINE_OS=2008
147
- goto architecture_select
148
-
149
- :Version5.2
150
- @set MACHINE_OS=2003r2
151
- goto architecture_select
152
-
153
- :Version6.1
154
- @set MACHINE_OS=2008r2
155
- goto architecture_select
156
-
157
- :Version6.2
158
- @set MACHINE_OS=2012
159
- goto architecture_select
160
-
161
- @rem Currently Windows Server 2012 R2 is treated as equivalent to Windows Server 2012
162
- :Version6.3
163
- goto Version6.2
164
-
165
- :architecture_select
166
- goto Architecture%PROCESSOR_ARCHITEW6432%
167
-
168
- :Architecture
169
- goto Architecture%PROCESSOR_ARCHITECTURE%
170
-
171
- @rem If this is an unknown architecture set the default
172
- @set MACHINE_ARCH=i686
173
- goto install
174
-
175
- :Architecturex86
176
- @set MACHINE_ARCH=i686
177
- goto install
178
-
179
- :Architectureamd64
180
- @set MACHINE_ARCH=x86_64
181
- goto install
182
-
183
- :install
184
- @rem If user has provided the custom installation command for chef-client then execute it
185
- chef-client -o recipe[cbk1::rec2]
186
-
187
- @endlocal
188
-
189
- @echo off
190
-
191
-
192
- echo Writing validation key...
193
-
194
-
195
- echo Validation key written.
196
- @echo on
197
-
198
-
199
-
200
-
201
- > C:\chef\client.rb (
202
- echo.chef_server_url "https://localhost:443"
203
- echo.validation_client_name "chef-validator"
204
- echo.file_cache_path "c:/chef/cache"
205
- echo.file_backup_path "c:/chef/backup"
206
- echo.cache_options ^({:path =^> "c:/chef/cache/checksums", :skip_expires =^> true}^)
207
- echo.# Using default node name ^(fqdn^)
208
- echo.log_level :info
209
- echo.log_location STDOUT
210
-
211
- )
212
-
213
- > C:\chef\first-boot.json (
214
- echo.{"run_list":null}
215
- )
216
-
217
- @echo Starting chef to bootstrap the node...
218
- SET "PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\ruby\bin;C:\opscode\chef\bin;C:\opscode\chef\embedded\bin"
219
- chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json
220
-
@@ -1,220 +0,0 @@
1
- @rem
2
- @rem Author:: Seth Chisamore (<schisamo@opscode.com>)
3
- @rem Copyright:: Copyright (c) 2011 Opscode, Inc.
4
- @rem License:: Apache License, Version 2.0
5
- @rem
6
- @rem Licensed under the Apache License, Version 2.0 (the "License");
7
- @rem you may not use this file except in compliance with the License.
8
- @rem You may obtain a copy of the License at
9
- @rem
10
- @rem http://www.apache.org/licenses/LICENSE-2.0
11
- @rem
12
- @rem Unless required by applicable law or agreed to in writing, software
13
- @rem distributed under the License is distributed on an "AS IS" BASIS,
14
- @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- @rem See the License for the specific language governing permissions and
16
- @rem limitations under the License.
17
- @rem
18
-
19
- @rem Use delayed environment expansion so that ERRORLEVEL can be evaluated with the
20
- @rem !ERRORLEVEL! syntax which evaluates at execution of the line of script, not when
21
- @rem the line is read. See help for the /E switch from cmd.exe /? .
22
- @setlocal ENABLEDELAYEDEXPANSION
23
-
24
-
25
-
26
- @set BOOTSTRAP_DIRECTORY=C:\chef
27
- @echo Checking for existing directory "%BOOTSTRAP_DIRECTORY%"...
28
- @if NOT EXIST %BOOTSTRAP_DIRECTORY% (
29
- @echo Existing directory not found, creating.
30
- @mkdir %BOOTSTRAP_DIRECTORY%
31
- ) else (
32
- @echo Existing directory found, skipping creation.
33
- )
34
-
35
- > C:\chef\wget.vbs (
36
- echo.url = WScript.Arguments.Named^("url"^)
37
- echo.path = WScript.Arguments.Named^("path"^)
38
- echo.proxy = null
39
- echo.'* Vaguely attempt to handle file:// scheme urls by url unescaping and switching all
40
- echo.'* / into . Also assume that file:/// is a local absolute path and that file://^<foo^>
41
- echo.'* is possibly a network file path.
42
- echo.If InStr^(url, "file://"^) = 1 Then
43
- echo.url = Unescape^(url^)
44
- echo.If InStr^(url, "file:///"^) = 1 Then
45
- echo.sourcePath = Mid^(url, Len^("file:///"^) + 1^)
46
- echo.Else
47
- echo.sourcePath = Mid^(url, Len^("file:"^) + 1^)
48
- echo.End If
49
- echo.sourcePath = Replace^(sourcePath, "/", "\"^)
50
- echo.
51
- echo.Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
52
- echo.If objFSO.Fileexists^(path^) Then objFSO.DeleteFile path
53
- echo.objFSO.CopyFile sourcePath, path, true
54
- echo.Set objFSO = Nothing
55
- echo.
56
- echo.Else
57
- echo.Set objXMLHTTP = CreateObject^("MSXML2.ServerXMLHTTP"^)
58
- echo.Set wshShell = CreateObject^( "WScript.Shell" ^)
59
- echo.Set objUserVariables = wshShell.Environment^("USER"^)
60
- echo.
61
- echo.rem http proxy is optional
62
- echo.rem attempt to read from HTTP_PROXY env var first
63
- echo.On Error Resume Next
64
- echo.
65
- echo.If NOT ^(objUserVariables^("HTTP_PROXY"^) = ""^) Then
66
- echo.proxy = objUserVariables^("HTTP_PROXY"^)
67
- echo.
68
- echo.rem fall back to named arg
69
- echo.ElseIf NOT ^(WScript.Arguments.Named^("proxy"^) = ""^) Then
70
- echo.proxy = WScript.Arguments.Named^("proxy"^)
71
- echo.End If
72
- echo.
73
- echo.If NOT isNull^(proxy^) Then
74
- echo.rem setProxy method is only available on ServerXMLHTTP 6.0+
75
- echo.Set objXMLHTTP = CreateObject^("MSXML2.ServerXMLHTTP.6.0"^)
76
- echo.objXMLHTTP.setProxy 2, proxy
77
- echo.End If
78
- echo.
79
- echo.On Error Goto 0
80
- echo.
81
- echo.objXMLHTTP.open "GET", url, false
82
- echo.objXMLHTTP.send^(^)
83
- echo.If objXMLHTTP.Status = 200 Then
84
- echo.Set objADOStream = CreateObject^("ADODB.Stream"^)
85
- echo.objADOStream.Open
86
- echo.objADOStream.Type = 1
87
- echo.objADOStream.Write objXMLHTTP.ResponseBody
88
- echo.objADOStream.Position = 0
89
- echo.Set objFSO = Createobject^("Scripting.FileSystemObject"^)
90
- echo.If objFSO.Fileexists^(path^) Then objFSO.DeleteFile path
91
- echo.Set objFSO = Nothing
92
- echo.objADOStream.SaveToFile path
93
- echo.objADOStream.Close
94
- echo.Set objADOStream = Nothing
95
- echo.End If
96
- echo.Set objXMLHTTP = Nothing
97
- echo.End If
98
-
99
- )
100
-
101
- > C:\chef\wget.ps1 (
102
- echo.param^(
103
- echo. [String] $remoteUrl,
104
- echo. [String] $localPath
105
- echo.^)
106
- echo.
107
- echo.$ProxyUrl = $env:http_proxy;
108
- echo.$webClient = new-object System.Net.WebClient;
109
- echo.
110
- echo.if ^($ProxyUrl -ne ''^) {
111
- echo. $WebProxy = New-Object System.Net.WebProxy^($ProxyUrl,$true^)
112
- echo. $WebClient.Proxy = $WebProxy
113
- echo.}
114
- echo.
115
- echo.$webClient.DownloadFile^($remoteUrl, $localPath^);
116
-
117
- )
118
-
119
- @rem Determine the version and the architecture
120
-
121
- @FOR /F "usebackq tokens=1-8 delims=.[] " %%A IN (`ver`) DO (
122
- @set WinMajor=%%D
123
- @set WinMinor=%%E
124
- @set WinBuild=%%F
125
- )
126
-
127
- @echo Detected Windows Version %WinMajor%.%WinMinor% Build %WinBuild%
128
-
129
- @set LATEST_OS_VERSION_MAJOR=6
130
- @set LATEST_OS_VERSION_MINOR=3
131
-
132
- @if /i %WinMajor% GTR %LATEST_OS_VERSION_MAJOR% goto VersionUnknown
133
- @if /i %WinMajor% EQU %LATEST_OS_VERSION_MAJOR% (
134
- @if /i %WinMinor% GTR %LATEST_OS_VERSION_MINOR% goto VersionUnknown
135
- )
136
-
137
- goto Version%WinMajor%.%WinMinor%
138
-
139
- :VersionUnknown
140
- @rem If this is an unknown version of windows set the default
141
- @set MACHINE_OS=2008r2
142
- @echo Warning: Unknown version of Windows, assuming default of Windows %MACHINE_OS%
143
- goto architecture_select
144
-
145
- :Version6.0
146
- @set MACHINE_OS=2008
147
- goto architecture_select
148
-
149
- :Version5.2
150
- @set MACHINE_OS=2003r2
151
- goto architecture_select
152
-
153
- :Version6.1
154
- @set MACHINE_OS=2008r2
155
- goto architecture_select
156
-
157
- :Version6.2
158
- @set MACHINE_OS=2012
159
- goto architecture_select
160
-
161
- @rem Currently Windows Server 2012 R2 is treated as equivalent to Windows Server 2012
162
- :Version6.3
163
- goto Version6.2
164
-
165
- :architecture_select
166
- goto Architecture%PROCESSOR_ARCHITEW6432%
167
-
168
- :Architecture
169
- goto Architecture%PROCESSOR_ARCHITECTURE%
170
-
171
- @rem If this is an unknown architecture set the default
172
- @set MACHINE_ARCH=i686
173
- goto install
174
-
175
- :Architecturex86
176
- @set MACHINE_ARCH=i686
177
- goto install
178
-
179
- :Architectureamd64
180
- @set MACHINE_ARCH=x86_64
181
- goto install
182
-
183
- :install
184
- @rem If user has provided the custom installation command for chef-client then execute it
185
- chef-client -o recipe[cbk1::rec2]
186
-
187
- @endlocal
188
-
189
- @echo off
190
-
191
-
192
- echo Writing validation key...
193
-
194
-
195
- echo Validation key written.
196
- @echo on
197
-
198
-
199
-
200
-
201
- > C:\chef\client.rb (
202
- echo.chef_server_url "https://localhost:443"
203
- echo.validation_client_name "chef-validator"
204
- echo.file_cache_path "c:/chef/cache"
205
- echo.file_backup_path "c:/chef/backup"
206
- echo.cache_options ^({:path =^> "c:/chef/cache/checksums", :skip_expires =^> true}^)
207
- echo.# Using default node name ^(fqdn^)
208
- echo.log_level :info
209
- echo.log_location STDOUT
210
-
211
- )
212
-
213
- > C:\chef\first-boot.json (
214
- echo.{"run_list":null}
215
- )
216
-
217
- @echo Starting chef to bootstrap the node...
218
- SET "PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\ruby\bin;C:\opscode\chef\bin;C:\opscode\chef\embedded\bin"
219
- chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json
220
-