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
LOGFILE=/tmp/archive-teslacam-clips.log
LOG_FILE=/tmp/archive-teslacam-clips.log
CAM_MOUNT=/mnt/cam
ARCHIVE_MOUNT=/mnt/archive
function log () {
echo "$( date )" >> "$LOGFILE"
echo "$1" >> "$LOGFILE"
echo "$( date )" >> "$LOG_FILE"
echo "$1" >> "$LOG_FILE"
}
function retry () {
@@ -36,7 +38,7 @@ function mount_mountpoint () {
log "Mounting $mount_point..."
local mounted=true
mount "$mount_point" >> "$LOGFILE" 2>&1 || mounted=false
mount "$mount_point" >> "$LOG_FILE" 2>&1 || mounted=false
if [ "$mounted" = true ]
then
log "Mounted $mount_point."
@@ -69,63 +71,57 @@ function ensure_mountpoint_is_mounted_with_retry () {
function move_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
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."
done
log "Finished moving clips to archive."
}
function disconnect_usb_from_host () {
function disconnect_usb_drives_from_host () {
log "Disconnecting usb from host..."
modprobe -r g_mass_storage
log "Disconnected usb from host."
}
function fix_errors_on_drive () {
function fix_errors_on_cam_drive () {
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."
}
function mount_usb_drive_locally () {
log "Mounting usb locally..."
mount /mnt/usb_share
log "Mounted usb locally."
}
function ensure_cam_archive_is_mounted () {
function ensure_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."
}
function ensure_usb_share_is_mounted () {
log "Ensuring usb share is mounted..."
ensure_mountpoint_is_mounted_with_retry /mnt/usb_share
log "Ensured usb share is mounted."
function ensure_cam_drive_is_mounted () {
log "Ensuring cam drive is mounted..."
ensure_mountpoint_is_mounted_with_retry "$CAM_MOUNT"
log "Ensured cam drive is mounted."
}
function unmount_usb_share () {
log "Unmounting usb share..."
umount /mnt/usb_share
log "Unmounted usb share."
function unmount_cam_drive () {
log "Unmounting cam drive..."
umount "$CAM_MOUNT"
log "Unmounted cam drive."
}
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
unmount_usb_share
unmount_cam_drive
connect_usb_to_host

View File

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

View File

@@ -45,13 +45,13 @@ cat ~/cmdline.txt | sed 's/[[:space:]]\+modules-load=[^ [:space:]]\+//' | sed 's
rm ~/cmdline.txt
fallocate -l "$size"K /piusb.bin
mkdosfs /piusb.bin -F 32 -I -n TESLAUSB
mkdir /mnt/usb_share
mkdir /mnt/cam_archive
mkfs.vfat /piusb.bin -F 32 -n CAM
mkdir /mnt/cam
mkdir /mnt/archive
echo "" >> /etc/fstab
echo "/piusb.bin /mnt/usb_share vfat noauto,users,umask=000 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 "/piusb.bin /mnt/cam vfat noauto,users,umask=000,debug 0 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 "password=$sharepassword" >> /root/.teslaCamArchiveCredentials