@@ -119,72 +119,31 @@ detect_distribution()
119
119
" CentOS " * )
120
120
# Example output for CentOS:
121
121
# CentOS Linux release 7.6.1810 (Core)
122
- VER=" $( echo " $REL " | sed -e ' s/^CentOS.* release \([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' ) "
123
- if ! echo " $VER " | grep -E ' ^[0-9]+\.[0-9]+$' > /dev/null
124
- then
125
- echo " Unknown CentOS version: $VER "
126
- exit 42
127
- fi
128
-
129
122
OS=centos
130
- OS_VERSION=" $VER "
131
- ;;
132
- " Red Hat Enterprise Linux AS release " * )
133
- VER=${REL# Red Hat Enterprise Linux AS release }
134
- case " $VER " in
135
- [0-9]" " * )
136
- MAJOR=${VER%% * }
137
- ;;
138
- * )
139
- echo " Unknown RHEL AS major version: $VER "
140
- exit 42
141
- ;;
142
- esac
143
-
144
- case " $VER " in
145
- * Update" " [0-9]" )" )
146
- MINOR=${VER#* Update }
147
- MINOR=${MINOR% \) } ;;
148
- * )
149
- echo " Unknnown RHEL AS minor version: $VER "
150
- exit 42
151
- ;;
152
- esac
153
-
154
- OS=rhel
155
- OS_VERSION=" $MAJOR .$MINOR "
156
- ;;
157
- " Red Hat Enterprise Linux Server release " * )
158
- VER=${REL# Red Hat Enterprise Linux Server release }
159
- VER=${VER% \( * } ;
160
- if ! echo " $VER " | grep -E ' ^[0-9]+.[0-9]+$' > /dev/null
161
- then
162
- echo " Unknown RHEL Server version: $VER "
163
- exit 42
164
- fi
165
-
166
- OS=rhel
167
- OS_VERSION=" $VER "
168
123
;;
169
-
170
- " Red Hat Enterprise Linux release " * )
171
- VER=${REL# Red Hat Enterprise Linux release }
172
- VER=${VER% \( * } ;
173
- if ! echo " $VER " | grep -E ' ^[0-9]+.[0-9]+$' > /dev/null
174
- then
175
- echo " Unknown RHEL Server version: $VER "
176
- exit 42
177
- fi
178
-
124
+ " Red Hat Enterprise Linux " * )
125
+ # Example output for RHEL:
126
+ # Red Hat Enterprise Linux release 8.10 (Ootpa)
179
127
OS=rhel
180
- OS_VERSION=" $VER "
181
128
;;
182
-
183
129
* )
184
- echo " Unknown RedHat-like distribution : $REL "
130
+ echo " Error: Could not determine Linux distro from /etc/redhat-release : $REL "
185
131
exit 42
186
132
;;
187
133
esac
134
+
135
+ # Common for all of these is that the version number starts just after the
136
+ # substring 'release '. Hence we reset the match (with \K) just after
137
+ # substring and extract the major and minor version.
138
+ version_string=$( echo " $REL " | grep -oP ' release \K\d+\.\d+' )
139
+
140
+ # Make sure we actually found a match
141
+ if [ -z " $version_string " ]; then
142
+ echo " Error: Could not determine version number from /etc/redhat-release: $REL "
143
+ exit 42
144
+ fi
145
+ OS_VERSION=$version_string
146
+
188
147
elif [ -f /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release; then
189
148
# This file was introduced by Linux Standard Base (LSB) which an attempt to
190
149
# standardize the Linux ecosystem. Unfortunately it was not adopted by many
0 commit comments