Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit 3f036ae

Browse files
authored
#286: Rework OS detection for unsupported distros (#292)
1 parent 7531b06 commit 3f036ae

2 files changed

Lines changed: 40 additions & 30 deletions

File tree

src/etc/one-context.d/loc-10-network

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,34 @@ if [ -z "${action}" ] ; then
2828
action="configure"
2929
fi
3030

31+
# update detect_os function if new distro is added
3132
if [ -z "${NETCFG_TYPE}" ] ; then
32-
for id in ${os_id}; do
33-
case "${id}" in
34-
alpine)
35-
NETCFG_TYPE='interfaces'
36-
;;
37-
altlinux)
38-
NETCFG_TYPE='networkd nm'
39-
;;
40-
debian|devuan|ubuntu)
41-
NETCFG_TYPE='interfaces netplan nm networkd'
42-
;;
43-
fedora|centos|rhel|almalinux|ol|rocky)
44-
NETCFG_TYPE='scripts nm networkd'
45-
;;
46-
opensuse*|sles|sled)
47-
NETCFG_TYPE='scripts'
48-
;;
49-
amzn)
50-
NETCFG_TYPE='scripts'
51-
;;
52-
freebsd)
53-
NETCFG_TYPE='bsd'
54-
;;
55-
*)
56-
NETCFG_TYPE='none'
57-
;;
58-
esac
59-
break
60-
done
33+
case "${os_id}" in
34+
alpine)
35+
NETCFG_TYPE='interfaces'
36+
;;
37+
altlinux)
38+
NETCFG_TYPE='networkd nm'
39+
;;
40+
debian|devuan|ubuntu)
41+
NETCFG_TYPE='interfaces netplan nm networkd'
42+
;;
43+
fedora|centos|rhel|almalinux|ol|rocky)
44+
NETCFG_TYPE='scripts nm networkd'
45+
;;
46+
opensuse*|sles|sled)
47+
NETCFG_TYPE='scripts'
48+
;;
49+
amzn)
50+
NETCFG_TYPE='scripts'
51+
;;
52+
freebsd)
53+
NETCFG_TYPE='bsd'
54+
;;
55+
*)
56+
NETCFG_TYPE='none'
57+
;;
58+
esac
6159
else
6260
# trim and lowercase
6361
NETCFG_TYPE=$(echo "$NETCFG_TYPE" | \

src/etc/one-context.d/loc-10-network.d/functions

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,21 @@ detect_os()
199199
if [ -f /etc/os-release ] ; then
200200
ID=
201201
ID_LIKE=
202+
LINUX_ID=
202203
# shellcheck disable=SC1091
203204
. /etc/os-release
204-
echo "$ID $ID_LIKE" | tr '[:upper:]' '[:lower:]'
205+
206+
case "$ID" in
207+
# supported distros
208+
alpine|altlinux|debian|devuan|ubuntu|fedora|centos|rhel|almalinux|ol|rocky|opensuse*|sles|sled|amzn|freebsd)
209+
LINUX_ID=$ID
210+
;;
211+
*)
212+
LINUX_ID=$ID_LIKE
213+
;;
214+
esac
215+
216+
echo "$LINUX_ID" | tr '[:upper:]' '[:lower:]'
205217

206218
# check for legacy RHEL/CentOS 6
207219
elif [ -f /etc/centos-release ]; then

0 commit comments

Comments
 (0)