Move moutpoints: usb_share -> cam, cam_archive -> archive

This commit is contained in:
cimryan
2018-10-13 17:26:58 -07:00
parent 641779c1a2
commit 9cfce11bd4
3 changed files with 34 additions and 38 deletions

View File

@@ -1,10 +1,12 @@
#!/bin/bash -eu #!/bin/bash -eu
LOGFILE=/tmp/archive-teslacam-clips.log LOG_FILE=/tmp/archive-teslacam-clips.log
CAM_MOUNT=/mnt/cam
ARCHIVE_MOUNT=/mnt/archive
function log () { function log () {
echo "$( date )" >> "$LOGFILE" echo "$( date )" >> "$LOG_FILE"
echo "$1" >> "$LOGFILE" echo "$1" >> "$LOG_FILE"
} }
function retry () { function retry () {
@@ -36,7 +38,7 @@ function mount_mountpoint () {
log "Mounting $mount_point..." log "Mounting $mount_point..."
local mounted=true local mounted=true
mount "$mount_point" >> "$LOGFILE" 2>&1 || mounted=false mount "$mount_point" >> "$LOG_FILE" 2>&1 || mounted=false
if [ "$mounted" = true ] if [ "$mounted" = true ]
then then
log "Mounted $mount_point." log "Mounted $mount_point."
@@ -69,63 +71,57 @@ function ensure_mountpoint_is_mounted_with_retry () {
function move_clips_to_archive () { function move_clips_to_archive () {
log "Moving clips to archive..." log "Moving clips to archive..."
for file_name in /mnt/usb_share/TeslaCam/saved*; do for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do
[ -e "$file_name" ] || continue [ -e "$file_name" ] || continue
log "Moving $file_name ..." log "Moving $file_name ..."
mv -- "$file_name" /mnt/cam_archive >> "$LOGFILE" 2>&1 || echo "" mv -- "$file_name" "$CAM_MOUNT" >> "$LOG_FILE" 2>&1 || echo ""
log "Moved $file_name." log "Moved $file_name."
done done
log "Finished moving clips to archive." log "Finished moving clips to archive."
} }
function disconnect_usb_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
log "Disconnected usb from host." log "Disconnected usb from host."
} }
function fix_errors_on_drive () { function fix_errors_on_cam_drive () {
log "Running fsck..." log "Running fsck..."
/sbin/fsck /mnt/usb_share -- -a >> "$LOGFILE" 2>&1 || echo "" /sbin/fsck "$CAM_MOUNT" -- -a >> "$LOG_FILE" 2>&1 || echo ""
log "Finished running fsck." log "Finished running fsck."
} }
function mount_usb_drive_locally () { function ensure_archive_is_mounted () {
log "Mounting usb locally..."
mount /mnt/usb_share
log "Mounted usb locally."
}
function ensure_cam_archive_is_mounted () {
log "Ensuring cam archive is mounted..." log "Ensuring cam archive is mounted..."
ensure_mountpoint_is_mounted_with_retry /mnt/cam_archive ensure_mountpoint_is_mounted_with_retry "$CAM_MOUNT"
log "Ensured cam archive is mounted." log "Ensured cam archive is mounted."
} }
function ensure_usb_share_is_mounted () { function ensure_cam_drive_is_mounted () {
log "Ensuring usb share is mounted..." log "Ensuring cam drive is mounted..."
ensure_mountpoint_is_mounted_with_retry /mnt/usb_share ensure_mountpoint_is_mounted_with_retry "$CAM_MOUNT"
log "Ensured usb share is mounted." log "Ensured cam drive is mounted."
} }
function unmount_usb_share () { function unmount_cam_drive () {
log "Unmounting usb share..." log "Unmounting cam drive..."
umount /mnt/usb_share umount "$CAM_MOUNT"
log "Unmounted usb share." log "Unmounted cam drive."
} }
log "Starting..." log "Starting..."
ensure_cam_archive_is_mounted ensure_archive_is_mounted
disconnect_usb_from_host disconnect_usb_drives_from_host
fix_errors_on_drive fix_errors_on_cam_drive
ensure_usb_share_is_mounted ensure_cam_drive_is_mounted
move_clips_to_archive move_clips_to_archive
unmount_usb_share unmount_cam_drive
connect_usb_to_host connect_usb_to_host

View File

@@ -20,7 +20,7 @@ function archive_is_reachable () {
true true
} }
function connect_usb_to_host() { function connect_usb_drives_to_host() {
log "Connecting usb to host..." log "Connecting usb to host..."
modprobe g_mass_storage modprobe g_mass_storage
log "Connected usb to host." log "Connected usb to host."
@@ -58,7 +58,7 @@ function wait_for_archive_to_be_unreachable () {
done done
} }
export -f connect_usb_to_host export -f connect_usb_drives_to_host
log "Starting..." log "Starting..."
@@ -68,7 +68,7 @@ then
wait_for_archive_to_be_unreachable wait_for_archive_to_be_unreachable
else else
connect_usb_to_host connect_usb_drives_to_host
fi fi
while [ true ] while [ true ]

View File

@@ -45,13 +45,13 @@ cat ~/cmdline.txt | sed 's/[[:space:]]\+modules-load=[^ [:space:]]\+//' | sed 's
rm ~/cmdline.txt rm ~/cmdline.txt
fallocate -l "$size"K /piusb.bin fallocate -l "$size"K /piusb.bin
mkdosfs /piusb.bin -F 32 -I -n TESLAUSB mkfs.vfat /piusb.bin -F 32 -n CAM
mkdir /mnt/usb_share mkdir /mnt/cam
mkdir /mnt/cam_archive mkdir /mnt/archive
echo "" >> /etc/fstab echo "" >> /etc/fstab
echo "/piusb.bin /mnt/usb_share vfat noauto,users,umask=000 0 0" >> /etc/fstab echo "/piusb.bin /mnt/cam vfat noauto,users,umask=000,debug 0 0" >> /etc/fstab
echo "//$archiveserverip/$sharename /mnt/cam_archive cifs vers=3,credentials=/root/.teslaCamArchiveCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab echo "//$archiveserverip/$sharename /mnt/archive cifs vers=3,credentials=/root/.teslaCamArchiveCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab
echo "username=$shareuser" > /root/.teslaCamArchiveCredentials echo "username=$shareuser" > /root/.teslaCamArchiveCredentials
echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials