Created
October 12, 2011 17:51
-
-
Save pyther/1281973 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# Detects Linux Distribution | |
# | |
# Most Distributions have lsb_release or use /etc/lsb_release | |
# For those that do not we have some fallback cases | |
OS=$(uname -s) | |
VER=$(uname -r) | |
# Look for lsb_release in path | |
LSB_REL=$(which lsb_release 2>/dev/null) | |
if [[ $OS == Linux ]]; then | |
# If lsb_release is executable set the DIST and VER | |
if [[ -x $LSB_REL ]]; then | |
DIST=$(lsb_release -is) | |
VER=$(lsb_release -rs) | |
elif [[ -f /etc/lsb-release ]]; then | |
DIST=$(grep 'DISTRIB_ID' /etc/lsb-release | cut -d"=" -f2) | |
VER=$(grep 'DISTRIB_RELEASE' /etc/lsb-release | cut -d"=" -f2) | |
elif [[ -f /etc/redhat-release ]]; then | |
DIST=$(sed 's/ release.*//' /etc/redhat-release) | |
VER=$(sed 's/.*release\ //' /etc/redhat-release | sed 's/\ .*//') | |
elif [[ -f /etc/SuSE-release ]]; then | |
DIST=$(head -1 suse | awk '{print $1}') | |
VER=$(awk '/VERSION/ {print $3}' /etc/SuSE-release) | |
elif [[ -f /etc/debian_version ]]; then | |
DIST="Debian" | |
read VER < /etc/debian_version | |
elif [[ -f /etc/arch-release ]]; then | |
DIST="Arch Linux" | |
VER="" | |
else | |
DIST="${OS}" | |
fi | |
# Exceptions | |
# RHEL uses multiple strings RedHatEnterpriseWS (4.x), RedHatEnterpriseServer (5.x, 6.x) | |
if [[ $DIST =~ RedHatEnterprise ]]; then | |
DIST="RedHatEnterprise" | |
fi | |
OSSTR="${DIST} ${VER}" | |
else | |
OSSTR="$OS $VER" | |
fi | |
echo ${OSSTR} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment