From c563f287ba383ca5fe45d99bc455b9b276339368 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 20:26:27 -0700 Subject: [PATCH] Make send-pushover safe to always invoke, and always invoke it. Split CIFS archiving to archive-cifs.sh --- windows_archive/archive-cifs.sh | 18 +++++++++++++++ windows_archive/archive-rsync | 24 +++++++------------- windows_archive/archive-teslacam-clips | 31 +++++--------------------- windows_archive/send-pushover | 19 +++++++++++----- windows_archive/setup-teslausb | 3 --- 5 files changed, 44 insertions(+), 51 deletions(-) create mode 100644 windows_archive/archive-cifs.sh diff --git a/windows_archive/archive-cifs.sh b/windows_archive/archive-cifs.sh new file mode 100644 index 0000000..ec3b4c0 --- /dev/null +++ b/windows_archive/archive-cifs.sh @@ -0,0 +1,18 @@ +#!/bin/bash -eu + +log "Moving clips to archive..." + +local move_count=0 + +for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do + [ -e "$file_name" ] || continue + log "Moving $file_name ..." + mv -- "$file_name" "$ARCHIVE_MOUNT" >> "$LOG_FILE" 2>&1 || echo "" + log "Moved $file_name." + move_count=$((move_count + 1)) +done +log "Moved $move_count file(s)." + +/root/bin/send-pushover "$num_files_moved" + +log "Finished moving clips to archive." diff --git a/windows_archive/archive-rsync b/windows_archive/archive-rsync index d163640..29f5a55 100644 --- a/windows_archive/archive-rsync +++ b/windows_archive/archive-rsync @@ -1,24 +1,16 @@ #!/bin/bash -eu -LOG_FILE=/tmp/archive-rsync.log - -function log () { - echo "$( date )" >> "$LOG_FILE" - echo "$1" >> "$LOG_FILE" -} +log "Archiving through rsync..." source /root/.teslaCamRsyncConfig -nfiles=$(rsync -auvh --stats --log-file=/tmp/archive-rsync-cmd.log /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') +num_files_moved=$(rsync -auvh --stats --log-file=/tmp/archive-rsync-cmd.log /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') -if [ $nfiles > 0 ] +/root/bin/send-pushover "$num_files_moved" + +if [ $num_files_moved > 0 ] then - if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $nfiles > 0] - then - log "Sending Pushover message for copied files." - /root/bin/send-pushover $nfiles - fi - log "Successfully synced files through rsync!" + log "Successfully synced files through rsync." else - log "No files to archive through rsync!" -fi \ No newline at end of file + log "No files to archive through rsync." +fi diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index c98d637..94e42d2 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -1,35 +1,13 @@ #!/bin/bash -eu -LOG_FILE=/tmp/archive-teslacam-clips.log -ARCHIVE_MOUNT=/mnt/archive +export LOG_FILE=/tmp/archive-teslacam-clips.log +export ARCHIVE_MOUNT=/mnt/archive function log () { echo "$( date )" >> "$LOG_FILE" echo "$1" >> "$LOG_FILE" } -function move_clips_to_archive () { - log "Moving clips to archive..." - local move_count=0 - for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do - [ -e "$file_name" ] || continue - log "Moving $file_name ..." - mv -- "$file_name" "$ARCHIVE_MOUNT" >> "$LOG_FILE" 2>&1 || echo "" - log "Moved $file_name." - move_count=$((move_count + 1)) - - done - log "Moved $move_count file(s)." - - if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $move_count > 0] - then - log "Sending Pushover message for copied files." - /root/bin/send-pushover $move_count - fi - - log "Finished moving clips to archive." -} - function disconnect_usb_drives_from_host () { log "Disconnecting usb from host..." modprobe -r g_mass_storage @@ -42,6 +20,8 @@ function ensure_archive_is_mounted () { log "Ensured cam archive is mounted." } +export -f log + log "Starting..." if [ ! -r "/root/.teslaCamRsyncConfig" ] @@ -57,10 +37,9 @@ fix_errors_in_cam_file if [ -r "/root/.teslaCamRsyncConfig" ] then - log "Archiving through rsync..." /root/bin/archive-rsync else - move_clips_to_archive + /root/bin/archive-cifs.sh fi unmount_cam_file diff --git a/windows_archive/send-pushover b/windows_archive/send-pushover index 6948c06..442833e 100644 --- a/windows_archive/send-pushover +++ b/windows_archive/send-pushover @@ -1,14 +1,21 @@ #!/bin/bash -eu +local num_files_moved="$1" + function log () { echo "$( date )" >> "$LOG_FILE" echo "$1" >> "$LOG_FILE" } -source /root/.teslaCamPushoverCredentials +if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $num_files_moved > 0] +then + log "Sending Pushover message for moved files." -curl -F "token=$pushover_app_key" \ --F "user=$pushover_user_key" \ --F "title=Dashcam Copy Complete" \ --F "message=$1 file(s) were copied." \ -https://api.pushover.net/1/messages + source /root/.teslaCamPushoverCredentials + + curl -F "token=$pushover_app_key" \ + -F "user=$pushover_user_key" \ + -F "title=Dashcam Copy Complete" \ + -F "message=$num_files_moved file(s) were copied." \ + https://api.pushover.net/1/messages +fi diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 9a0e2ee..a2460b2 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -199,13 +199,10 @@ function configure_archive_scripts () { } function configure_pushover_scripts() { -if [ ${USER_ENABLED_PUSHOVER} = "true" ] -then pushd /root/bin wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover chmod +x send-pushover popd -fi } function configure_rc_local () {