vigil

Security camera system built on motion and yolov7.
git clone git://code.dwrz.net/vigil
Log | Files | Refs

commit 6ef6f554ceae9ce3c18803baab16322b937667f8
parent 7501d00d76df45911be409bd02aedff305c3bd2f
Author: dwrz <dwrz@dwrz.net>
Date:   Sun, 28 May 2023 18:28:18 +0000

Refactor to use rsync server

Diffstat:
Mscripts/notify | 15+++++++--------
Mscripts/sync | 11+++++------
Msetup | 14++++++++++++++
3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/scripts/notify b/scripts/notify @@ -1,8 +1,5 @@ #!/usr/bin/env bash -# Backblaze B2 Bucket -readonly BUCKET="${B2_BUCKET}" - # Devices to check -- if populated and up, no notifications are sent. readonly DEVICES=() @@ -19,6 +16,10 @@ readonly PROJECT="/tmp/yolov7" # Notification recipient. readonly RECIPIENT="${NOTIFICATION_RECIPIENT}" +# rsync user and server for backups. +readonly RSYNC_USER="${RSYNC_USER}" +readonly RSYNC_SERVER="${RSYNC_SERVER}" + acquire_lock () { while true; do if mkdir "${LOCKFILE}"; then @@ -63,11 +64,9 @@ notify() { upload() { local name="$1" - backblaze-b2 upload-file \ - --threads 2 \ - "${BUCKET}" \ - "${PROJECT}/motion/${name}.jpg" \ - "${HOSTNAME}/photo/${name}.jpg" + rsync --archive --verbose \ + "${PROJECT}/motion/${name}.jpg" \ + "${RSYNC_USER}@${RSYNC_SERVER}:/photo/${name}.jpg" } delete_outdated() { diff --git a/scripts/sync b/scripts/sync @@ -1,17 +1,16 @@ #!/usr/bin/env bash -readonly BUCKET="${B2_BUCKET}" +readonly RSYNC_USER="${RSYNC_USER}" +readonly RSYNC_SERVER="${RSYNC_SERVER}" main() { local filepath="$1" local name name="$(basename "${filepath}")" - backblaze-b2 upload-file \ - --threads 2 \ - "${BUCKET}" \ - "${HOME}/timelapse/${name}" \ - "${HOSTNAME}/timelapse/${name}" + rsync --archive --verbose \ + "${HOME}/timelapse/${name}" \ + "${RSYNC_USER}@${RSYNC_SERVER}:/timelapse/${name}" # Delete outdated files. # This assumes the timelapse is created on an hourly basis. diff --git a/setup b/setup @@ -21,6 +21,8 @@ MOTION_LOG_FILE="/var/log/motion/motion.log" MOTION_PASSWORD="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 24 ; echo '')" MOTION_USER="${USER}" NOTIFICATION_RECIPIENT="1234567890@sms.example.com" +RSYNC_USER="user" +RSYNC_SERVER="server" PORT_CONTROL="8080" PORT_STREAM="3000" TLS_CERT="/etc/letsencrypt/live/${DOMAIN}/fullchain.pem" @@ -85,6 +87,14 @@ input_settings() { read -r input PORT_STREAM="${input:-$PORT_STREAM}" + printf "rsync user (%s): " "${RSYNC_USER}" + read -r input + RSYNC_USER="${input:-$RSYNC_USER}" + + printf "rsync server (%s): " "${RSYNC_SERVER}" + read -r input + RSYNC_SERVER="${input:-$RSYNC_SERVER}" + printf "TLS certifcate path (%s): " "${TLS_CERT}" read -r input TLS_CERT="${input:-$TLS_CERT}" @@ -109,6 +119,8 @@ print_settings() { printf "Motion password: %s\n" "${MOTION_PASSWORD}" printf "Webcontrol port: %s\n" "${PORT_CONTROL}" printf "Livestream port: %s\n" "${PORT_STREAM}" + printf "rsync user: %s\n" "${RSYNC_USER}" + printf "rsync server: %s\n" "${RSYNC_SERVER}" printf "Notification recipient: %s\n" "${NOTIFICATION_RECIPIENT}" printf "TLS certificate: %s\n" "${TLS_CERT}" printf "TLS key: %s\n" "${TLS_KEY}" @@ -130,6 +142,8 @@ write_settings() { sed -i 's|\${NOTIFICATION_RECIPIENT}|'"${NOTIFICATION_RECIPIENT}"'|g' "${f}" sed -i 's|\${PORT_CONTROL}|'"${PORT_CONTROL}"'|g' "${f}" sed -i 's|\${PORT_STREAM}|'"${PORT_STREAM}"'|g' "${f}" + sed -i 's|\${RSYNC_USER}|'"${RSYNC_USER}"'|g' "${f}" + sed -i 's|\${RSYNC_SERVER}|'"${RSYNC_SERVER}"'|g' "${f}" sed -i 's|\${TLS_CERT}|'"${TLS_CERT}"'|g' "${f}" sed -i 's|\${TLS_KEY}|'"${TLS_KEY}"'|g' "${f}" done