Make send-pushover safe to always invoke, and always invoke it. Split CIFS archiving to archive-cifs.sh

This commit is contained in:
cimryan
2018-10-23 20:26:27 -07:00
parent cb35f069bf
commit c563f287ba
5 changed files with 44 additions and 51 deletions

View File

@@ -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."

View File

@@ -1,24 +1,16 @@
#!/bin/bash -eu #!/bin/bash -eu
LOG_FILE=/tmp/archive-rsync.log log "Archiving through rsync..."
function log () {
echo "$( date )" >> "$LOG_FILE"
echo "$1" >> "$LOG_FILE"
}
source /root/.teslaCamRsyncConfig 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 then
if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $nfiles > 0] log "Successfully synced files through rsync."
then
log "Sending Pushover message for copied files."
/root/bin/send-pushover $nfiles
fi
log "Successfully synced files through rsync!"
else else
log "No files to archive through rsync!" log "No files to archive through rsync."
fi fi

View File

@@ -1,35 +1,13 @@
#!/bin/bash -eu #!/bin/bash -eu
LOG_FILE=/tmp/archive-teslacam-clips.log export LOG_FILE=/tmp/archive-teslacam-clips.log
ARCHIVE_MOUNT=/mnt/archive export ARCHIVE_MOUNT=/mnt/archive
function log () { function log () {
echo "$( date )" >> "$LOG_FILE" echo "$( date )" >> "$LOG_FILE"
echo "$1" >> "$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 () { function disconnect_usb_drives_from_host () {
log "Disconnecting usb from host..." log "Disconnecting usb from host..."
modprobe -r g_mass_storage modprobe -r g_mass_storage
@@ -42,6 +20,8 @@ function ensure_archive_is_mounted () {
log "Ensured cam archive is mounted." log "Ensured cam archive is mounted."
} }
export -f log
log "Starting..." log "Starting..."
if [ ! -r "/root/.teslaCamRsyncConfig" ] if [ ! -r "/root/.teslaCamRsyncConfig" ]
@@ -57,10 +37,9 @@ fix_errors_in_cam_file
if [ -r "/root/.teslaCamRsyncConfig" ] if [ -r "/root/.teslaCamRsyncConfig" ]
then then
log "Archiving through rsync..."
/root/bin/archive-rsync /root/bin/archive-rsync
else else
move_clips_to_archive /root/bin/archive-cifs.sh
fi fi
unmount_cam_file unmount_cam_file

View File

@@ -1,14 +1,21 @@
#!/bin/bash -eu #!/bin/bash -eu
local num_files_moved="$1"
function log () { function log () {
echo "$( date )" >> "$LOG_FILE" echo "$( date )" >> "$LOG_FILE"
echo "$1" >> "$LOG_FILE" echo "$1" >> "$LOG_FILE"
} }
if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $num_files_moved > 0]
then
log "Sending Pushover message for moved files."
source /root/.teslaCamPushoverCredentials source /root/.teslaCamPushoverCredentials
curl -F "token=$pushover_app_key" \ curl -F "token=$pushover_app_key" \
-F "user=$pushover_user_key" \ -F "user=$pushover_user_key" \
-F "title=Dashcam Copy Complete" \ -F "title=Dashcam Copy Complete" \
-F "message=$1 file(s) were copied." \ -F "message=$num_files_moved file(s) were copied." \
https://api.pushover.net/1/messages https://api.pushover.net/1/messages
fi

View File

@@ -199,13 +199,10 @@ function configure_archive_scripts () {
} }
function configure_pushover_scripts() { function configure_pushover_scripts() {
if [ ${USER_ENABLED_PUSHOVER} = "true" ]
then
pushd /root/bin pushd /root/bin
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover
chmod +x send-pushover chmod +x send-pushover
popd popd
fi
} }
function configure_rc_local () { function configure_rc_local () {