Files
iDS-Defaults/default.inc
2019-01-31 22:42:40 -06:00

187 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
do_with_root() {
if [[ `whoami` = 'root' ]]; then
$*
elif [[ -x /bin/sudo || -x /usr/bin/sudo ]]; then
echo "sudo $*"
sudo $*
else
echo -e "${BOrange}Please run this script as root.${Color_Off}"
exit 1
fi
}
EXIT1() {
clear
exit 0
}
is_service_running() {
local result=$(ssh root@${1} pgrep $2 | wc -l);
echo $result
}
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
if type apt &>/dev/null; then
ATYPE="apt"
if [ "$EUID" -ne 0 ]; then APTFUNC='sudo apt'
else APTFUNC='apt'
fi
elif type apt-get &>/dev/null; then
ATYPE="apt-get"
if [ "$EUID" -ne 0 ]; then APTFUNC='sudo apt-get'
else APTFUNC='apt-get'
fi
elif type yum &>/dev/null; then
ATYPE="yum"
if [ "$EUID" -ne 0 ]; then APTFUNC='sudo yum'
else APTFUNC='yum'
fi
else
ATYPE="unknown"
#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
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
}
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 () {
if [ -f /etc/redhat-release ] ; then
echo DISTRIBUTION=redhat
echo FAMILY=rh
redhat_derivative
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
echo DISTRIBUTION=debian
echo FAMILY=debian
debian_derivative
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 -A abet
abet[0]="a"
abet[1]="b"
abet[2]="c"
abet[3]="d"
abet[4]="e"
abet[5]="f"
abet[6]="g"
abet[7]="h"
abet[8]="i"
abet[9]="i"
abet[10]="k"
abet[11]="l"
abet[12]="m"
abet[13]="n"
abet[14]="o"
abet[15]="p"
abet[16]="q"
abet[17]="r"
abet[18]="s"
abet[19]="v"
abet[20]="u"
abet[21]="v"
abet[22]="w"
abet[23]="x"
abet[24]="y"
abet[25]="z"