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

118 lines
2.8 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
2012-03-02 00:23:20 +01:00
args=$*
usage="./cloudbot {start|stop|restart|clear|status}"
locatefiles() {
botfile="/bot.py"
botfile=$(pwd)$botfile
logfile="/botlog"
logfile=$(pwd)$logfile
}
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
}
2012-03-02 00:23:20 +01:00
running() {
ps ax|grep bot|grep -v grep|grep -v ./cloudbot
return $?
}
2012-03-01 23:41:37 +01:00
setcommands() {
if [ "$backend" == "daemon" ]; then
2012-03-02 00:23:20 +01:00
start() {
daemon -r -n cloudbot -O $logfile python $botfile
}
stop() {
daemon -n cloudbot --stop
}
pid() {
pidof /usr/bin/daemon
}
2012-03-01 23:41:37 +01:00
elif [ "$backend" == "screen" ]; then
2012-03-02 00:23:20 +01:00
start() {
screen -d -m -S cloudbot -t cloudbot python $botfile > $logfile 2>&1
}
stop() {
kill $(pidof /usr/bin/screen)
}
pid() {
pidof /usr/bin/screen
}
2012-03-01 23:41:37 +01:00
elif [ "$backend" == "manual" ]; then
2012-03-02 00:23:20 +01:00
start() {
$botfile
}
stop() {
kill $(pidof $botfile)
}
pid() {
pidof $botfile
}
fi
2012-03-02 00:23:20 +01:00
status() {
if running; then
echo "CloudBot is running!"
pid
else
echo "CloudBot is not running!"
fi
}
clear() {
: > $logfile
}
}
processargs() {
2012-03-02 00:23:20 +01:00
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
clear)
clear
;;
status)
status
;;
*)
echo $usage
;;
esac
}
main() {
2012-03-02 00:23:20 +01:00
locatefiles
checkbackend
setcommands
2012-03-02 00:23:20 +01:00
processargs $1
}
2012-03-02 00:23:20 +01:00
main $*