vigil

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

commit 3b62c8f759b75da9b65a37dc99d6b0037d601325
parent 71a978af34228c6aa1ecbdf7e0a7a30d7569e7f1
Author: dwrz <dwrz@dwrz.net>
Date:   Thu, 27 Oct 2022 20:43:12 +0000

Add setup script

Diffstat:
Mconfig/motion.conf | 4++--
Mconfig/msmtprc | 14+++++++-------
Mconfig/muttrc | 2+-
Mscripts/alert | 2+-
Mscripts/notify | 2+-
Asetup | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 132 insertions(+), 12 deletions(-)

diff --git a/config/motion.conf b/config/motion.conf @@ -32,7 +32,7 @@ timelapse_filename /timelapse/%Y-%m-%d-%H-%M-%S # WEBCONTROL webcontrol_auth_method 2 -webcontrol_authentication ${USER}:${PASS} +webcontrol_authentication ${MOTION_USER}:${MOTION_PASSWORD} webcontrol_port 8080 webcontrol_localhost off webcontrol_cert /etc/letsencrypt/live/${DOMAIN}/fullchain.pem @@ -47,7 +47,7 @@ stream_quality 25 stream_motion on stream_maxrate 24 stream_auth_method 2 -stream_authentication ${USER}:${PASS} +stream_authentication ${MOTION_USER}:${MOTION_PASSWORD} stream_preview_method 0 stream_tls on diff --git a/config/msmtprc b/config/msmtprc @@ -4,11 +4,11 @@ tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile ~/.msmtp.log -account gmail -host smtp.gmail.com -port 587 -from user@example.com -user user@example.com -password app-password +account default +host ${EMAIL_HOST} +port ${EMAIL_PORT} +from ${EMAIL_USER} +user ${EMAIL_USER} +password ${EMAIL_PASSWORD} -account default : gmail +account default : default diff --git a/config/muttrc b/config/muttrc @@ -1,3 +1,3 @@ set sendmail="/usr/bin/msmtp" set use_from=yes -set from=user@example.com +set from=${EMAIL_USER} diff --git a/scripts/alert b/scripts/alert @@ -1,6 +1,6 @@ #!/usr/bin/env bash -readonly RECIPIENT="" +readonly RECIPIENT="${NOTIFICATION_RECIPIENT}" main() { echo "${HOSTNAME}: motion detected at $(date '+%Y-%m-%dT%H:%M:%S%:z')." | \ diff --git a/scripts/notify b/scripts/notify @@ -11,7 +11,7 @@ readonly LABEL_CAT=15 readonly PROJECT="/tmp/yolov7" # Notification recipient. -readonly RECIPIENT="" +readonly RECIPIENT="${NOTIFICATION_RECIPIENT}" detect_objects() { local filepath="$1" diff --git a/setup b/setup @@ -0,0 +1,120 @@ +#!/usr/bin/env bash + +readonly FILES=( + "./config/motion.conf" + "./config/msmtprc" + "./config/muttrc" + "./scripts/alert" + "./scripts/cameras" + "./scripts/notify" + "./scripts/sync" +) + +BUCKET="my-bucket-name" +CAMERA_NAME="Kitchen" +DOMAIN="kitchen.example.com" +EMAIL_HOST="smtp.gmail.com" +EMAIL_PORT="587" +EMAIL_USER="user@example.com" +MOTION_PASSWORD="" +MOTION_USER="" +NOTIFICATION_RECIPIENT="1234567890@sms.example.com" + +input_settings() { + local input + + # Set the B2 bucket name. + printf "Bucket (%s): " "${BUCKET}" + read -r input + BUCKET="${input:-$BUCKET}" + + # Set the camera name. + printf "Camera name (%s): " "${CAMERA_NAME}" + read -r input + CAMERA_NAME="${input:-$CAMERA_NAME}" + + # Set the domain. + printf "Domain (%s): " "${DOMAIN}" + read -r input + DOMAIN="${input:-$DOMAIN}" + + # Set the Email user and sender. + printf "Email host (%s): " "${EMAIL_HOST}" + read -r input + EMAIL_HOST="${input:-$EMAIL_HOST}" + + # Set the Email port and sender. + printf "Email port (%s): " "${EMAIL_PORT}" + read -r input + EMAIL_PORT="${input:-$EMAIL_PORT}" + + # Set the Email user and sender. + printf "Email user (%s): " "${EMAIL_USER}" + read -r input + EMAIL_USER="${input:-$EMAIL_USER}" + + # Set the Email password. + printf "Email password (%s): " "${EMAIL_PASSWORD}" + read -r input + EMAIL_PASSWORD="${input:-$EMAIL_PASSWORD}" + + # Set the Motion user for webcontrol and livestream. + printf "Motion user (%s): " "${MOTION_USER}" + read -r input + MOTION_USER="${input:-$MOTION_USER}" + + # Set the Motion password for webcontrol and livestream. + printf "Motion password (%s): " "${MOTION_PASSWORD}" + read -r input + MOTION_PASSWORD="${input:-$MOTION_PASSWORD}" + + # Set the notification recipient. + printf "Notification recipient (%s): " "${NOTIFICATION_RECIPIENT}" + read -r input + NOTIFICATION_RECIPIENT="${input:-$NOTIFICATION_RECIPIENT}" +} + +print_settings() { + printf "Your settings:\n" + printf "Bucket: %s\n" "${BUCKET}" + printf "Camera name: %s\n" "${CAMERA_NAME}" + printf "Domain: %s\n" "${DOMAIN}" + printf "Email host: %s\n" "${EMAIL_HOST}" + printf "Email port: %s\n" "${EMAIL_PORT}" + printf "Email user: %s\n" "${EMAIL_USER}" + printf "Email password: %s\n" "${EMAIL_PASSWORD}" + printf "Motion user: %s\n" "${MOTION_USER}" + printf "Motion password: %s\n" "${MOTION_PASSWORD}" + printf "Notification recipient: %s\n" "${NOTIFICATION_RECIPIENT}" +} + +write_settings() { + for f in "${FILES[@]}"; do + sed -i "s/\${BUCKET}/${BUCKET}/g" "${f}" + sed -i "s/\${CAMERA_NAME}/${CAMERA_NAME}/g" "${f}" + sed -i "s/\${DOMAIN}/${DOMAIN}/g" "${f}" + sed -i "s/\${EMAIL_HOST}/${EMAIL_HOST}/g" "${f}" + sed -i "s/\${EMAIL_PORT}/${EMAIL_PORT}/g" "${f}" + sed -i "s/\${EMAIL_USER}/${EMAIL_USER}/g" "${f}" + sed -i "s/\${EMAIL_PASSWORD}/${EMAIL_PASSWORD}/g" "${f}" + sed -i "s/\${MOTION_USER}/${MOTION_USER}/g" "${f}" + sed -i "s/\${MOTION_PASSWORD}/${MOTION_PASSWORD}/g" "${f}" + sed -i "s/\${NOTIFICATION_RECIPIENT}/${NOTIFICATION_RECIPIENT}/g" "${f}" + done +} + +main() { + input_settings + + print_settings + + echo "Update files?" + select yn in "yes" "no"; do + case "${yn}" in + yes ) write_settings && exit 0 ;; + no ) exit 0 ;; + esac + done +} + +main "$@"