mirror of
https://github.com/cimryan/teslausb.git
synced 2026-03-01 12:40:33 +00:00
58 lines
1.3 KiB
Bash
58 lines
1.3 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..."
|
|
|
|
ensure_archive_is_mounted
|
|
|
|
disconnect_usb_drives_from_host
|
|
|
|
ensure_cam_file_is_mounted
|
|
|
|
fix_errors_in_cam_file
|
|
|
|
move_clips_to_archive
|
|
|
|
unmount_cam_file
|
|
|
|
connect_usb_drives_to_host
|