drone/app/gitspace/orchestrator/common/script/os_info.sh
Vikyath Harekal 4c278448c4 feat: [CDE-332]: Update the gitspace setup scripts to support more OSes (#2872)
* feat: [CDE-332]: Update the gitspace setup scripts to support more OSes
2024-10-26 11:42:12 +00:00

58 lines
977 B
Bash

# Detect OS type
os() {
uname="$(uname)"
case $uname in
Linux) echo linux ;;
Darwin) echo macos ;;
FreeBSD) echo freebsd ;;
*) echo "$uname" ;;
esac
}
# Detect Linux distro type
distro() {
local os_name
os_name=$(os)
if [ "$os_name" = "macos" ] || [ "$os_name" = "freebsd" ]; then
echo "$os_name"
return
fi
if [ -f /etc/os-release ]; then
(
. /etc/os-release
if [ "${ID_LIKE-}" ]; then
for id_like in $ID_LIKE; do
case "$id_like" in debian | fedora | opensuse | arch)
echo "$id_like"
return
;;
esac
done
fi
echo "$ID"
)
return
fi
}
# Print a human-readable name for the OS/distro
distro_name() {
if [ "$(uname)" = "Darwin" ]; then
echo "macOS v$(sw_vers -productVersion)"
return
fi
if [ -f /etc/os-release ]; then
(
. /etc/os-release
echo "$PRETTY_NAME"
)
return
fi
uname -sr
}