forked from intel/eth-fast-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_id_and_versionid.sh
executable file
·111 lines (108 loc) · 2.59 KB
/
get_id_and_versionid.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
#!/bin/bash
if [ -f /etc/os-release ]
then
id=$(grep ^ID= /etc/os-release | cut -f2 -d= | cut -f2 -d\")
if [[ "$id" == "sle_hpc" ]]; then
id="sles"
fi
versionid=$(grep ^VERSION_ID= /etc/os-release | cut -f2 -d\")
else
if [ `uname -s` == "Darwin" ]
then
# Apple Mac
rval=apple
else
filelist=`'ls' /etc/*-release | egrep -v lsb | egrep -v os`
rval=""
for file in $filelist
do
if [ -f $file ]
then
rval=`basename $file -release`
if [ $rval = 'SuSE' ]
then
if [ -f /etc/UnitedLinux-release ]
then
rval=UnitedLinux
fi
elif [ $rval = 'centos' ]
then
rval=redhat
elif [ $rval = 'rocky' ]
then
rval=redhat
elif [ $rval = 'almalinux' ]
then
rval=redhat
elif [ $rval = 'circle' ]
then
rval=redhat
elif [ $rval != 'os' ]
then
break
fi
fi
done
fi
case $rval in
redhat)
id=rhel
;;
SuSE)
id=sles
;;
*)
id=""
;;
esac
case $id in
rhel)
if grep -qi advanced /etc/redhat-release
then
rval=`cat /etc/redhat-release | cut -d' ' -f7`
elif grep -qi enterprise /etc/redhat-release
then
# /etc/redhat-release = "Red Hat Enterprise Linux Server release $a.$b ($c)"
rval=`cat /etc/redhat-release | cut -d' ' -f7 | cut -d. -f1`
major=`cat /etc/redhat-release | cut -d' ' -f7 | cut -d. -f1`
minor=`cat /etc/redhat-release | cut -d' ' -f7 | cut -d. -f2`
if [ \( $major -ge 7 -a $minor -ne 0 \) -o \( $major -eq 6 -a $minor -ge 7 \) ]
then
rval=$rval.$minor
fi
elif grep -qi centos /etc/redhat-release
then
# CentOS
rval=`cat /etc/redhat-release | sed -r 's/^.+([[:digit:]])\.([[:digit:]]).+$/\1.\2/'`
elif grep -qi rocky /etc/redhat-release
then
# Rocky Linux
rval=`cat /etc/redhat-release | sed -r 's/^.+([[:digit:]])\.([[:digit:]]).+$/\1.\2/'`
elif grep -qi almalinux /etc/redhat-release
then
# AlmaLinux
rval=`cat /etc/redhat-release | sed -r 's/^.+([[:digit:]])\.([[:digit:]]).+$/\1.\2/'`
elif grep -qi circle /etc/redhat-release
then
# Circle Linux
rval=`cat /etc/redhat-release | sed -r 's/^.+([[:digit:]])\.([[:digit:]]).+$/\1.\2/'`
elif grep -qi scientific /etc/redhat-release
then
# Scientific Linux.
rval=`cat /etc/redhat-release | sed -r 's/^.+([[:digit:]])\.([[:digit:]]).+$/\1.\2/'`
else
rval=`cat /etc/redhat-release | cut -d' ' -f5`
fi
;;
sles)
v1=$(grep VERSION /etc/SuSE-release | cut -d' ' -f3)
v2=$(grep PATCHLEVEL /etc/SuSE-release | cut -d' ' -f3)
rval=${v1}.$v2
;;
*)
rval=""
esac
versionid=$rval
fi
echo $id $versionid
exit 0