Verify that the archive is mountable before making changes to the file systems.

This commit is contained in:
cimryan
2018-10-19 14:26:10 -07:00
parent eb21377738
commit 5788bc4f7b

View File

@@ -56,6 +56,38 @@ function check_archive_server_reachable () {
echo "The archive server is reachable." 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
}
function check_available_space () { function check_available_space () {
echo "Verifying that there is sufficient space available on the MicroSD card..." echo "Verifying that there is sufficient space available on the MicroSD card..."
@@ -70,6 +102,7 @@ function check_available_space () {
echo "There is sufficient space available." echo "There is sufficient space available."
} }
function get_ancillary_setup_scripts () { function get_ancillary_setup_scripts () {
pushd /tmp pushd /tmp
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh
@@ -104,13 +137,23 @@ function create_usb_drive_backing_files () {
} }
function configure_archive () { function configure_archive () {
echo "Configuring the archive..." local archive_server_ip_address="$1"
mkdir /mnt/archive
local 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 '()')"
echo "//$archive_server_ip_address/$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 "Configuring the archive..."
echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials
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." echo "Configured the archive."
} }
@@ -190,6 +233,11 @@ function make_root_fs_readonly () {
echo "Verifying environment variables..." echo "Verifying environment variables..."
if [ ! -n "${cifs_version+x}" ]
then
cifs_version=3
fi
check_variable "archiveserver" check_variable "archiveserver"
check_variable "sharename" check_variable "sharename"
check_variable "shareuser" check_variable "shareuser"
@@ -200,6 +248,10 @@ check_pushover_enabled
check_archive_server_reachable check_archive_server_reachable
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 '()')"
check_archive_mountable "$ARCHIVE_SERVER_IP_ADDRESS"
check_available_space check_available_space
get_ancillary_setup_scripts get_ancillary_setup_scripts
@@ -216,7 +268,7 @@ echo "" >> /etc/fstab
create_usb_drive_backing_files create_usb_drive_backing_files
configure_archive configure_archive "$ARCHIVE_SERVER_IP_ADDRESS"
configure_rc_local configure_rc_local