vigil

Security camera system built on motion and yolov7.
Log | Files | Refs

commit 91ff9e6325e9a550d0ad771ae82a05f083af592a
parent 603034d1b4204e8b627a67753de59eb7a7f267ff
Author: dwrz <dwrz@dwrz.net>
Date:   Fri, 28 Oct 2022 14:57:09 +0000

Add semaphore to notify script

Diffstat:
Mscripts/notify | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/scripts/notify b/scripts/notify @@ -10,12 +10,24 @@ readonly DEVICES=() readonly LABEL_PERSON=0 readonly LABEL_CAT=15 +# Lockfile to ensure that only one instance of the script is running. +readonly LOCKFILE="/tmp/motion-notify.lock.d" + # yolov7 working directory. readonly PROJECT="/tmp/yolov7" # Notification recipient. readonly RECIPIENT="${NOTIFICATION_RECIPIENT}" +acquire_lock () { + while true; do + if mkdir "${LOCKFILE}"; then + break; + fi + sleep 1 + done +} + check_devices() { for device in "${DEVICES[@]}"; do if ping -c 1 -w 1 "${device}" &> "/dev/null"; then @@ -61,12 +73,20 @@ upload() { delete_outdated() { local filepath="$1" + acquire_lock + rm -f "$1" rm -f "${PROJECT}/motion/${name}.jpg" find "${HOME}/photo/" -mmin +5 -delete find "${HOME}/timelapse/" -mmin +60 -delete find "${PROJECT}/motion/" -iname "*.jpg" -mmin +5 -delete find "${PROJECT}/motion/labels/" -mmin +5 -delete + + release_lock +} + +release_lock () { + rmdir "${LOCKFILE}" } main() {