Skip to content

Instantly share code, notes, and snippets.

@pbanaszkiewicz
Last active December 21, 2015 21:29
Show Gist options
  • Save pbanaszkiewicz/6368418 to your computer and use it in GitHub Desktop.
Save pbanaszkiewicz/6368418 to your computer and use it in GitHub Desktop.
Detect Linux operating system distribution, it's version and architecture (only Ubuntu, Debian and CentOS).
lsb_release='/usr/bin/lsb_release'
architecture=`uname -i`
os='unknown'
if [ -x $lsb_release ]; then
# we pull in default values, should work for both Debian and Ubuntu
os=`$lsb_release -s -i | tr "[:upper:]" "[:lower:]"`
if [ "$OS" == "centos" ]; then
os_codename=`$lsb_release -s -r | sed -e 's/\..*//'`
else
os_codename=`$lsb_release -s -c | tr "[:upper:]" "[:lower:]"`
fi
elif [ -r "/etc/redhat-release" ]; then
# it's either RHEL or CentOS, which is fine
os='centos'
# instead of codename, we pull in release version ('6.3', '6.4', etc)
os_codename=`sed s/.*release\ // /etc/redhat-release | sed s/\ .*//`
fi
echo $os $os_codename $architecture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment