-
Notifications
You must be signed in to change notification settings - Fork 110
/
windows-chef-client-msi.erb
127 lines (97 loc) · 3.52 KB
/
windows-chef-client-msi.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@rem
@rem Author:: Seth Chisamore (<schisamo@opscode.com>)
@rem Copyright:: Copyright (c) 2011 Opscode, Inc.
@rem License:: Apache License, Version 2.0
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@setlocal
<%= "SETX HTTP_PROXY \"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] %>
mkdir <%= bootstrap_directory %>
> <%= bootstrap_directory %>\wget.vbs (
<%= win_wget %>
)
> <%= bootstrap_directory %>\wget.ps1 (
<%= win_wget_ps %>
)
@rem Determine the version and the architecture
FOR /F "tokens=1-8 delims=.[] " %%A IN ('ver') DO (
@set WinMajor=%%D
@set WinMinor=%%E
@set WinBuild=%%F
)
goto Version%WinMajor%.%WinMinor%
@rem If this is an unknown version of windows set the default
@set MACHINE_OS=2008r2
goto architecture
:Version6.0
@set MACHINE_OS=2008
goto architecture
:Version5.2
@set MACHINE_OS=2003r2
goto architecture
:Version6.1
@set MACHINE_OS=2008r2
goto architecture
:Version6.2
@set MACHINE_OS=2012
goto architecture
:architecture
goto Architecture%PROCESSOR_ARCHITECTURE%
@rem If this is an unknown architecture set the default
@set MACHINE_ARCH=i686
goto install
:Architecturex86
@set MACHINE_ARCH=i686
goto install
:Architectureamd64
@set MACHINE_ARCH=x86_64
goto install
:install
@rem Install Chef using chef-client MSI installer
@set "REMOTE_SOURCE_MSI_URL=https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%"
@set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
@set "FALLBACK_QUERY_STRING=&DownloadContext=PowerShell"
cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
@rem Work around issues found in Windows Server 2012 around job objects not respecting WSMAN memory quotas
@rem that cause the MSI download process to exceed the quota even when it is increased by administrators.
@rem Retry the download using a more memory-efficient mechanism that only works if PowerShell is available.
@if ERRORLEVEL 1 (
echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
echo Warning: Retrying download with PowerShell if available
if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
@powershell -ExecutionPolicy Unrestricted -NoProfile -NonInteractive "& '<%= bootstrap_directory %>\wget.ps1' '%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%' '%LOCAL_DESTINATION_MSI_PATH%'"
if NOT ERRORLEVEL 1 (
echo Download succeeded
) else (
echo Failed to download "%REMOTE_SOURCE_MSI_URL%"
echo Subsequent attempt to install the downloaded MSI is likely to fail
)
)
<%= install_chef %>
@endlocal
> <%= bootstrap_directory %>\validation.pem (
<%= validation_key %>
)
<% if @config[:encrypted_data_bag_secret] -%>
> <%= bootstrap_directory %>\encrypted_data_bag_secret (
<%= encrypted_data_bag_secret %>
)
<% end -%>
> <%= bootstrap_directory %>\client.rb (
<%= config_content %>
)
> <%= bootstrap_directory %>\first-boot.json (
<%= run_list %>
)
<%= start_chef %>