@@ -107,12 +107,18 @@ detect_os()
107
107
export OS OS_VERSION
108
108
}
109
109
110
+ # The uname command does not reveal the specific distribution on Linux. Hence,
111
+ # we'll need to parse it from different files located in the /etc/ directory.
112
+ # Unfortunately, there is no standard across the existing distributions. Thus,
113
+ # this is going to be a bit messy.
110
114
detect_distribution ()
111
115
{
112
116
if [ -f /etc/redhat-release ]; then
113
117
REL=$( cat /etc/redhat-release)
114
118
case " $REL " in
115
119
" CentOS " * )
120
+ # Example output for CentOS:
121
+ # CentOS Linux release 7.6.1810 (Core)
116
122
VER=" $( echo " $REL " | sed -e ' s/^CentOS.* release \([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' ) "
117
123
if ! echo " $VER " | grep -E ' ^[0-9]+\.[0-9]+$' > /dev/null
118
124
then
@@ -180,8 +186,29 @@ detect_distribution()
180
186
;;
181
187
esac
182
188
elif [ -f /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release; then
189
+ # This file was introduced by Linux Standard Base (LSB) which an attempt to
190
+ # standardize the Linux ecosystem. Unfortunately it was not adopted by many
191
+ # Linux distributions. Ubuntu dropped the support for LSB in 2015. However,
192
+ # the /etc/lsb-release file is still available as of Ubuntu 24.
193
+ #
194
+ # It might be naive to assume the file will continue to exist and that the
195
+ # existence of the file is only present in Ubuntu. Hence, if this breaks in
196
+ # the future, you'll know why.
197
+ #
198
+ # Example output of /etc/lsb-release:
199
+ #
200
+ # DISTRIB_ID=Ubuntu
201
+ # DISTRIB_RELEASE=24.04
202
+ # DISTRIB_CODENAME=noble
203
+ # DISTRIB_DESCRIPTION="Ubuntu 24.04.2 LTS"
204
+
205
+ # Get the line containing 'DISTRIB_RELEASE='
183
206
REL=$( grep DISTRIB_RELEASE= /etc/lsb-release)
207
+
208
+ # Remove the 'DISTRIB_RELEASE=' part
184
209
REL=${REL# DISTRIB_RELEASE=}
210
+
211
+ # Verify that we can find a valid version number
185
212
case " $REL " in
186
213
[0-9][0-9].[0-9][0-9])
187
214
;;
@@ -194,6 +221,11 @@ detect_distribution()
194
221
OS=ubuntu
195
222
OS_VERSION=" $REL "
196
223
elif [ -f /etc/debian_version ]; then
224
+ # This file contains only the version number.
225
+ #
226
+ # Example output of /etc/debian_version
227
+ # 12.11
228
+
197
229
REL=$( cat /etc/debian_version)
198
230
if ! echo " $REL " | grep -E ' ^[0-9]+\.[0-9]+(\.[0-9]+)?$' > /dev/null
199
231
then
@@ -233,6 +265,17 @@ detect_distribution()
233
265
elif [ -f /etc/os-release ]; then
234
266
# see https://en.opensuse.org/SDB:Find_openSUSE_version for rules of
235
267
# parsing this file
268
+
269
+ # Example output for /etc/os-release:
270
+ #
271
+ # NAME="SLES"
272
+ # VERSION="12-SP5"
273
+ # VERSION_ID="12.5"
274
+ # PRETTY_NAME="SUSE Linux Enterprise Server 12 SP5"
275
+ # ID="sles"
276
+ # ANSI_COLOR="0;32"
277
+ # CPE_NAME="cpe:/o:suse:sles:12:sp5"
278
+
236
279
os=" $( sh -c " . /etc/os-release; echo \$ ID" ) "
237
280
ver=" $( sh -c " . /etc/os-release; echo \$ VERSION_ID" ) "
238
281
if [ " $os " = " sles" ]; then
0 commit comments