From bca8fc75ae5ad4cd65e4fd5cca590fdc21a4e6a5 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Zimin" Date: Sat, 14 Sep 2024 13:34:36 +0300 Subject: [PATCH] Update scripts --- bot/bot.conf | 1 + bot/bot.php | 2 +- etc/cron.d/xbmc | 2 +- etc/sudoers.d/xbmc | 20 +++++++++++++++++++- motion/{check_hdd.sh => checks.sh} | 15 +++++++++++++++ motion/on_ups_event.sh | 8 ++++++++ 6 files changed, 45 insertions(+), 3 deletions(-) rename motion/{check_hdd.sh => checks.sh} (76%) mode change 100755 => 100644 create mode 100644 motion/on_ups_event.sh diff --git a/bot/bot.conf b/bot/bot.conf index 32babbd..22a7d0a 100644 --- a/bot/bot.conf +++ b/bot/bot.conf @@ -1,5 +1,6 @@ { "system_name" : "XBMC", + "network_interface" : "wlan0", "admins_chats" : [ "000000000", "123456789" diff --git a/bot/bot.php b/bot/bot.php index 5c5bc06..c8f8db6 100644 --- a/bot/bot.php +++ b/bot/bot.php @@ -142,7 +142,7 @@ function http_save($url, $path) } elseif(!empty($update['message']['text']) && $update['message']['text'] == '/ping') { - $output = system('ip -json -6 addr show end0 scope global | jq -r \'.[0].addr_info[0].local\''); + $output = system('ip -json -6 addr show '.$config['network_interface'].' scope global | jq -r \'.[0].addr_info[0].local\''); $temp = round(intval(system('cat /sys/class/thermal/thermal_zone0/temp'))/1000, 1); $response = array( diff --git a/etc/cron.d/xbmc b/etc/cron.d/xbmc index e6d08c9..daec9aa 100644 --- a/etc/cron.d/xbmc +++ b/etc/cron.d/xbmc @@ -2,4 +2,4 @@ @reboot xbmc php -f /home/xbmc/bot/bot.php -- --boot */1 * * * * xbmc php -f /home/xbmc/bot/bot.php 0 */6 * * * xbmc /usr/sbin/rotate-byspace.sh -p /mnt/data/motion/bydays -s 30; /usr/sbin/move_by_dates.sh -s /mnt/data/motion -d /mnt/data/motion/bydays -*/15 * * * * xbmc /opt/motion/check_hdd.sh +*/15 * * * * xbmc /opt/motion/checks.sh diff --git a/etc/sudoers.d/xbmc b/etc/sudoers.d/xbmc index db5389f..772a0d9 100644 --- a/etc/sudoers.d/xbmc +++ b/etc/sudoers.d/xbmc @@ -1 +1,19 @@ -ALL ALL=NOPASSWD: /usr/bin/systemctl poweroff,/usr/bin/systemctl halt,/usr/bin/systemctl reboot,/usr/bin/poweroff,/usr/bin/systemctl shutdown,/usr/bin/shutdown,/usr/bin/reboot,/usr/bin/systemctl start motion,/usr/bin/systemctl stop motion,/usr/bin/systemctl show motion -p ActiveState,/opt/motion/on_cam_enable.sh *,/opt/motion/on_cam_disable.sh *,/opt/motion/on_snapshot.sh,/opt/motion/on_cam_record_disable.sh *,/opt/motion/on_cam_record_enable.sh *,/opt/motion/on_send_sms.sh *,/opt/motion/on_flag_set.sh *,/opt/motion/on_flag_clear.sh *,/usr/bin/fsck * +ALL ALL=NOPASSWD: /usr/bin/systemctl shutdown +ALL ALL=NOPASSWD: /usr/bin/systemctl poweroff +ALL ALL=NOPASSWD: /usr/bin/systemctl reboot +ALL ALL=NOPASSWD: /usr/bin/systemctl halt +ALL ALL=NOPASSWD: /usr/bin/shutdown +ALL ALL=NOPASSWD: /usr/bin/poweroff +ALL ALL=NOPASSWD: /usr/bin/reboot +ALL ALL=NOPASSWD: /usr/bin/systemctl start motion +ALL ALL=NOPASSWD: /usr/bin/systemctl stop motion +ALL ALL=NOPASSWD: /usr/bin/systemctl show motion -p ActiveState +ALL ALL=NOPASSWD: /opt/motion/on_cam_enable.sh * +ALL ALL=NOPASSWD: /opt/motion/on_cam_disable.sh * +ALL ALL=NOPASSWD: /opt/motion/on_snapshot.sh +ALL ALL=NOPASSWD: /opt/motion/on_cam_record_disable.sh * +ALL ALL=NOPASSWD: /opt/motion/on_cam_record_enable.sh * +ALL ALL=NOPASSWD: /opt/motion/on_send_sms.sh * +ALL ALL=NOPASSWD: /opt/motion/on_flag_set.sh * +ALL ALL=NOPASSWD: /opt/motion/on_flag_clear.sh * +ALL ALL=NOPASSWD: /usr/bin/fsck * diff --git a/motion/check_hdd.sh b/motion/checks.sh old mode 100755 new mode 100644 similarity index 76% rename from motion/check_hdd.sh rename to motion/checks.sh index 2d4a0e4..8832d67 --- a/motion/check_hdd.sh +++ b/motion/checks.sh @@ -8,6 +8,21 @@ if [ ! -e /opt/motion/flags/flag_check_zigbee.disabled ] ; then fi fi +if [ ! -e /opt/motion/flags/flag_check_internet.disabled ] ; then + cnt=`cat /tmp/no_internet.count` || cnt=0 + + if ! ping -c 1 8.8.8.8 >/dev/null 2>&1 ; then + if ! ping -c 1 77.88.8.8 >/dev/null 2>&1 ; then + cnt=$((cnt + 1)) + if [ $cnt -gt 3 ] ; then + reboot + else + echo $cnt > /tmp/no_internet.count + fi + fi + fi +fi + if [ ! -e /opt/motion/flags/flag_check_hdd.disabled ] ; then filecontent=`cat /mnt/data/mounted` diff --git a/motion/on_ups_event.sh b/motion/on_ups_event.sh new file mode 100644 index 0000000..ce89dcf --- /dev/null +++ b/motion/on_ups_event.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# ./on_ups_event.sh message_text + +/opt/motion/send_event.sh -f -i ups_event "${1}" + +/opt/motion/send_snapshot_rtsp.sh "rtsp://10.1.1.1/?user=admin&password=password&channel=1&stream=0" +/opt/motion/send_snapshot_rtsp.sh "rtsp://10.1.1.2/?user=admin&password=password&channel=1&stream=0"