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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
#! /bin/sh
# Copyright (c) 2015, Citrix Systems
# All rights reserved.
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# Script to write information about the current distribution to stdout or a file.
# Information collected:
# - Distribution name
# - Distribution version (major and minor)
# - Kernel version (uname)
LANG="C"
export LANG
write_to_output()
{
local distro="$1"
local major="$2"
local minor="$3"
local name="$4"
local uname=$(uname -r)
if [ -n "${TEST_RESULT}" ] ; then
MAJOR=$major
MINOR=$minor
DISTRO=$distro
UNAME=$uname
return 0
fi
echo "os_distro=\"${distro}\""
echo "os_majorver=\"${major}\""
echo "os_minorver=\"${minor}\""
echo "os_uname=\"${uname}\""
echo "os_name=\"${name}\""
return 0
}
identify_debian()
{
local debian_version="$1"
local major
local minor
# 3.1
# 4.0
# Ignores testing and unstable which contain ".*/sid".
if [ ! -f "${debian_version}" ] ; then
return 1
fi
eval $(awk -F. '/^[0-9]*\.[0-9]*/ \
{ print "major="$1 ; print "minor="$2 ; exit 0 }' \
"${debian_version}")
if [ -z "${major}" ] && [ -z "${minor}" ] && ! grep -q /sid "${debian_version}" ; then
return 1
fi
write_to_output "debian" "${major}" "${minor}" "Debian $(head -n 1 $debian_version)"
return 0
}
identify_redhat()
{
redhat_release="$1"
local distro
local major
local minor
local beta
# distro=rhel
# Red Hat Enterprise Linux AS release 3 (Taroon Update 6)
# Red Hat Enterprise Linux AS release 3 (Taroon Update 8)
# Red Hat Enterprise Linux AS release 4 (Nahant)
# Red Hat Enterprise Linux AS release 4 (Nahant Update 1)
# Red Hat Enterprise Linux AS release 4 (Nahant Update 2)
# Red Hat Enterprise Linux AS release 4 (Nahant Update 3)
# Red Hat Enterprise Linux AS release 4 (Nahant Update 4)
# Red Hat Enterprise Linux Server release 4.92 (Tikanga)
# Red Hat Enterprise Linux Server release 5 (Tikanga)
# Red Hat Enterprise Linux Server release 5.1 Beta (Tikanga)
# Red Hat Enterprise Linux release 6.0 Beta (Santiago)
# distro=xe-ddk
# \@PRODUCT_BRAND\@ DDK release \@PRODUCT_VERSION\@-\@BUILD_NUMBER\@ (\@PRODUCT_NAME\@)
# Rio DDK release 0.5.6-2991c (xenenterprise)
# distro=xe-sdk
# \@PRODUCT_BRAND\@ SDK release \@PRODUCT_VERSION\@-\@BUILD_NUMBER\@ (\@PRODUCT_NAME\@)
# Rio SDK release 0.5.6-2991c (xenenterprise)
# distro=fedora
# Fedora Core release 3 (Heidelberg)
# distro=centos
# CentOS release 4.0 (Final)
# CentOS release 5 (Final)
# CentOS Linux release 7.0.1406 (Core)
# distro=scientific
# Scientific Linux release 6.5 (Carbon)
# distro=oracle
# Enterprise Linux Enterprise Linux Server release 5 (Carthage)
# Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
# Oracle Linux Server release 5.6
if [ ! -f "${redhat_release}" ] ; then
return 1
fi
eval $(sed -nr \
's/^(.*) DDK release ([^-]*)(-(.*))? (.*)$/distro=xe-ddk;major=\2;minor=\4/gp;' \
"${redhat_release}")
eval $(sed -n \
-e 's/^\(.*\) SDK release \(.*\)-\(.*\) (.*)$/distro=xe-sdk;major=\2;minor=\3/gp;' \
-e 's/^Red Hat Enterprise Linux.* release \([0-9]*\) (.* Update \(.*\))$/distro=rhel;major=\1;minor=\2/gp;'\
-e 's/^Red Hat Enterprise Linux.* release \([0-9]*\) (.*)$/distro=rhel;major=\1/gp;' \
-e 's/^Red Hat Enterprise Linux.* release \([0-9]*\)\.\([0-9]*\) \([Bb]eta \)\?(.*)$/distro=rhel;major=\1;minor=\2;beta=\3;/gp;' \
-e 's/^Fedora.*release \([0-9]*\) (.*)$/distro=fedora;major=\1/gp;' \
-e 's/^CentOS release \([0-9]*\)\.\([0-9]*\) (.*)/distro=centos;major=\1;minor=\2/gp;' \
-e 's/^CentOS release \([0-9]*\) (.*)/distro=centos;major=\1/gp;' \
-e 's/^CentOS Linux release \([0-9]*\)\.\([0-9]*\)\(\.[0-9]*\)\? (.*)/distro=centos;major=\1;minor=\2/gp;' \
-e 's/^Enterprise Linux Enterprise Linux .* release \([0-9]*\)\.\([0-9]*\) (.*)$/distro=oracle;major=\1;minor=\2;/gp;' \
-e 's/^Enterprise Linux Enterprise Linux .* release \([0-9]*\) (.*)$/distro=oracle;major=\1/gp;' \
-e 's/^Oracle Linux Server release \([0-9]*\)\.\([0-9]*\)$/distro=oracle;major=\1;minor=\2/gp;' \
-e 's/^Scientific Linux SL release \([0-9]*\)\.\([0-9]*\) (.*)$/distro=scientific;major=\1;minor=\2;/gp;' \
-e 's/^Scientific Linux release \([0-9]*\)\.\([0-9]*\) (.*)$/distro=scientific;major=\1;minor=\2;/gp;' \
"${redhat_release}")
if [ -z "${major}" -o -z "${distro}" ] ; then
return 1
fi
if [ -z "${minor}" ] ; then
minor=0
fi
# HACK to handle RHEL betas
if [ "${distro}" == "rhel" ] && [ ${minor} -gt 90 ] ; then
major=$(expr ${major} + 1 )
minor=0
beta=Beta
fi
if [ -n "${beta}" ] ; then
minor="${minor}beta"
fi
write_to_output "${distro}" "${major}" "${minor}" "$(head -n 1 ${redhat_release})"
}
identify_sles()
{
suse_release="$1"
local major
local minor
local _major
# SUSE LINUX Enterprise Server 9 (i586)
# VERSION = 9
#
# SUSE LINUX Enterprise Server 9 (i586)
# VERSION = 9
# PATCHLEVEL = 2
#
# SUSE LINUX Enterprise Server 9 (i586)
# VERSION = 9
# PATCHLEVEL = 3
#
# SUSE Linux Enterprise Server 10 (i586)
# VERSION = 10
#
# SUSE Linux Enterprise Server 10 (i586)
# VERSION = 10
# PATCHLEVEL = 1
#
# SUSE Linux Enterprise Server 11 (i586)
# VERSION = 11
# PATCHLEVEL = 0
if [ ! -f "${suse_release}" ] ; then
return 1
fi
eval $(sed -n \
-e 's/^SUSE L\(inux\|INUX\) Enterprise \([a-zA-Z0-9_]*\) \([0-9]*\) (.*)/_major=\3;/gp;' \
-e 's/^VERSION = \([0-9]*\)$/major=\1;/gp;' \
-e 's/^PATCHLEVEL = \([0-9]*\)$/minor=\1;/gp;' \
"${suse_release}")
if [ -z "${major}" -o -z "${_major}" ] ; then
return 1
fi
if [ "${major}" != "${_major}" ] ; then
return 1
fi
if [ -z "${minor}" ] ; then
minor=0
fi
write_to_output "sles" "${major}" "${minor}" "$(head -n 1 ${suse_release})"
}
identify_lsb()
{
lsb_release="$1"
if [ ! -x "${lsb_release}" ] ; then
saved_IFS=$IFS
IFS=:
for i in $PATH ; do
if [ -x "${i}/${lsb_release}" ] ; then
lsb_release="${i}/${lsb_release}"
break
fi
done
IFS=$saved_IFS
fi
if [ -x "${lsb_release}" ] ; then
distro=$(${lsb_release} --short --id | tr 'A-Z' 'a-z')
description=$(${lsb_release} --short --description | sed -e 's/^"\(.*\)"$/\1/g')
release=$(${lsb_release} --short --release)
else
if [ -f /etc/lsb-release ] ; then
source /etc/lsb-release
distro="$DISTRIB_ID"
description="$DISTRIB_DESCRIPTION"
release="$DISTRIB_RELEASE"
else
return 1
fi
fi
if [ -z "${distro}" -o -z "${release}" ] ; then
return 1
fi
eval $(echo $release | awk -F. -- '{ subindex = index($0,"."); \
print "major=\"" $1 "\""; \
print "minor=\"" substr($0,subindex+1) "\"" }')
if [ -z "${major}" -o -z "${distro}" ] ; then
return 1
fi
write_to_output "${distro}" "${major}" "${minor}" "${description}"
}
identify_kylin()
{
kylin_release="$1"
local distro
local major
local minor
# distro
# NeoKylin Linux Advanced Server release 6.5 (Berryllium)
# NeoKylin Linux Advanced Server release 7.0
if [ ! -f "${kylin_release}" ] ; then
return 1
fi
eval $(sed -rn \
's/^NeoKylin Linux Advanced Server release V*([0-9]*)[^0-9]*([0-9]*).*$/distro=neokylin;major=\1;minor=\2;/gp;' \
"${kylin_release}")
if [ -z "${major}" -o -z "${distro}" ] ; then
return 1
fi
if [ -z "${minor}" ] ; then
minor=0
fi
write_to_output "${distro}" "${major}" "${minor}" "$(head -n 1 ${kylin_release})"
}
identify_asianux()
{
asianux_release="$1"
local distro
local major
local minor
# distro
# 'Asianux Server 4.5 (Final)'
# 'Asianux Server 4 (Hiranya SP2)'
# 'Asianux Server 4 (Hiranya SP4)'
if [ ! -f "${asianux_release}" ] ; then
return 1
fi
eval $(sed -rn \
's/^Asianux Server ([0-9]*)\.([0-9]*) .*$/distro=asianux;major=\1;minor=\2;/gp;'`
`'s/^Asianux Server ([0-9]*) \([^0-9]*([0-9]*)\)$/distro=asianux;major=\1;minor=\2;/gp;' \
"${asianux_release}")
if [ -z "${major}" -o -z "${distro}" ] ; then
return 1
fi
if [ -z "${minor}" ] ; then
minor=0
fi
write_to_output "${distro}" "${major}" "${minor}" "$(head -n 1 ${asianux_release})"
}
identify_turbo()
{
turbo_release="$1"
local distro
local major
local minor
# distro
# GreatTurbo Enterprise Server release 12.2 (Theseus)
if [ ! -f "${turbo_release}" ] ; then
return 1
fi
eval $(sed -rn \
's/^GreatTurbo[^0-9]*([0-9]*)\.?([0-9]*)?.*$/distro=turbo;major=\1;minor=\2;/gp;' \
"${turbo_release}")
if [ -z "${major}" -o -z "${distro}" ] ; then
return 1
fi
if [ -z "${minor}" ] ; then
minor=0
fi
write_to_output "${distro}" "${major}" "${minor}" "$(head -n 1 ${turbo_release})"
}
identify_boot2docker()
{
boot2docker_release="$1"
local major
local minor
if [ ! -f "${boot2docker_release}" ] ; then
return 1
fi
major=$(awk -F. '{printf("%s", $1)}' /etc/version)
minor=$(awk -F. '{printf("%s.%s", $2, $3)}' /etc/version)
write_to_output "boot2docker" "${major}" "${minor}" "boot2docker $(head -n 1 /etc/version)"
}
if [ $# -eq 1 ] ; then
exec 1>"$1"
fi
if [ -z "${TEST}" ] ; then
#identify kylin disto before redhat, as kylin has both kylin_release and redhat_release.
identify_asianux /etc/asianux-release && exit 0
identify_turbo /etc/turbo-release && exit 0
identify_kylin /etc/neokylin-release && exit 0
identify_redhat /etc/oracle-release && exit 0
identify_redhat /etc/enterprise-release && exit 0
identify_redhat /etc/centos-release && exit 0
identify_redhat /etc/redhat-release && exit 0
identify_sles /etc/SuSE-release && exit 0
identify_lsb lsb_release && exit 0
identify_debian /etc/debian_version && exit 0
identify_boot2docker /etc/boot2docker && exit 0
if [ $# -eq 1 ] ; then
rm -f "$1"
fi
exit 1
fi
|