Created
June 7, 2012 19:05
-
-
Save glenbot/2890869 to your computer and use it in GitHub Desktop.
Detect debian operating system
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 | |
# Try and get debian operating system | |
# id, codename, and release | |
get_debian_os_meta() { | |
OS=$(uname) | |
ID="unknown" | |
CODENAME="unknown" | |
RELEASE="unknown" | |
if [ "$OS" == "Linux" ]; then | |
# could be debian or ubuntu | |
if [ $(which lsb_release) ]; then | |
ID=$(lsb_release -i | cut -f2) | |
CODENAME=$(lsb_release -c | cut -f2) | |
RELEASE=$(lsb_release -r | cut -f2) | |
elif [ -f "/etc/lsb-release" ]; then | |
ID=$(cat /etc/lsb-release | grep DISTRIB_ID | cut -d "=" -f2) | |
CODENAME=$(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d "=" -f2) | |
RELEASE=$(cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d "=" -f2) | |
elif [ -f "/etc/issue" ]; then | |
ID=$(head -1 /etc/issue | cut -d " " -f1) | |
if [ -f "/etc/debian_version" ]; then | |
RELEASE=$(</etc/debian_version) | |
else | |
RELEASE=$(head -1 /etc/issue | cut -d " " -f2) | |
fi | |
fi | |
fi | |
# lower case the names in a solid way | |
# can't assume bash 4.0 syntax | |
ID=$(echo "$ID" | tr '[A-Z]' '[a-z]') | |
CODENAME=$(echo "$CODENAME" | tr '[A-Z]' '[a-z]') | |
RELEASE=$(echo "$RELEASE" | tr '[A-Z]' '[a-z]') | |
echo -e "ID\t$ID" | |
echo -e "CODENAME\t$CODENAME" | |
echo -e "RELEASE\t$RELEASE" | |
} | |
get_debian_os_meta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment