Create get-os.sh

This commit is contained in:
2019-03-03 23:13:46 -06:00
parent a1794f2535
commit e103c4892b

67
get-os.sh Executable file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/env bash
redhat_derivative () {
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
}
detect_os () {
#local -n OSinfo="$1" || return 1
declare -A OSinfo
OSinfo[MACH]=`uname -m`
if [ -f /etc/redhat-release ] ; then
echo DISTRIBUTION=redhat
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
# TODO - not tested
echo DISTRIBUTION=suse
echo PSUEDONAME=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//`
echo REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //`
echo VERSION=`cat /etc/SuSE-release | grep 'VERSION' | sed -e 's#[^0-9]##g'`
elif [ -f /etc/mandrake-release ] ; then
# TODO - not tested
echo DISTRIBUTION=mandrake
echo PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
echo REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
echo FAMILY=rh
elif [ -f /etc/debian_version ] ; then
OSinfo[DISTRIBUTION]=debian
if which lsb_release 2>&1 > /dev/null ; then
OSinfo[DERIVATIVE]=`lsb_release --id --short 2> /dev/null`
OSinfo[RELEASE]=`lsb_release --release --short 2> /dev/null`
OSinfo[CODENAME]=`lsb_release --codename --short 2> /dev/null`
else
OSinfo[DERIVATIVE]=unknown
OSinfo[RELEASE]=`cat /etc/debian_version`
OSinfo[CODENAME]=unknown
fi
elif [ -f /etc/UnitedLinux-release ]; then
echo DISTRIBUTION="united"
echo VERSION=`cat /etc/UnitedLinux-release`
elif [ -r /etc/init.d/functions.sh ]; then
# TODO - not tested
source /etc/init.d/functions.sh
[ zz`type -t ebegin 2>/dev/null` == "zzfunction" ] && echo DISTRIBUTION="gentoo"
fi
#declare -p OSinfo
echo "${OSinfo[@]}"
}
detect_os