mirror of
https://github.com/cimryan/teslausb.git
synced 2026-03-01 04:30:33 +00:00
Separate files into those used for setup and those used at runtime.
Files used for both will go in the run tree.
This commit is contained in:
18
run/cifs_archive/archive-clips.sh
Normal file
18
run/cifs_archive/archive-clips.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
log "Moving clips to archive..."
|
||||
|
||||
NUM_FILES_MOVED=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."
|
||||
NUM_FILES_MOVED=$((NUM_FILES_MOVED + 1))
|
||||
done
|
||||
log "Moved $NUM_FILES_MOVED file(s)."
|
||||
|
||||
/root/bin/send-pushover "$NUM_FILES_MOVED"
|
||||
|
||||
log "Finished moving clips to archive."
|
||||
26
run/cifs_archive/configure-archive.sh
Normal file
26
run/cifs_archive/configure-archive.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
function configure_archive () {
|
||||
local archive_server_ip_address="$1"
|
||||
|
||||
echo "Configuring the archive..."
|
||||
|
||||
local archive_path="/mnt/archive"
|
||||
|
||||
if [ ! -e "$archive_path" ]
|
||||
then
|
||||
mkdir "$archive_path"
|
||||
fi
|
||||
|
||||
local credentials_file_path="/root/.teslaCamArchiveCredentials"
|
||||
|
||||
/root/bin/write-archive-credentials-to.sh "$credentials_file_path"
|
||||
|
||||
echo "//$archive_server_ip_address/$sharename $archive_path cifs vers=${cifs_version},credentials=${credentials_file_path},iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab
|
||||
|
||||
echo "Configured the archive."
|
||||
}
|
||||
|
||||
ARCHIVE_SERVER_IP_ADDRESS="$( /root/bin/get-archiveserver-ip-address.sh )"
|
||||
|
||||
configure_archive "$ARCHIVE_SERVER_IP_ADDRESS"
|
||||
9
run/cifs_archive/connect-archive.sh
Normal file
9
run/cifs_archive/connect-archive.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
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."
|
||||
}
|
||||
|
||||
ensure_archive_is_mounted
|
||||
2
run/cifs_archive/disconnect-archive.sh
Normal file
2
run/cifs_archive/disconnect-archive.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash -eu
|
||||
# Nothing to do. It's okay to leave the archive mounted.
|
||||
47
run/cifs_archive/verify-archive-configuration.sh
Normal file
47
run/cifs_archive/verify-archive-configuration.sh
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
function check_archive_server_reachable () {
|
||||
echo "Verifying that the archive server $archiveserver is reachable..."
|
||||
local serverunreachable=false
|
||||
ping -c 1 -w 1 "$archiveserver" 1>/dev/null 2>&1 || serverunreachable=true
|
||||
|
||||
if [ "$serverunreachable" = true ]
|
||||
then
|
||||
echo "STOP: The archive server $archiveserver is unreachable. Try specifying its IP address instead."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "The archive server is reachable."
|
||||
}
|
||||
|
||||
function check_archive_mountable () {
|
||||
local archive_server_ip_address="$1"
|
||||
|
||||
local test_mount_location="/tmp/archivetestmount"
|
||||
|
||||
if [ ! -e "$test_mount_location" ]
|
||||
then
|
||||
mkdir "$test_mount_location"
|
||||
fi
|
||||
|
||||
local tmp_credentials_file_path="/tmp/teslaCamArchiveCredentials"
|
||||
|
||||
/root/bin/write-archive-credentials-to.sh "$tmp_credentials_file_path"
|
||||
|
||||
local mount_failed=false
|
||||
mount -t cifs "//$archive_server_ip_address/$sharename" "$test_mount_location" -o "vers=${cifs_version},credentials=${tmp_credentials_file_path},iocharset=utf8,file_mode=0777,dir_mode=0777" || mount_failed=true
|
||||
|
||||
if [ "$mount_failed" = true ]
|
||||
then
|
||||
echo "STOP: The archive couldn't be mounted with CIFS version ${cifs_version}. Try specifying a lower number for the CIFS version like this: export cifs_version=2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
umount "$test_mount_location"
|
||||
}
|
||||
|
||||
check_archive_server_reachable
|
||||
|
||||
ARCHIVE_SERVER_IP_ADDRESS="$( /root/bin/get-archiveserver-ip-address.sh )"
|
||||
|
||||
check_archive_mountable "$ARCHIVE_SERVER_IP_ADDRESS"
|
||||
6
run/cifs_archive/write-archive-credentials-to.sh
Normal file
6
run/cifs_archive/write-archive-credentials-to.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
FILE_PATH="$1"
|
||||
|
||||
echo "username=$shareuser" > "$FILE_PATH"
|
||||
echo "password=$sharepassword" >> "$FILE_PATH"
|
||||
Reference in New Issue
Block a user