Skip to content

Commit 2a06b43

Browse files
committed
♻️ Update detectionOn.sh for better code quality
- Replace `-o` with `||` for better readability and consistency - Add shellcheck directives for better code quality - Improve variable handling with `${var:?}` to prevent errors - Update conditional statements for better readability
1 parent 11ef5bc commit 2a06b43

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

firmware_mod/scripts/detectionOn.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ debug_msg () {
1717
send_snapshot() {
1818

1919
# Publish a mqtt message
20-
if [ "$publish_mqtt_message" = true -o "$publish_mqtt_snapshot" = true ] ; then
20+
if [ "$publish_mqtt_message" = true ] || [ "$publish_mqtt_snapshot" = true ] ; then
2121
(
22+
# shellcheck source=config/mqtt.conf.dist
2223
. /system/sdcard/config/mqtt.conf
2324

2425
if [ "$publish_mqtt_message" = true ] ; then
@@ -41,12 +42,13 @@ send_snapshot() {
4142
# Send a telegram message
4243
if [ "$send_telegram" = true ]; then
4344
(
45+
# shellcheck source=config/telegram.conf.dist
4446
include /system/sdcard/config/telegram.conf
4547

4648
if [ "$telegram_alert_type" = "text" ] ; then
4749
debug_msg "Send telegram text"
4850
/system/sdcard/bin/telegram m "Motion detected"
49-
elif [ "$telegram_alert_type" = "image" -o "$telegram_alert_type" = "video+image" ] ; then
51+
elif [ "$telegram_alert_type" = "image" ] || [ "$telegram_alert_type" = "video+image" ] ; then
5052
debug_msg "Send telegram image"
5153
/system/sdcard/bin/telegram p "$snapshot_tempfile"
5254
fi
@@ -61,7 +63,7 @@ send_snapshot() {
6163
if [ "$matrix_alert_type" = "text" ] ; then
6264
debug_msg "Send matrix text"
6365
/system/sdcard/bin/matrix m "Motion detected"
64-
elif [ "$matrix_alert_type" = "image" -o "$matrix_alert_type" = "video+image" ] ; then
66+
elif [ "$matrix_alert_type" = "image" ] || [ "$matrix_alert_type" = "video+image" ] ; then
6567
debug_msg "Send matrix image"
6668
/system/sdcard/bin/matrix p "$filename" "$snapshot_tempfile"
6769
fi
@@ -113,7 +115,7 @@ send_snapshot() {
113115

114116
# Limit the number of snapshots
115117
if [ "$(ls "$save_snapshot_dir" | wc -l)" -ge "$max_snapshot_days" ]; then
116-
rm -rf "${save_snapshot_dir}/$(ls -ltr "$save_snapshot_dir" | awk 'NR==2{print $9}')"
118+
rm -rf "${save_snapshot_dir:?}/$(ls -ltr "$save_snapshot_dir" | awk 'NR==2{print $9}')"
117119
fi
118120

119121
chmod "$save_files_attr" "$snapshot_tempfile"
@@ -225,8 +227,8 @@ send_snapshot &
225227
if [ "$save_video" = true ] ||
226228
[ "$smb_video" = true ] ||
227229
[ "$dropbox_video" = true ] ||
228-
([ "$send_telegram" = true ] && ([ "$telegram_alert_type" = video+image ] || [ "$telegram_alert_type" = video ])) ||
229-
([ "$send_matrix" = true ] && ([ "$matrix_alert_type" = video+image ] || [ "$matrix_alert_type" = video ])) ||
230+
{ [ "$send_telegram" = true ] && { [ "$telegram_alert_type" = video+image ] || [ "$telegram_alert_type" = video ]; }; } ||
231+
{ [ "$send_matrix" = true ] && { [ "$matrix_alert_type" = video+image ] || [ "$matrix_alert_type" = video ]; }; } ||
230232
[ "$publish_mqtt_video" = true ]
231233
then
232234
record_video
@@ -246,7 +248,7 @@ if [ "$save_video" = true ] ; then
246248

247249
# Limit the number of videos
248250
if [ "$(ls "$save_video_dir" | wc -l)" -ge "$max_video_days" ]; then
249-
rm -rf "$save_video_dir/$(ls -ltr "$save_video_dir" | awk 'NR==2{print $9}')"
251+
rm -rf "${save_video_dir:?}/$(ls -ltr "$save_video_dir" | awk 'NR==2{print $9}')"
250252
fi
251253

252254
chmod "$save_files_attr" "$video_tempfile"
@@ -356,7 +358,7 @@ if [ "$send_telegram" = true ]; then
356358
(
357359
include /system/sdcard/config/telegram.conf
358360

359-
if [ "$telegram_alert_type" = "video" -o "$telegram_alert_type" = "video+image" ] ; then
361+
if [ "$telegram_alert_type" = "video" ] || [ "$telegram_alert_type" = "video+image" ] ; then
360362
if [ "$video_use_rtsp" = true ]; then
361363
if [ "$AUDIOFORMAT" = "PCMU" ] || [ "$AUDIOFORMAT" = "OFF" ] ; then
362364
# Convert file to mp4 and remove audio stream so video plays in telegram app
@@ -383,7 +385,7 @@ if [ "$send_matrix" = true ]; then
383385
(
384386
include /system/sdcard/config/matrix.conf
385387

386-
if [ "$matrix_alert_type" = "video" -o "$matrix_alert_type" = "video+image" ] ; then
388+
if [ "$matrix_alert_type" = "video" ] || [ "$matrix_alert_type" = "video+image" ] ; then
387389
debug_msg "Send matrix video"
388390
if [ "$video_use_rtsp" = true ]; then
389391
/system/sdcard/bin/matrix v "$filename" "$video_tempfile"

firmware_mod/scripts/telegram-bot-daemon.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CURL="/system/sdcard/bin/curl"
88
LASTUPDATEFILE="/tmp/last_update_id"
99
TELEGRAM="/system/sdcard/bin/telegram"
1010
JQ="/system/sdcard/bin/jq"
11-
11+
1212
# shellcheck source=config/telegram.conf.dist
1313
. /system/sdcard/config/telegram.conf
1414
[ -z "$apiToken" ] && echo "api token not configured yet" && exit 1

0 commit comments

Comments
 (0)