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