This commit is contained in:
2019-01-31 23:27:58 -06:00
parent 5ce9eb5032
commit f08c574c71
2 changed files with 21 additions and 83 deletions

View File

@@ -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`

20
test.sh
View File

@@ -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