Refactor to use rsync server
This commit is contained in:
+6
-7
@@ -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}" \
|
||||
rsync --archive --verbose \
|
||||
"${PROJECT}/motion/${name}.jpg" \
|
||||
"${HOSTNAME}/photo/${name}.jpg"
|
||||
"${RSYNC_USER}@${RSYNC_SERVER}:/photo/${name}.jpg"
|
||||
}
|
||||
|
||||
delete_outdated() {
|
||||
|
||||
+4
-5
@@ -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}" \
|
||||
rsync --archive --verbose \
|
||||
"${HOME}/timelapse/${name}" \
|
||||
"${HOSTNAME}/timelapse/${name}"
|
||||
"${RSYNC_USER}@${RSYNC_SERVER}:/timelapse/${name}"
|
||||
|
||||
# Delete outdated files.
|
||||
# This assumes the timelapse is created on an hourly basis.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user