flipje

distro-detect

Mar 9th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.95 KB | None | 0 0
  1. #!/bin/sh
  2. # Detects which OS and if it is Linux then it will detect which Linux Distribution.
  3.  
  4. OS=`uname -s`
  5. REV=`uname -r`
  6. MACH=`uname -m`
  7.  
  8. GetVersionFromFile()
  9. {
  10.   VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
  11. }
  12.  
  13. if [ "${OS}" = "SunOS" ] ; then
  14.   OS=Solaris
  15.   ARCH=`uname -p`
  16.   OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
  17. elif [ "${OS}" = "AIX" ] ; then
  18.   OSSTR="${OS} `oslevel` (`oslevel -r`)"
  19. elif [ "${OS}" = "Linux" ] ; then
  20.   KERNEL=`uname -r`
  21.   if [ -f /etc/redhat-release ] ; then
  22.     DIST=$(cat /etc/redhat-release | awk '{print $1}')
  23.     if [ "${DIST}" = "CentOS" ]; then
  24.       DIST="CentOS"
  25.     else
  26.       DIST="RedHat"
  27.     fi
  28.  
  29.     PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
  30.     REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
  31.   elif [ -f /etc/SuSE-release ] ; then
  32.     DIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
  33.     REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
  34.   elif [ -f /etc/mandrake-release ] ; then
  35.     DIST='Mandrake'
  36.     PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
  37.     REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
  38.   elif [ -f /etc/debian_version ] ; then
  39.     DIST="Debian `cat /etc/debian_version`"
  40.     REV=""
  41.   fi
  42.  
  43.   if [ -f /etc/UnitedLinux-release ] ; then
  44.     DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
  45.   fi
  46.  
  47.   if [ -f /etc/lsb-release ] ; then
  48.     LSB_DIST="`cat /etc/lsb-release | grep DISTRIB_ID | cut -d "=" -f2`"
  49.     LSB_REV="`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d "=" -f2`"
  50.     if [ "$LSB_DIST" != "" ] ; then
  51.       DIST=$LSB_DIST
  52.       REV=$LSB_REV
  53.     fi
  54.   fi
  55.  
  56. #  OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"
  57.   OSSTR="${DIST} ${REV}"
  58. elif [ "${OS}" = "Darwin" ] ; then
  59.   if [ -f /usr/bin/sw_vers ] ; then
  60.     OSSTR=`/usr/bin/sw_vers|grep -v Build|sed 's/^.*:.//'| tr "\n" ' '`
  61.   fi
  62. fi
  63.  
  64. echo ${OSSTR}
Advertisement
Add Comment
Please, Sign In to add comment