2012-03-01 23:54:28 +01:00
|
|
|
#!/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 "
|
2012-03-01 23:54:28 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2012-03-01 23:54:28 +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"
|
2012-03-01 23:54:28 +01:00
|
|
|
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"
|
2012-03-01 23:54:28 +01:00
|
|
|
echo "backend: screen"
|
|
|
|
else
|
2012-03-01 23:41:37 +01:00
|
|
|
backend="manual"
|
2012-03-01 23:54:28 +01:00
|
|
|
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
|
|
|
|
}
|
2012-03-01 23:54:28 +01:00
|
|
|
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
|
|
|
|
}
|
2012-03-01 23:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2012-03-01 23:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2012-03-02 00:23:20 +01:00
|
|
|
locatefiles
|
2012-03-01 23:54:28 +01:00
|
|
|
checkbackend
|
|
|
|
setcommands
|
2012-03-02 00:23:20 +01:00
|
|
|
processargs $1
|
2012-03-01 23:54:28 +01:00
|
|
|
}
|
|
|
|
|
2012-03-02 00:23:20 +01:00
|
|
|
main $*
|