Files
teslausb/windows_archive/archive-teslacam-clips
cimryan cb35f069bf Merge branch 'master' into u/gocnak/rsync_archive
# Conflicts:
#	windows_archive/setup-teslausb
2018-10-23 19:37:33 -07:00

69 lines
1.5 KiB
Bash

#!/bin/bash -eu
LOG_FILE=/tmp/archive-teslacam-clips.log
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
log "Disconnected usb from host."
}
function ensure_archive_is_mounted () {
log "Ensuring cam archive is mounted..."
ensure_mountpoint_is_mounted_with_retry "$ARCHIVE_MOUNT"
log "Ensured cam archive is mounted."
}
log "Starting..."
if [ ! -r "/root/.teslaCamRsyncConfig" ]
then
ensure_archive_is_mounted
fi
disconnect_usb_drives_from_host
ensure_cam_file_is_mounted
fix_errors_in_cam_file
if [ -r "/root/.teslaCamRsyncConfig" ]
then
log "Archiving through rsync..."
/root/bin/archive-rsync
else
move_clips_to_archive
fi
unmount_cam_file
connect_usb_drives_to_host