1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-08 15:10:45 +02:00

Introduce telegram bot service (#772)

* introduce telgram bot service

* move bot daemon to scripts, use full path to call jq, use infinite while instead of watch

* fix typo
This commit is contained in:
Eugene
2018-11-04 08:56:09 +03:00
committed by jmtatsch
parent 4b6e06e863
commit 12d0c89a05
2 changed files with 131 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
#!/bin/sh
######### Bot commands #########
# /mem - show memory information
# /shot - take a shot
# /on - motion detect on
# /off - motion detect off
PIDFILE="/run/telegram-bot.pid"
if [ ! -f /system/sdcard/config/telegram.conf ]; then
echo "You have to configure telegram first. Please see /system/sdcard/config/telegram.conf.dist for further instructions"
fi
status()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill -0 "$pid" >/dev/null && echo "PID: $pid" || return 1
fi
}
start()
{
if [ -f $PIDFILE ]; then
echo "Bot already running";
else
echo "Starting bot"
/system/sdcard/bin/busybox nohup /system/sdcard/scripts/telegram-bot-daemon.sh >/dev/null 2>&1 &
echo "$!" > "$PIDFILE"
fi
}
stop()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill -9 "$pid"
rm "$PIDFILE"
echo "Bot stopped"
else
echo "Could not find a bot to stop."
fi
}
if [ $# -eq 0 ]; then
start
else
case $1 in start|stop|status)
$1
;;
esac
fi