Move CIFS-specific functions out of setup-teslausb.

This commit is contained in:
cimryan
2018-10-23 22:05:25 -07:00
parent 9261cc9b20
commit 1685fa78f7
8 changed files with 133 additions and 96 deletions

View File

@@ -0,0 +1,3 @@
#!/bin/bash -eu
echo "$(ping -c 1 -w 1 $archiveserver 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')"

View File

@@ -0,0 +1,16 @@
#!/bin/bash -eu
function configure_archive () {
local archive_server_ip_address="$1"
echo "Configuring the archive..."
echo "Configuring for Rsync..."
echo "user=$RSYNC_USER" > /root/.teslaCamRsyncConfig
echo "server=$RSYNC_SERVER" >> /root/.teslaCamRsyncConfig
echo "path=$RSYNC_PATH" >> /root/.teslaCamRsyncConfig
}
ARCHIVE_SERVER_IP_ADDRESS="$( /root/bin/get-archiveserver-ip-address.sh )"
configure_archive "$ARCHIVE_SERVER_IP_ADDRESS"

View File

@@ -0,0 +1 @@
#!/bin/bash -eu

View File

@@ -1,7 +1,5 @@
#!/bin/bash -eu
# Change the value on the right side of the equal sign to the name of the server hosting the archive.
ARCHIVE_HOST_NAME=archiveserver
ARCHIVE_HOST_NAME="$1"
LOG_FILE=/tmp/archiveloop.log

View File

@@ -0,0 +1,28 @@
#!/bin/bash -eu
cifs_version="${cifs_version:-3}"
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"

View File

@@ -44,54 +44,6 @@ function check_pushover_enabled () {
fi
}
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 write_archive_credentials_to () {
local file_path="$1"
echo "username=$shareuser" > "$file_path"
echo "password=$sharepassword" >> "$file_path"
}
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"
write_archive_credentials_to "$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"
}
function check_available_space () {
echo "Verifying that there is sufficient space available on the MicroSD card..."
@@ -139,49 +91,14 @@ function create_usb_drive_backing_files () {
/tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT"
}
function configure_archive () {
local archive_server_ip_address="$1"
echo "Configuring the archive..."
if [ $RSYNC_ENABLE = true ]
then
echo "Configuring for Rsync..."
echo "user=$RSYNC_USER" > /root/.teslaCamRsyncConfig
echo "server=$RSYNC_SERVER" >> /root/.teslaCamRsyncConfig
echo "path=$RSYNC_PATH" >> /root/.teslaCamRsyncConfig
else
local archive_path="/mnt/archive"
if [ ! -e "$archive_path" ]
then
mkdir "$archive_path"
fi
local credentials_file_path="/root/.teslaCamArchiveCredentials"
write_archive_credentials_to "$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."
fi
}
function configure_archive_scripts () {
echo "Configuring the archive scripts..."
mkdir /root/bin
pushd ~
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop
sed s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/ ~/archiveloop > /root/bin/archiveloop
rm ~/archiveloop
chmod +x /root/bin/archiveloop
popd
pushd /root/bin
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips
chmod +x archive-teslacam-clips
if [ $RSYNC_ENABLE = true ]
then
@@ -198,6 +115,8 @@ function configure_archive_scripts () {
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/disconnect-archive.sh
fi
chmod +x archiveloop
chmod +x archive-teslacam-clips
chmod +x archive-clips.sh
chmod +x connect-archive.sh
chmod +x disconnect-archive.sh
@@ -232,12 +151,12 @@ function log () {
}
log "Launching archival script..."
/root/bin/archiveloop &
/root/bin/archiveloop "$archiveserver" &
log "All done"
exit 0
EOF
cat ~/rc.local > /etc/rc.local
cat ~/rc.local >> /etc/rc.local
rm ~/rc.local
echo "Configured rc.local."
}
@@ -281,11 +200,28 @@ check_variable "campercent"
check_pushover_enabled
check_archive_server_reachable
pushd /root/bin
if [ $RSYNC_ENABLE = true ]
then
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/verify-archive-configuration.sh
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/configure-archive.sh
else
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/verify-archive-configuration.sh
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/configure-archive.sh
ARCHIVE_SERVER_IP_ADDRESS="$(ping -c 1 -w 1 $archiveserver 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')"
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/write-archive-credentials-to.sh
chmod +x write-archive-credentials-to.sh
fi
check_archive_mountable "$ARCHIVE_SERVER_IP_ADDRESS"
chmod +x verify-archive-configuration.sh
chmod +x configure-archive.sh
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/get-archiveserver-ip-address.sh
chmod +x get-archiveserver-ip-address.sh
popd
/root/bin/verify-archive-configuration.sh
check_available_space
@@ -303,7 +239,7 @@ echo "" >> /etc/fstab
create_usb_drive_backing_files
configure_archive "$ARCHIVE_SERVER_IP_ADDRESS"
/root/bin/configure-archive.sh
configure_rc_local

View File

@@ -0,0 +1,49 @@
#!/bin/bash -eu
cifs_version="${cifs_version:-3}"
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"

View File

@@ -0,0 +1,6 @@
#!/bin/bash -eu
local file_path="$1"
echo "username=$shareuser" > "$file_path"
echo "password=$sharepassword" >> "$file_path"