mirror of
https://github.com/cimryan/teslausb.git
synced 2026-02-28 20:20:32 +00:00
Avoid connecting the USB drive if it'll just immediately be disconnected.
This commit is contained in:
@@ -44,7 +44,7 @@ function move_clips_to_archive () {
|
||||
for file_name in /mnt/usb_share/TeslaCam/saved*; do
|
||||
[ -e "$file_name" ] || continue
|
||||
log "Moving $file_name ..."
|
||||
mv -- "$file_name" /mnt/cam_archive >> "$LOGFILE" 2>&1
|
||||
mv -- "$file_name" /mnt/cam_archive >> "$LOGFILE" 2>&1 || echo ""
|
||||
log "Moved $file_name."
|
||||
done
|
||||
log "Finished moving clips to archive."
|
||||
@@ -56,6 +56,12 @@ function disconnect_usb_from_host () {
|
||||
log "Disconnected usb from host."
|
||||
}
|
||||
|
||||
function fix_errors_on_drive () {
|
||||
log "Running fsck..."
|
||||
/sbin/fsck /mnt/usb_share -- -a >> "$LOGFILE" 2>&1 || echo ""
|
||||
log "Finished running fsck."
|
||||
}
|
||||
|
||||
function mount_usb_drive_locally () {
|
||||
log "Mounting usb locally..."
|
||||
mount /mnt/usb_share
|
||||
@@ -80,22 +86,18 @@ function unmount_usb_share () {
|
||||
log "Unmounted usb share."
|
||||
}
|
||||
|
||||
function connect_usb_to_host() {
|
||||
log "Connecting usb to host..."
|
||||
modprobe g_mass_storage
|
||||
log "Connected usb to host."
|
||||
}
|
||||
|
||||
log "Starting..."
|
||||
|
||||
ensure_cam_archive_is_mounted
|
||||
|
||||
disconnect_usb_from_host
|
||||
|
||||
fix_errors_on_drive
|
||||
|
||||
ensure_usb_share_is_mounted
|
||||
|
||||
move_clips_to_archive
|
||||
|
||||
unmount_usb_share
|
||||
|
||||
connect_usb_to_host
|
||||
connect_usb_to_host
|
||||
@@ -4,16 +4,12 @@
|
||||
ARCHIVE_HOST_NAME=archiveserver
|
||||
LOGFILE=/tmp/archiveloop.log
|
||||
|
||||
function clear_log () {
|
||||
rm "$LOGFILE" > /dev/null 2>&1 || echo ""
|
||||
}
|
||||
|
||||
function log () {
|
||||
echo "$( date )" >> "$LOGFILE"
|
||||
echo "$1" >> "$LOGFILE"
|
||||
}
|
||||
|
||||
function check_archive_reachability () {
|
||||
function archive_is_reachable () {
|
||||
local reachable=true
|
||||
ping -q -w 1 -c 1 "$ARCHIVE_HOST_NAME" > /dev/null 2>&1 || reachable=false
|
||||
if [ "$reachable" = false ]
|
||||
@@ -24,11 +20,17 @@ function check_archive_reachability () {
|
||||
true
|
||||
}
|
||||
|
||||
function connect_usb_to_host() {
|
||||
log "Connecting usb to host..."
|
||||
modprobe g_mass_storage
|
||||
log "Connected usb to host."
|
||||
}
|
||||
|
||||
function wait_for_archive_to_be_reachable () {
|
||||
log "Waiting for archive to be reachable..."
|
||||
while [ true ]
|
||||
do
|
||||
if check_archive_reachability
|
||||
if archive_is_reachable
|
||||
then
|
||||
log "Archive is reachable."
|
||||
break
|
||||
@@ -47,7 +49,7 @@ function wait_for_archive_to_be_unreachable () {
|
||||
log "Waiting for archive to be unreachable..."
|
||||
while [ true ]
|
||||
do
|
||||
if ! check_archive_reachability
|
||||
if ! archive_is_reachable
|
||||
then
|
||||
log "Archive is unreachable."
|
||||
break
|
||||
@@ -56,10 +58,17 @@ function wait_for_archive_to_be_unreachable () {
|
||||
done
|
||||
}
|
||||
|
||||
clear_log
|
||||
export -f connect_usb_to_host
|
||||
|
||||
log "Starting..."
|
||||
|
||||
if archive_is_reachable
|
||||
then
|
||||
archive_clips
|
||||
else
|
||||
connect_usb_to_host
|
||||
fi
|
||||
|
||||
while [ true ]
|
||||
do
|
||||
wait_for_archive_to_be_reachable
|
||||
@@ -67,4 +76,4 @@ do
|
||||
archive_clips
|
||||
|
||||
wait_for_archive_to_be_unreachable
|
||||
done
|
||||
done
|
||||
@@ -73,10 +73,6 @@ function log () {
|
||||
echo "$1" >> "$LOGFILE"
|
||||
}
|
||||
|
||||
log "Running fsck..."
|
||||
/sbin/fsck /mnt/usb_share -- -a >> "$LOGFILE" 2>&1 || echo ""
|
||||
log "Running modprobe..."
|
||||
/sbin/modprobe g_mass_storage >> "$LOGFILE" 2>&1
|
||||
log "Launching archival script..."
|
||||
/root/bin/archiveloop &
|
||||
log "All done"
|
||||
|
||||
Reference in New Issue
Block a user