Skip to content

Instantly share code, notes, and snippets.

@nabinno
Last active February 23, 2016 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nabinno/43dda8d55a2978f77b38 to your computer and use it in GitHub Desktop.
Save nabinno/43dda8d55a2978f77b38 to your computer and use it in GitHub Desktop.
OS detection
case "${OSTYPE}" in
freebsd*|darwin*|linux*)
[ -z "$PS1" ] && return
stty -ixon
stty start undef
stty stop undef
OS=`uname -s`
REV=`uname -r`
MACH=`uname -m`
function GetVersionFromFile () {
VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
}
if [ "${OS}" = "SunOS" ] ; then
OS=Solaris
ARCH=`uname -p`
OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
elif [ "${OS}" = "AIX" ] ; then
OSSTR="${OS} `oslevel` (`oslevel -r`)"
elif [ "${OS}" = "Linux" ] ; then
KERNEL=`uname -r`
if [ -f /etc/redhat-release ] ; then
DIST='RedHat'
DIST_VERSION=''
DIST2=''
PSUEDONAME=`cat /etc/redhat-release | sed -e 's/.*(//' | sed -e 's/)//'`
REV=`cat /etc/redhat-release | sed -e 's/.*release //' | sed -e 's/ .*//'`
elif [ -f /etc/SUSE-release ] ; then
DIST="SUSE"
DIST_VERSION=''
DIST2=`cat /etc/SUSE-release | tr "\n" ' '| sed -e 's/VERSION.*//'`
PSUEDONAME=''
REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed -e 's/.*= //'`
elif [ -f /etc/mandrake-release ] ; then
DIST='Mandrake'
DIST_VERSION=''
DIST2=''
PSUEDONAME=`cat /etc/mandrake-release | sed -e 's/.*(//' | sed -e 's/)//'`
REV=`cat /etc/mandrake-release | sed -e 's/.*release //' | sed -e 's/ .*//'`
elif [ -f /etc/debian_version ] ; then
if ! type -p lsb_release > /dev/null; then
sudo apt-get install -y lsb-release
fi
DIST="$(lsb_release -i -s)"
DIST_VERSION="$(lsb_release -s -r)"
DIST2="Debian `cat /etc/debian_version`"
PSUEDONAME=''
REV=""
fi
if [ -f /etc/UnitedLinux-release ] ; then
DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed -e 's/VERSION.*//'`]"
fi
OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"
fi
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment