diff --git a/default.inc b/default.inc index dab286e..83823fa 100755 --- a/default.inc +++ b/default.inc @@ -46,47 +46,6 @@ else #exit 1 fi - -# Script outputs results in the format that can either be parsed or -# directly eval'ed in Bourne shell: -# -# Example -# ----------- -# sherlock -# OS=Linux -# MACH=x86_64 -# KERNEL=2.6.32-5-amd64 -# DISTRIBUTION=debian -# FAMILY=debian -# DERIVATIVE=Debian -# RELEASE=6.0.6 -# CODENAME=squeeze -# - -detect_os () { - - OS=`uname -s` - MACH=`uname -m` - - echo OS=$OS - echo MACH=$MACH - - if [ "${OS}" = "SunOS" ] ; then - echo ARCH=`uname -p` - OSSTR="${OS} ${REV}(${ARCH} `uname -v`)" - echo FAMILY=solaris - elif [ "${OS}" = "AIX" ] ; then - echo OSSTR="${OS} `oslevel` (`oslevel -r`)" - echo FAMILY=aix - elif [ "${OS}" = "Darwin" ] ; then - echo REV=`uname -r` - echo FAMILY=macosx - elif [ "${OS}" = "Linux" ] ; then - echo KERNEL="`uname -r`" - linux_distro - fi -} - redhat_derivative () { local FILE=/etc/redhat-release @@ -100,31 +59,20 @@ redhat_derivative () { echo DERIVATIVE=unknown } -redhat_release () { - echo RELEASE=`tr -d 'a-zA-Z [](){}' < /etc/redhat-release` -} - -debian_derivative () { - if which lsb_release 2>&1 > /dev/null ; then - echo DERIVATIVE=`lsb_release --id --short 2> /dev/null` - echo RELEASE=`lsb_release --release --short 2> /dev/null` - echo CODENAME=`lsb_release --codename --short 2> /dev/null` - return - else - echo DERIVATIVE=unknown - echo RELEASE=`cat /etc/debian_version` - echo CODENAME=unknown - return - fi -} - -linux_distro () { - +detect_os () { + local -n myresult="$1" || return 1 + echo MACH=$MACH if [ -f /etc/redhat-release ] ; then echo DISTRIBUTION=redhat echo FAMILY=rh - redhat_derivative - redhat_release + local FILE=/etc/redhat-release + grep -i 'red.*hat.*enterprise.*linux' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=rhel; return; } + grep -i 'red.*hat.*linux' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=rh; return; } + grep -i 'cern.*e.*linux' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=cel; return; } + grep -i 'scientific linux cern' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=slc; return; } + grep -i 'centos' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=centos; return; } + #echo DERIVATIVE=unknown + echo RELEASE=`tr -d 'a-zA-Z [](){}' < /etc/redhat-release` elif [ -s /etc/slackware-version ]; then echo DISTRIBUTION="slackware" elif [ -f /etc/SUSE-release ] ; then @@ -142,7 +90,15 @@ linux_distro () { elif [ -f /etc/debian_version ] ; then echo DISTRIBUTION=debian echo FAMILY=debian - debian_derivative + if which lsb_release 2>&1 > /dev/null ; then + echo DERIVATIVE=`lsb_release --id --short 2> /dev/null` + echo RELEASE=`lsb_release --release --short 2> /dev/null` + echo CODENAME=`lsb_release --codename --short 2> /dev/null` + else + echo DERIVATIVE=unknown + echo RELEASE=`cat /etc/debian_version` + echo CODENAME=unknown + fi elif [ -f /etc/UnitedLinux-release ]; then echo DISTRIBUTION="united" echo VERSION=`cat /etc/UnitedLinux-release` diff --git a/test.sh b/test.sh index 268ca47..0d86543 100755 --- a/test.sh +++ b/test.sh @@ -18,22 +18,4 @@ fi -function myfunc() -{ - local -n myresult="$1" || return 1 - myresult[0]="a" - myresult[1]="b" - myresult[2]="c" - myresult[3]="d" - myresult[4]="e" -} -generatearray() { - # $1 is array name in which array is generated - local -n array="$1" || return 1 - array=( foo doo coo ) -} -# call function that constructs the array with the array name -myfunc targetvalue -# display it -declare -p myresult - +detect_os \ No newline at end of file