xe-linux-distribution 8.86 KB
   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
#! /bin/sh

# Copyright (C) 2009 Citrix Systems Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# 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 -n \
-e 's/^\(.*\) DDK release \(.*\)-\(.*\) (.*)$/distro=xe-ddk;major=\2;minor=\3/gp;' \
-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_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_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