-
Notifications
You must be signed in to change notification settings - Fork 35
/
distro
executable file
·135 lines (129 loc) · 3.61 KB
/
distro
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
#!/bin/bash
#
# This script determines the Linux distribution we are running
# on. It output two words: (1) The distro name and (2) the version
# Example output "UBUNTU 10.04"
# Ubuntu is detected with /etc/lsb-release
SEP=${1:- }
if [ -e /etc/lsb-release ]
then
. /etc/lsb-release
if [ -n "$DISTRIB_ID" -a -n "$DISTRIB_RELEASE" ] ; then
echo "${DISTRIB_ID^^*}$SEP$DISTRIB_RELEASE"
exit 0
fi
fi
# Debian
if [ -e /etc/debian_version ]; then
VERSION=`cat /etc/debian_version`
VERSION=${VERSION%%.*}
if [ $VERSION = 'wheezy/sid' ]; then VERSION="7"; fi
if [ $VERSION = 'jessie/sid' ]; then VERSION="8"; fi
if [ $VERSION = 'stretch/sid' ]; then VERSION="9"; fi
if [ $VERSION = 'buster/sid' ]; then VERSION="10"; fi
if [ $VERSION = 'bullseye/sid' ]; then VERSION="11"; fi
if [ $VERSION = 'bookworm/sid' ]; then VERSION="12"; fi
echo "DEBIAN$SEP$VERSION"
exit 0
fi
# RedHat / CentOS
if [ -e /etc/redhat-release ]
then
# CentOS release 5.4 (Final)
VERSION=$(cat /etc/redhat-release)
if [ "${VERSION:0:6}" = CentOS ]
then
if [ "${VERSION:0:24}" = "CentOS Linux release 6.0" ]; then
echo "CENTOS${SEP}6"
exit 0
elif [ "${VERSION:0:22}" = "CentOS Linux release 7" ]; then
echo "CENTOS${SEP}7"
exit 0
elif [ "${VERSION:0:22}" = "CentOS Linux release 8" ]; then
echo "CENTOS${SEP}8"
exit 0
fi
echo "CENTOS$SEP${VERSION:15:1}"
exit 0
elif [ "${VERSION:0:24}" = "Red Hat Enterprise Linux" ]
then
echo "REDHAT$SEP${VERSION:40:1}"
exit 0
elif [ "${VERSION:0:6}" = "Fedora" ]
then
[[ $VERSION =~ (Fedora release ([0-9]+)) ]] && REL=${BASH_REMATCH[2]} || exit 0
echo "FEDORA$SEP$REL"
exit 0
elif [ "${VERSION:0:5}" = "Rocky" ]
then
[[ $VERSION =~ (Rocky Linux release ([0-9]+)) ]] && REL=${BASH_REMATCH[2]} || exit 0
echo "ROCKY$SEP$REL"
exit 0
fi
fi
# SLES
if [ -e /etc/SuSE-release ]
then
# SLES 11
VERSION=$(sed -rn 's/^VERSION = (.*)/\1/p' < /etc/SuSE-release)
SP=$(sed -rn 's/^PATCHLEVEL = (.*)/\1/p' < /etc/SuSE-release)
if [ "$VERSION" = 11 -a "$SP" = 1 ]
then
echo "SLES$SEP${VERSION}SP1"
exit 0
elif [ "$VERSION" = 11 -a "$SP" = 2 ]
then
echo "SLES$SEP${VERSION}SP2"
exit 0
elif [ "$VERSION" = 11 -a "$SP" = 3 ]
then
echo "SLES$SEP${VERSION}SP3"
exit 0
elif [ "$VERSION" = 11 -a "$SP" = 4 ]
then
echo "SLES$SEP${VERSION}SP4"
exit 0
elif [ "$VERSION" = 10 -a "$SP" = 1 ]
then
echo "SLES$SEP${VERSION}SP1"
exit 0
elif [ "$VERSION" = 10 -a "$SP" = 2 ]
then
echo "SLES$SEP${VERSION}SP2"
exit 0
elif [ "$VERSION" = 11 ]
then
echo "SLES$SEP${VERSION}"
exit 0
elif [ "$VERSION" = 12 ]
then
echo -n "SLES$SEP${VERSION}"
if [ $SP != 0 ]; then
echo "SP$SP"
else
echo
fi
exit 0
elif [ "$VERSION" = 12.1 ]
then
echo "OPENSUSE$SEP${VERSION}"
exit 0
fi
fi
# SLES > 15
if [ -e /etc/os-release ]
then
NAME=$(sed -rn 's/^NAME="(.*)"/\1/p' < /etc/os-release)
if [ "$NAME" = "SLES" ]; then
VERSION=$(sed -rn 's/^VERSION="(.*)"/\1/p' < /etc/os-release)
echo "$NAME$SEP${VERSION/-/}"
exit 0
fi
if [ "$NAME" = "openSUSE Leap" ]; then
NAME="OPENSUSE"
VERSION=$(sed -rn 's/^VERSION="(.*)"/\1/p' < /etc/os-release)
echo "$NAME$SEP${VERSION}"
exit 0
fi
fi
exit 1