From e103c4892bacb7af48846a53b7036f2bdd28431c Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sun, 3 Mar 2019 23:13:46 -0600 Subject: [PATCH] Create get-os.sh --- get-os.sh | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 get-os.sh diff --git a/get-os.sh b/get-os.sh new file mode 100755 index 0000000..731ab3e --- /dev/null +++ b/get-os.sh @@ -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 \ No newline at end of file