2023-02-18 09:22:41 +03:00
|
|
|
#! /bin/sh
|
|
|
|
# chkconfig: 2345 20 80
|
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
2023-12-19 22:21:05 +03:00
|
|
|
# Provides: sendtelegram-reboot
|
|
|
|
# Required-Start: $all
|
|
|
|
# Required-Stop:
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop:
|
|
|
|
# Short-Description: Sending a message on startup
|
2023-02-18 09:22:41 +03:00
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
start() {
|
2023-12-19 22:45:10 +03:00
|
|
|
API_URL="$(grep "API_URL=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
|
|
|
|
SILENCE="$(grep "SILENCE=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
|
|
|
|
CHAT_ID="$(grep "CHAT_ID=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
|
|
|
|
THRD_ID="$(grep "THRD_ID=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
|
2023-12-19 22:21:05 +03:00
|
|
|
TXT_MSG="[System States] $(cat /etc/hostname): computer has been rebooted"
|
2023-02-18 09:22:41 +03:00
|
|
|
|
2023-12-19 22:21:05 +03:00
|
|
|
sleep 15
|
|
|
|
if [ -z "${THRD_ID}" ]; then
|
|
|
|
curl -s -o /dev/null -X POST \
|
|
|
|
-d chat_id="${CHAT_ID}" \
|
|
|
|
-d text="${TXT_MSG}" \
|
|
|
|
-d disable_notification="${SILENCE}" \
|
|
|
|
"${API_URL}"
|
|
|
|
else
|
|
|
|
curl -s -o /dev/null -X POST \
|
|
|
|
-d chat_id="${CHAT_ID}" \
|
|
|
|
-d text="$TXT_MSG" \
|
|
|
|
-d disable_notification="${SILENCE}" \
|
|
|
|
-d message_thread_id="$THRD_ID" \
|
|
|
|
"${API_URL}"
|
|
|
|
fi
|
2023-02-18 09:22:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2023-12-19 22:21:05 +03:00
|
|
|
pkill -f curl -s -o /dev/null -X POST -d chat_id="${CHAT_ID}"
|
2023-02-18 09:22:41 +03:00
|
|
|
}
|
|
|
|
|
2023-12-19 22:21:05 +03:00
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "%s\n" "Usage: $0 {start|stop|restart}"
|
2023-02-18 09:22:41 +03:00
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|