Last active
December 21, 2015 21:29
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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