This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/cloudbot.sh

73 lines
2.1 KiB
Bash
Raw Normal View History

#!/bin/bash
echo
2012-03-01 23:41:37 +01:00
echo "Welcome to: "
echo " ______ __ ______ __ __ _______ .______ ______ .___________."
echo " / || | / __ \ | | | | | \ | _ \ / __ \ | |"
echo "| ,----'| | | | | | | | | | | .--. || |_) | | | | | \`---| |----\`"
echo "| | | | | | | | | | | | | | | || _ < | | | | | | "
echo "| \`----.| \`----.| \`--' | | \`--' | | '--' || |_) | | \`--' | | | "
echo " \______||_______| \______/ \______/ |_______/ |______/ \______/ |__| "
echo " http://git.io/cloudbot by lukeroge "
echo
2012-03-01 23:41:37 +01:00
checkbackend() {
if dpkg -l| grep ^ii|grep daemon|grep 'turns other' > /dev/null; then
2012-03-01 23:41:37 +01:00
backend="daemon"
echo "backend: daemon"
elif dpkg -l| grep ^ii|grep screen|grep 'terminal multi' > /dev/null; then
2012-03-01 23:41:37 +01:00
backend="screen"
echo "backend: screen"
else
2012-03-01 23:41:37 +01:00
backend="manual"
echo "backend: manual"
2012-03-01 23:41:37 +01:00
fi
return 0
}
setcommands() {
if [ "$backend" == "daemon" ]; then
start="daemon -r -n cloudbot -O ./bot.log python ./bot.py"
2012-03-01 23:41:37 +01:00
stop="daemon -n cloudbot --stop"
pid="pidof /usr/bin/daemon"
elif [ "$backend" == "screen" ]; then
start="screen -d -m -S cloudbot -t cloudbot python ./bot.py > ./bot.log 2>&1"
stop="kill $(pidof /usr/bin/screen)"
2012-03-01 23:41:37 +01:00
pid="pidof /usr/bin/screen"
elif [ "$backend" == "manual" ]; then
start="./bot.py"
stop="kill $(pidof ./bot.py)"
restart="./cloudbot stop > /dev/null 2>&1 && ./cloudbot start > /dev/null 2>&1"
fi
restart="./cloudbot stop > /dev/null 2>&1 && ./cloudbot start > /dev/null 2>&1"
}
running() {
ps ax|grep bot|grep -v grep|grep -v ./cloudbot
return $?
}
processargs() {
args=$1
case $args in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
}
main() {
checkbackend
setcommands
processargs
}
main