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

Commit

Permalink
#286: Rework OS detection for unsupported distros (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 authored May 5, 2023
1 parent 7531b06 commit 3f036ae
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
56 changes: 27 additions & 29 deletions src/etc/one-context.d/loc-10-network
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,34 @@ if [ -z "${action}" ] ; then
action="configure"
fi

# update detect_os function if new distro is added
if [ -z "${NETCFG_TYPE}" ] ; then
for id in ${os_id}; do
case "${id}" in
alpine)
NETCFG_TYPE='interfaces'
;;
altlinux)
NETCFG_TYPE='networkd nm'
;;
debian|devuan|ubuntu)
NETCFG_TYPE='interfaces netplan nm networkd'
;;
fedora|centos|rhel|almalinux|ol|rocky)
NETCFG_TYPE='scripts nm networkd'
;;
opensuse*|sles|sled)
NETCFG_TYPE='scripts'
;;
amzn)
NETCFG_TYPE='scripts'
;;
freebsd)
NETCFG_TYPE='bsd'
;;
*)
NETCFG_TYPE='none'
;;
esac
break
done
case "${os_id}" in
alpine)
NETCFG_TYPE='interfaces'
;;
altlinux)
NETCFG_TYPE='networkd nm'
;;
debian|devuan|ubuntu)
NETCFG_TYPE='interfaces netplan nm networkd'
;;
fedora|centos|rhel|almalinux|ol|rocky)
NETCFG_TYPE='scripts nm networkd'
;;
opensuse*|sles|sled)
NETCFG_TYPE='scripts'
;;
amzn)
NETCFG_TYPE='scripts'
;;
freebsd)
NETCFG_TYPE='bsd'
;;
*)
NETCFG_TYPE='none'
;;
esac
else
# trim and lowercase
NETCFG_TYPE=$(echo "$NETCFG_TYPE" | \
Expand Down
14 changes: 13 additions & 1 deletion src/etc/one-context.d/loc-10-network.d/functions
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,21 @@ detect_os()
if [ -f /etc/os-release ] ; then
ID=
ID_LIKE=
LINUX_ID=
# shellcheck disable=SC1091
. /etc/os-release
echo "$ID $ID_LIKE" | tr '[:upper:]' '[:lower:]'

case "$ID" in
# supported distros
alpine|altlinux|debian|devuan|ubuntu|fedora|centos|rhel|almalinux|ol|rocky|opensuse*|sles|sled|amzn|freebsd)
LINUX_ID=$ID
;;
*)
LINUX_ID=$ID_LIKE
;;
esac

echo "$LINUX_ID" | tr '[:upper:]' '[:lower:]'

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

0 comments on commit 3f036ae

Please sign in to comment.