-
Notifications
You must be signed in to change notification settings - Fork 26
/
pywbem_os_setup.sh
executable file
·350 lines (314 loc) · 10.6 KB
/
pywbem_os_setup.sh
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
349
350
#!/bin/bash
#
# (C) Copyright 2017 IBM Corp.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author: Andreas Maier <maiera@de.ibm.com>
#
# Script that installs OS-level prerequisites for pywbem on Linux, MacOS, and
# Windows with UNIX-like environments (Cygwin).
#
# Prerequisite commands for running this script:
# python (This script uses the active Python environment, virtual Python
# environments are supported)
# pip (with support for download subcommand, is installed by makefile)
# uname
# The package installer for your OS (yum, dnf, apt, zypper, brew, ...)
arg1="${1:-install}"
arg2="${2:-}"
myname=$(basename $0)
if [[ "$arg1" == "--help" || "$arg1" == "-h" ]]; then
echo ""
echo "$myname: Install OS-level packages needed by pywbem."
echo ""
echo "Usage:"
echo " $myname [PURPOSE]"
echo ""
echo "Where:"
echo " PURPOSE Purpose of the OS-level package installation, with values:"
echo " install: Packages needed for installing pywbem (default)."
echo " develop: Additional packages needed for developing pywbem."
echo ""
exit 2
fi
if [[ "$arg2" != "" ]]; then
echo "$myname: Error: Too many arguments; Invoke with --help for usage." >&2
exit 2
fi
purpose="$arg1"
if [[ "$purpose" != "install" && "$purpose" != "develop" ]]; then
echo "$myname: Error: Invalid purpose: $purpose; Invoke with --help for usage." >&2
exit 2
fi
if [[ "$purpose" == "install" ]]; then
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.sh 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:"
fi
function run_cmd() {
cmd="$1"
echo "$cmd"
eval "$cmd"
rc=$?
if [[ $rc != 0 ]]; then
echo "$myname: Error: Command failed with rc=$rc: $cmd"
exit 2
fi
}
function install_redhat() {
installer="$1"
pkg="$2"
echo "$myname: Installing package: $pkg"
run_cmd "sudo $installer -y install $pkg"
run_cmd "sudo $installer list installed $pkg"
echo "$myname: Done installing package: $pkg"
}
function install_debian() {
pkg="$1"
echo "$myname: Installing package: $pkg"
# Note: The python:2.7.18-buster Docker container has no sudo
apt -qq list $pkg
if [[ "$(apt -qq list $pkg)" != *"installed"* ]]; then
if which sudo >/dev/null; then
echo "Installing $pkg package"
run_cmd "sudo apt-get --yes install $pkg"
run_cmd "sudo apt list --installed | grep $pkg"
else
echo "Warning: Not installing $pkg package due to missing sudo"
fi
else
echo "$pkg package is already installed"
fi
echo "$myname: Done installing package: $pkg"
}
function install_suse() {
pkg="$1"
echo "$myname: Installing package: $pkg"
run_cmd "sudo zypper install -y $pkg"
run_cmd "sudo zypper pa -i | grep $pkg"
echo "$myname: Done installing package: $pkg"
}
function install_osx() {
pkg="$1"
echo "$myname: Upgrading or installing package: $pkg"
run_cmd "brew upgrade $pkg || brew install $pkg"
run_cmd "brew info $pkg"
echo "$myname: Done installing package: $pkg"
}
function install_cygwin() {
pkg="$1"
echo "$myname: Installing package: $pkg"
if [[ "$(uname -m)" == "x86_64" ]]; then
run_cmd "/cygdrive/c/cygwin64/setup-x86_64.exe --no-shortcuts --quiet-mode --packages $pkg"
else
run_cmd "/cygdrive/c/cygwin/setup-x86.exe --no-shortcuts --quiet-mode --packages $pkg"
fi
echo "$myname: Done installing package: $pkg"
}
if [[ "$OS" == "Windows_NT" ]]; then
# Note: Native Windows and CygWin are hard to distinguish: The native Windows
# envvars are set in CygWin as well. Using uname will display CYGWIN_NT-.. on
# both platforms. If the CygWin make is used on native Windows, most of the
# CygWin behavior is then visible in context of that make (e.g. a SHELL envvar
# is set, the PATH envvar gets converted to UNIX syntax, execution of batch
# files requires execute permission, etc.).
if [[ -n $PWD ]]; then
distro_id="cygwin"
distro_family="cygwin"
platform="Windows_CygWin"
else
distro_id="windows"
distro_family="windows"
platform="Windows_native"
fi
# If you need support for more Unix-like environments on Windows (e.g. MinGW)
# please provide the code for detecting them here.
elif [[ "$(uname -s)" == "Linux" ]]; then
distro_id=$(python -c "import distro; print(distro.id())" 2>/dev/null)
if [[ $? != 0 ]]; then
echo "$myname: Installing the Python 'distro' package into the current Python environment."
pip install distro
if [[ $? != 0 ]]; then
echo "$myname: Error: Cannot install Python 'distro' package into current Python environment." >&2
exit 1
fi
distro_id=$(python -c "import distro; print(distro.id())")
fi
if [[ -z $distro_id ]]; then
echo "$myname: Error: Cannot determine Linux distro." >&2
exit 1
fi
case $distro_id in
rhel|centos|fedora)
distro_family="redhat";;
debian|ubuntu)
distro_family="debian";;
sles|opensuse)
distro_family="suse";;
*)
distro_family=$distro_id;;
esac
platform="Linux (distro: $distro_id, family: $distro_family)"
elif [[ "$(uname -s)" == "Darwin" ]]; then
distro_id="osx"
distro_family=$distro_id
platform="OS-X"
else
echo "$myname: Error: Cannot determine operating system. Diagnostic info:" >&2
echo ". uname -a: $(uname -a)" >&2
echo ". uname -s: $(uname -s)" >&2
echo ". OS env.var: $OS" >&2
exit 1
fi
py_m=$(python -c "import sys; print(sys.version_info[0])")
py_mn=$(python -c "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))")
echo "$myname: Installing OS-level prerequisite packages for $purpose on platform ${platform}..."
if [[ "$distro_family" == "redhat" ]]; then
if which dnf >/dev/null 2>/dev/null; then
installer=dnf
else
installer=yum
fi
echo "$myname: Using installer: $installer"
if [[ "$installer" == "dnf" ]]; then
sudo $installer makecache
else
sudo $installer makecache fast
fi
if [[ "$purpose" == "install" ]]; then
if [[ "$py_m" == "2" ]]; then
# For M2Crypto:
install_redhat $installer openssl-devel
install_redhat $installer gcc-c++
install_redhat $installer swig
install_redhat $installer python-devel
fi
fi
if [[ "$purpose" == "develop" ]]; then
# For lxml:
install_redhat $installer libxml2
install_redhat $installer libxslt
fi
elif [[ "$distro_family" == "debian" ]]; then
sudo apt-get --quiet update
if [[ "$purpose" == "install" ]]; then
if [[ "$py_m" == "2" ]]; then
# For M2Crypto:
install_debian libssl-dev
install_debian g++
install_debian swig
install_debian python-dev
fi
fi
if [[ "$purpose" == "develop" ]]; then
# For lxml:
install_debian libxml2-utils
install_debian libxslt1-dev
fi
elif [[ "$distro_family" == "suse" ]]; then
sudo zypper refresh
if [[ "$purpose" == "install" ]]; then
if [[ "$py_m" == "2" ]]; then
# For M2Crypto:
install_suse openssl-devel
install_suse gcc-c++
install_suse swig
install_suse python-devel
fi
fi
if [[ "$purpose" == "develop" ]]; then
# For lxml:
install_suse libxml2
install_suse libxslt
fi
elif [[ "$distro_family" == "osx" ]]; then
if [[ "$purpose" == "install" ]]; then
# Python devel seems to be part of the python package.
if [[ "$py_m" == "2" ]]; then
# For M2Crypto:
install_osx openssl
install_osx gcc
install_osx swig
fi
fi
if [[ "$purpose" == "develop" ]]; then
# For lxml:
install_osx libxml2
install_osx libxslt
fi
elif [[ "$distro_family" == "windows" ]]; then
if [[ "$purpose" == "install" ]]; then
echo "$myname: Invoking 'pywbem_os_setup.bat install' on platform ${platform}." >&2
cmd /d /c pywbem_os_setup.bat install
fi
if [[ "$purpose" == "develop" ]]; then
echo "$myname: Invoking 'pywbem_os_setup.bat develop' on platform ${platform}." >&2
cmd /d /c pywbem_os_setup.bat develop
fi
elif [[ "$distro_family" == "cygwin" ]]; then
if [[ "$purpose" == "install" ]]; then
if [[ "$py_m" == "2" ]]; then
# For M2Crypto:
install_cygwin openssl
install_cygwin libssl-devel
install_cygwin openssl-devel
install_cygwin gcc
install_cygwin swig
# For M2Crypto, pyzmq (used by Jupyter), lxml:
install_cygwin python2-devel
install_cygwin python2-cython
fi
fi
if [[ "$purpose" == "develop" ]]; then
# For lxml:
install_cygwin libxml2
install_cygwin libxslt
install_cygwin libxml2-devel
install_cygwin libxslt-devel
install_cygwin libcrypt-devel
# For pyzmq (used by Jupyter):
install_cygwin libzmq-devel
install_cygwin libffi-devel
if [[ "$py_m" == "2" ]]; then
# For pyzmq (used by Jupyter), lxml:
install_cygwin python2-devel
install_cygwin python2-cython
fi
if [[ "$py_m" == "3" ]]; then
# For pyzmq, lxml:
install_cygwin python3-devel
install_cygwin python3-cython
fi
fi
else
echo "$myname: Warning: Installation of OS-level packages not supported on platform ${platform}." >&2
echo ". The equivalent packages for the Linux RedHat family are:" >&2
echo ". For installing pywbem:" >&2
echo ". * openssl-devel (at least 1.0.1, only on Python 2)" >&2
echo ". * gcc-c++ (at least 4.4, only on Python 2)" >&2
echo ". * swig (>=2.0.0, only on Python 2)" >&2
echo ". * python-devel (only on Python 2" >&2
echo ". In addition, for developing pywbem:" >&2
echo ". * libxml2 (>=2.7.0,!=2.7.4,!=2.7.5,!=2.7.6 on Python 2 and 3)" >&2
fi