/
pywbem_os_setup.bat
executable file
·348 lines (286 loc) · 10.7 KB
/
pywbem_os_setup.bat
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
@rem ---------------------------------------------------------------------------
@rem Script that installs OS-level prerequisites for pywbem on native Windows
@rem
@rem Prerequisite commands for running this script:
@rem python (This script uses the active Python environment, virtual Python
@rem environments are supported)
@rem pip>=8.0.0 (with support for download subcommand, is installed by makefile)
@rem choco (Chocolatey package manager, from https://chocolatey.org)
@rem tar
@rem chmod
@setlocal enableextensions
@echo off
set errorlevel=
set myname=pywbem_os_setup.bat
:: Bit size of the Python env.
if defined PYTHON_ARCH goto arch_defined
python -c "import struct; print('@set PYTHON_ARCH=%%s' %% (struct.Struct('P').size * 8))" >tmp_arch.bat
call tmp_arch.bat
del tmp_arch.bat
:arch_defined
:: Python version
python -c "import sys; print('@set PYTHON_M_VERSION=%%s' %% sys.version_info[0])" >tmp_vers.bat
call tmp_vers.bat
del tmp_vers.bat
echo %myname%: Current Python is: Version %PYTHON_M_VERSION%, %PYTHON_ARCH%-bit
if "%1"=="" goto do_install
if "%1"=="install" goto do_install
if "%1"=="develop" goto do_develop
echo Usage: pywbem_os_setup.bat [develop / install]
goto end
:do_install
echo %myname%:
echo %myname%: ================================================================
echo %myname%:
echo %myname%: Starting with pywbem 1.0.0, the installation of pywbem does not
echo %myname%: need any OS-level prerequisite packages anymore, and therefore
echo %myname%: no longer needs to run the pywbem_os_setup.bat script. Because
echo %myname%: this script cannot determine the version of pywbem, it will
echo %myname%: install the prerequisites needed for pywbem before 1.0.0.
echo %myname%:
echo %myname%: ================================================================
echo %myname%:
echo %myname%: Installing OS-level prerequisite packages for install on platform Windows_native ...
if not exist tmp_pywbem_os_setup mkdir tmp_pywbem_os_setup
pushd tmp_pywbem_os_setup
if not %PYTHON_M_VERSION%==2 goto install_no_py2
where swig >nul
if %errorlevel%==0 (
echo %myname%: Swig is already installed ... showing details
echo where swig
where swig
echo swig -version
swig -version
echo %myname%: Swig is already installed ... skipping
goto done_swig
)
echo %myname%: Installing Swig ...
:: The following installation of swig installs swig but without generating
:: the swig.exe shim file (using GenShim).
:: See GenShim issue https://github.com/chocolatey/shimgen/issues/43
:: Therefore, we install swig in appveyor.yml in order to create the swig.exe
:: shim file.
:: We install it here again for users of pywbem.
:: TODO: Remove the circumvention once it works in pywbem_os_setup.bat.
:: swig 4.0.2 (at least when used with M2Crypto) is missing the swig.swg file,
:: so we stay with 4.0.1.
set _CMD=choco install -y swig --version 4.0.1
:: The following test ensures that this script still works when downloaded standalone.
if exist ..\tools\retry.bat set _CMD=..\tools\retry.bat %_CMD%
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" echo %myname%: Warning: choco returned rc=%_RC%
set _CMD=where swig
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error1
echo %myname%: Done installing Swig
:done_swig
where curl >nul
if %errorlevel%==0 (
echo %myname%: Curl is already installed ... showing details
echo where curl
where curl
echo curl --version
curl --version
echo %myname%: Curl is already installed ... skipping
goto done_curl
)
echo %myname%: Installing Curl ...
set _CMD=choco install -y curl
:: The following test ensures that this script still works when downloaded standalone.
if exist ..\tools\retry.bat set _CMD=..\tools\retry.bat %_CMD%
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" echo %myname%: Warning: choco returned rc=%_RC%
set _CMD=where curl
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error1
echo %myname%: Done installing Curl
:done_curl
where grep >nul
if %errorlevel%==0 (
echo %myname%: Grep is already installed ... showing details
echo where grep
where grep
echo grep --version
grep --version
echo %myname%: Grep is already installed ... skipping
goto done_grep
)
echo %myname%: Installing Grep ...
set _CMD=choco install -y grep
:: The following test ensures that this script still works when downloaded standalone.
if exist ..\tools\retry.bat set _CMD=..\tools\retry.bat %_CMD%
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" echo %myname%: Warning: choco returned rc=%_RC%
set _CMD=where grep
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error1
echo %myname%: Done installing Grep
:done_grep
echo %myname%: Installing Win32OpenSSL ...
:: The version of Win32OpenSSL to be downloaded.
:: Note that the Win32OpenSSL project at https://slproweb.com/ removes
:: the previously available version when a new version is released. Whenever
:: that happens, this version here must be updated.
set _WIN32OPENSSL_VERSION_UNDERSCORED=1_1_1h
set _WIN32OPENSSL_VERSION_DASHED=1-1-1h
:: The bit size of Win32OpenSSL must match the bit size of the Python env.
set _WIN32OPENSSL_BITSIZE=%PYTHON_ARCH%
set _WIN32OPENSSL_BASENAME=Win%_WIN32OPENSSL_BITSIZE%OpenSSL-%_WIN32OPENSSL_VERSION_UNDERSCORED%
set _WIN32OPENSSL_INSTALL_DIR=C:\OpenSSL-%_WIN32OPENSSL_VERSION_DASHED%-Win%_WIN32OPENSSL_BITSIZE%
if exist %_WIN32OPENSSL_INSTALL_DIR% (
echo %myname%: %_WIN32OPENSSL_BASENAME% is already installed in %_WIN32OPENSSL_INSTALL_DIR% ... skipping
goto done_winopenssl
)
if exist %_WIN32OPENSSL_BASENAME%.exe (
echo %myname%: %_WIN32OPENSSL_BASENAME% has already been downloaded - using it.
goto install_winopenssl
)
set _CMD=curl -o %_WIN32OPENSSL_BASENAME%.exe -sSL https://slproweb.com/download/%_WIN32OPENSSL_BASENAME%.exe --retry 3 --retry-connrefused --retry-delay 10
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error1
:: If the web site does not know the file, it returns an HTML page showing an
:: error, and curl succeeds downloading that HTML page.
:: Note: The desired regexp would be "^<html>", but grep 3.0 on Appveyor does
:: not support "^" and the Windows command shell has difficulties with
:: the angle brackets in "<html>".
set _CMD=grep ".html." %_WIN32OPENSSL_BASENAME%.exe
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if "%_RC%"=="0" (
echo %myname%: Error: The %_WIN32OPENSSL_BASENAME%.exe file does not exist on https://slproweb.com.
echo %myname%: The https://slproweb.com web site says:
type %_WIN32OPENSSL_BASENAME%.exe
echo %myname%: End of https://slproweb.com web site
echo %myname%: The most likely reason for this is that a new version of WinOpenSSL has been released.
echo %myname%: You can deal with this as follows:
echo %myname%: - Go to https://slproweb.com - Products - Win32/Win64 OpenSSL
echo %myname%: - Download the latest fix version of %_WIN32OPENSSL_BASENAME%.exe into the current directory.
echo %myname%: That is the version with the same numeric version but a different fix letter.
echo %myname%: - Re-run the pywbem_os_setup.bat script
echo %myname%: Please also open an issue on https://github.com/pywbem/pywbem/issues
rm %_WIN32OPENSSL_BASENAME%.exe
set _RC=1
goto error1
)
:install_winopenssl
:: Downloaded files may not have the execution right.
rem TODO: Find a way to set RX with the built-in icacls to remove dependency on chmod
rem set _CMD=icacls %_WIN32OPENSSL_BASENAME%.exe /grant "*S-1-1-0":F
set _CMD=chmod 755 %_WIN32OPENSSL_BASENAME%.exe
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error1
echo %myname%: ACL permissions of %_WIN32OPENSSL_BASENAME%.exe:
icacls %_WIN32OPENSSL_BASENAME%.exe
:: The installer has a GUI which is suppressed by /silent /verysilent
set _CMD=%_WIN32OPENSSL_BASENAME%.exe /silent /verysilent /suppressmsgboxes /dir="%_WIN32OPENSSL_INSTALL_DIR%"
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error1
echo %myname%: Done installing Win32OpenSSL
:done_winopenssl
pip show M2Crypto >nul 2>nul
if %errorlevel%==0 (
echo %myname%: Python package M2Crypto is already installed ... skipping
goto done_m2crypto
)
set _M2CRYPTO_VERSION=0.31.0
echo %myname%: Installing Python package M2Crypto version %_M2CRYPTO_VERSION% ...
set _CMD=pip download M2Crypto==%_M2CRYPTO_VERSION%
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error1
set _CMD=tar -xz -f M2Crypto-%_M2CRYPTO_VERSION%.tar.gz
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error1
pushd M2Crypto-%_M2CRYPTO_VERSION%
set _CMD=python setup.py build --openssl=%_WIN32OPENSSL_INSTALL_DIR%
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error2
set _CMD=python setup.py bdist_wheel
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error2
echo %myname%: Files in dist:
dir dist
if %PYTHON_ARCH%==32 (
set _ARCH_SUFFIX=win32
) else (
set _ARCH_SUFFIX=win_amd64
)
for %%i in (dist\M2Crypto-%_M2CRYPTO_VERSION%-*.whl) do set _M2CRYPTO_WHEEL=%%i
echo %myname%: File path of wheel archive:
echo %_M2CRYPTO_WHEEL%
set _CMD=pip install %_M2CRYPTO_WHEEL%
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error2
popd
echo %myname%: Done installing Python package M2Crypto
:done_m2crypto
:install_no_py2
popd
goto end
:do_develop
echo %myname%: Installing OS-level prerequisite packages for develop on platform Windows_native ...
where xmllint >nul
if %errorlevel%==0 (
echo %myname%: xmllint is already installed ... showing details
echo where xmllint
where xmllint
echo xmllint --version
xmllint --version
echo %myname%: xmllint is already installed ... skipping
goto done_xmllint
)
echo %myname%: Installing xmllint ...
set _CMD=choco install -y xsltproc
:: The following test ensures that this script still works when downloaded standalone.
if exist tools\retry.bat set _CMD=tools\retry.bat %_CMD%
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" echo %myname%: Warning: choco returned rc=%_RC%
set _CMD=where xmllint
echo %_CMD%
call %_CMD%
set _RC=%errorlevel%
if not "%_RC%"=="0" goto error1
echo %myname%: Done installing xmllint
:done_xmllint
goto end
:error2
popd
:error1
popd
:error
echo %myname%: Error: Command returned rc=%_RC%
exit /b %_RC%
:end
rmdir /q /s tmp_pywbem_os_setup
endlocal
exit /b 0