Skip to content

Instantly share code, notes, and snippets.

@dreiggy
Last active July 15, 2020 13:30
Show Gist options
  • Save dreiggy/f601d42d219712bb0daad3d159ffe0f6 to your computer and use it in GitHub Desktop.
Save dreiggy/f601d42d219712bb0daad3d159ffe0f6 to your computer and use it in GitHub Desktop.
# Check OS and VERSION
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$ID
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
OS=Suse
VER=$(cat /etc/SuSe-release)
elif [ -f /etc/redhat-release ]; then
OS=redhad
VER=$(cat /etc/redhat-release)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment