143 lines
4.1 KiB
Bash
Executable File
143 lines
4.1 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
|
|
|
|
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 __resultvar="$1" || return 1
|
|
__resultvar[MACH]=`uname -m`
|
|
if [ -f /etc/redhat-release ] ; then
|
|
echo DISTRIBUTION=redhat
|
|
echo FAMILY=rh
|
|
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
|
|
__resultvar[DISTRIBUTION]=debian
|
|
__resultvar[FAMILY]=debian
|
|
if which lsb_release 2>&1 > /dev/null ; then
|
|
__resultvar[DERIVATIVE]=`lsb_release --id --short 2> /dev/null`
|
|
__resultvar[RELEASE]=`lsb_release --release --short 2> /dev/null`
|
|
__resultvar[CODENAME]=`lsb_release --codename --short 2> /dev/null`
|
|
else
|
|
__resultvar[DERIVATIVE]=unknown
|
|
__resultvar[RELEASE]=`cat /etc/debian_version`
|
|
__resultvar[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 -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"
|