From 4d0b010e8df7347fa14043c320240c0f6daf9411 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Mon, 29 Oct 2018 15:06:46 -0700 Subject: [PATCH 01/38] removing since this is done in configure-archive and to make it more consistent with the others --- run/cifs_archive/verify-archive-configuration.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/run/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh index 5bbc131..b7d47e1 100644 --- a/run/cifs_archive/verify-archive-configuration.sh +++ b/run/cifs_archive/verify-archive-configuration.sh @@ -24,10 +24,6 @@ function check_archive_mountable () { 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 From d91aff3ced40f191b9684e937b162f3153c94cb7 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Mon, 29 Oct 2018 16:56:30 -0700 Subject: [PATCH 02/38] remove write archive dependency --- run/cifs_archive/configure-archive.sh | 4 ++-- run/cifs_archive/write-archive-credentials-to.sh | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 run/cifs_archive/write-archive-credentials-to.sh diff --git a/run/cifs_archive/configure-archive.sh b/run/cifs_archive/configure-archive.sh index eff994f..f6c4fe4 100644 --- a/run/cifs_archive/configure-archive.sh +++ b/run/cifs_archive/configure-archive.sh @@ -13,8 +13,8 @@ function configure_archive () { fi local credentials_file_path="/root/.teslaCamArchiveCredentials" - - /root/bin/write-archive-credentials-to.sh "$credentials_file_path" + echo "username=$shareuser" > "$credentials_file_path" + echo "password=$sharepassword" >> "$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 diff --git a/run/cifs_archive/write-archive-credentials-to.sh b/run/cifs_archive/write-archive-credentials-to.sh deleted file mode 100644 index edce256..0000000 --- a/run/cifs_archive/write-archive-credentials-to.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -eu - -FILE_PATH="$1" - -echo "username=$shareuser" > "$FILE_PATH" -echo "password=$sharepassword" >> "$FILE_PATH" From e543363009b83931937eea45c799c7d85170eaa5 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Mon, 29 Oct 2018 16:57:40 -0700 Subject: [PATCH 03/38] clean up the archive server set up routine --- setup/pi/setup-teslausb | 106 +++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index d92ad4b..ee8a9dd 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -113,6 +113,43 @@ function check_pushover_enabled () { fi } +function check_archive_configs () { + + RSYNC_ENABLE="${RSYNC_ENABLE:-false}" + RCLONE_ENABLE="${RCLONE_ENABLE:-false}" + + if [ "$RSYNC_ENABLE" = true ] && [ "$RCLONE_ENABLE" = true ] + then + echo "STOP: Cannot enable rsync and rclone at the same time" + exit 1 + fi + + if [ "$RSYNC_ENABLE" = true ] + then + check_variable "RSYNC_USER" + check_variable "RSYNC_SERVER" + export archiveserver="$RSYNC_SERVER" + check_variable "RSYNC_PATH" + export archive_module="run/rsync_archive" + elif [ "$RCLONE_ENABLE" = true ] + then + check_variable "RCLONE_DRIVE" + check_variable "RCLONE_PATH" + # since it's a cloud hosted drive we'll just set this to google dns + export archiveserver="8.8.8.8" + export archive_module="run/rclone_archive" + else # Else for now, TODO allow both for more redundancy? + check_variable "sharename" + check_variable "shareuser" + check_variable "sharepassword" + + export cifs_version="${cifs_version:-3.0}" + export archive_module="run/cifs_archive" + fi + + check_variable "archiveserver" +} + function check_available_space () { setup_progress "Verifying that there is sufficient space available on the MicroSD card..." @@ -190,28 +227,23 @@ function configure_archive_scripts () { setup_progress "Configuring the archive scripts..." get_script /root/bin archiveloop run - - if [ $RSYNC_ENABLE = true ] - then - get_script /root/bin archive-clips.sh run/rsync_archive - get_script /root/bin connect-archive.sh run/rsync_archive - get_script /root/bin disconnect-archive.sh run/rsync_archive - elif [ $RCLONE_ENABLE = true ] - then - get_script /root/bin archive-clips.sh run/rclone_archive - get_script /root/bin connect-archive.sh run/rclone_archive - get_script /root/bin disconnect-archive.sh run/rclone_archive - else - get_script /root/bin archive-clips.sh run/cifs_archive - get_script /root/bin connect-archive.sh run/cifs_archive - get_script /root/bin disconnect-archive.sh run/cifs_archive - fi - get_script /root/bin remountfs_rw run setup_progress "Configured the archive scripts." } +function install_archive_scripts () { + check_variable "archive_module" + echo $archive_module + + local install_path="/root/bin" + get_script $install_path verify-archive-configuration.sh $archive_module + get_script $install_path configure-archive.sh $archive_module + get_script $install_path archive-clips.sh $archive_module + get_script $install_path connect-archive.sh $archive_module + get_script $install_path disconnect-archive.sh $archive_module +} + function configure_pushover_scripts() { get_script /root/bin send-pushover run } @@ -274,32 +306,8 @@ headless_setup_progress_flash 1 setup_progress "Verifying environment variables..." -RSYNC_ENABLE="${RSYNC_ENABLE:-false}" -RCLONE_ENABLE="${RCLONE_ENABLE:-false}" - -if [ "$RSYNC_ENABLE" = true ] -then - check_variable "RSYNC_USER" - check_variable "RSYNC_SERVER" - export archiveserver="$RSYNC_SERVER" - check_variable "RSYNC_PATH" -elif [ "$RCLONE_ENABLE" = true ] -then - check_variable "RCLONE_DRIVE" - check_variable "RCLONE_PATH" - # since it's a cloud hosted drive we'll just set this to google dns - export archiveserver="8.8.8.8" -else # Else for now, TODO allow both for more redundancy? - check_variable "sharename" - check_variable "shareuser" - check_variable "sharepassword" - - export cifs_version="${cifs_version:-3.0}" -fi - -check_variable "archiveserver" check_variable "campercent" - +check_archive_configs check_pushover_enabled # Flash for Stage 3 headless (grab scripts) @@ -312,19 +320,7 @@ then mkdir /root/bin fi -if [ "$RSYNC_ENABLE" = true ] -then - get_script /root/bin verify-archive-configuration.sh run/rsync_archive - get_script /root/bin configure-archive.sh run/rsync_archive -elif [ "$RCLONE_ENABLE" = true ] -then - get_script /root/bin verify-archive-configuration.sh run/rclone_archive - get_script /root/bin configure-archive.sh run/rclone_archive -else - get_script /root/bin verify-archive-configuration.sh run/cifs_archive - get_script /root/bin configure-archive.sh run/cifs_archive - get_script /root/bin write-archive-credentials-to.sh run/cifs_archive -fi +install_archive_scripts get_script /root/bin get-archiveserver-ip-address.sh run From c54c5c26c3a3a78d016c5a98a61379fe553a8113 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Mon, 29 Oct 2018 18:52:53 -0700 Subject: [PATCH 04/38] fixing typo --- setup/pi/make-root-fs-readonly.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/pi/make-root-fs-readonly.sh b/setup/pi/make-root-fs-readonly.sh index fdf2ba6..aeafeb0 100644 --- a/setup/pi/make-root-fs-readonly.sh +++ b/setup/pi/make-root-fs-readonly.sh @@ -25,7 +25,7 @@ append_cmdline_txt_param ro # Move fake-hwclock.data to /mutable directory so it can be updated if ! findmnt --mountpoint /mutable then - echo "Mounting the multable partition..." + echo "Mounting the mutable partition..." mount /mutable echo "Mounted." fi From 0e016fb17621f370e76f861997a3622579225840 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Mon, 29 Oct 2018 19:03:29 -0700 Subject: [PATCH 05/38] had a debug echo in there -- making it a log message instead --- setup/pi/setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index ee8a9dd..d8e889a 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -234,7 +234,7 @@ function configure_archive_scripts () { function install_archive_scripts () { check_variable "archive_module" - echo $archive_module + echo "Installing scripts for archive module: $archive_module" local install_path="/root/bin" get_script $install_path verify-archive-configuration.sh $archive_module From ef523f542d20f4565bf9a6fb4827d092565fa1e3 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Mon, 29 Oct 2018 22:56:11 -0700 Subject: [PATCH 06/38] making changes to reflect upstream changes --- setup/pi/setup-teslausb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index d8e889a..b80034e 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -120,7 +120,7 @@ function check_archive_configs () { if [ "$RSYNC_ENABLE" = true ] && [ "$RCLONE_ENABLE" = true ] then - echo "STOP: Cannot enable rsync and rclone at the same time" + setup_progress "STOP: Cannot enable rsync and rclone at the same time" exit 1 fi @@ -234,7 +234,7 @@ function configure_archive_scripts () { function install_archive_scripts () { check_variable "archive_module" - echo "Installing scripts for archive module: $archive_module" + setup_progress "Installing scripts for archive module: $archive_module" local install_path="/root/bin" get_script $install_path verify-archive-configuration.sh $archive_module From fc1568db6142cf49007809bd73edcf7b3f4bf5c1 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Mon, 29 Oct 2018 23:59:04 -0700 Subject: [PATCH 07/38] fixing cifs issue with my last change and reordering so we don't need a separate credential file --- run/cifs_archive/verify-archive-configuration.sh | 2 ++ setup/pi/setup-teslausb | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/run/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh index b7d47e1..684a42b 100644 --- a/run/cifs_archive/verify-archive-configuration.sh +++ b/run/cifs_archive/verify-archive-configuration.sh @@ -24,6 +24,8 @@ function check_archive_mountable () { mkdir "$test_mount_location" fi + local tmp_credentials_file_path="/root/.teslaCamArchiveCredentials" + 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 diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index b80034e..0b52fe1 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -320,10 +320,10 @@ then mkdir /root/bin fi -install_archive_scripts - get_script /root/bin get-archiveserver-ip-address.sh run +install_archive_scripts +/root/bin/configure-archive.sh /root/bin/verify-archive-configuration.sh check_available_space @@ -332,7 +332,6 @@ get_ancillary_setup_scripts pushd ~ - configure_archive_scripts configure_pushover_scripts @@ -346,8 +345,6 @@ headless_setup_progress_flash 3 create_usb_drive_backing_files -/root/bin/configure-archive.sh - configure_rc_local configure_hostname From 9254d857be49e573916553ecd10a344394e7df7a Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Tue, 30 Oct 2018 00:32:01 -0700 Subject: [PATCH 08/38] - fixed adafruit link to the correct official case - added zero stem option because it's cool - added hint about setting campercent for the music option --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e95413c..89a6ffc 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,10 @@ Required: * A mechanism to connect the Pi to the Tesla. Either: * A USB A/Micro B cable: [Adafruit](https://www.adafruit.com/product/898) or [Amazon](https://www.amazon.com/gp/product/B013G4EAEI/), or * A USB A Add-on Board if you want to plug your Pi into your Tesla like a USB drive instead of using a cable. [Amazon](https://www.amazon.com/gp/product/B07BK2BR6C/) + * A PCB kit if you want the lowest profile possible and you're able to solder. [Sparkfun](https://www.sparkfun.com/products/14526) Optional: -* A case. The "Official" case: [Adafruit](https://www.adafruit.com/product/2885) or [Amazon](https://www.amazon.com/gp/product/B06Y593MHV). There are many others to choose from. Note that the official case won't work with the USB A Add on board. +* A case. The "Official" case: [Adafruit](https://www.adafruit.com/product/3446) or [Amazon](https://www.amazon.com/gp/product/B06Y593MHV). There are many others to choose from. Note that the official case won't work with the USB A Add-on board or the PCB kit. * USB Splitter if you don't want to lose a front USB port. [The Onvian Splitter](https://www.amazon.com/gp/product/B01KX4TKH6) has been reported working by multiple people on reddit. ### Software @@ -94,6 +95,8 @@ On the next boot, the Pi hostname will become `teslausb`, so future `ssh` sessio Your Pi is now ready to be plugged into your Tesla. If you want to add music to the Pi, follow the instructions in the next section. ## (Optional) Add music to the Pi +> Note: If you set `campercent` to 100% this drive will not show up + Connect the Pi to a computer. If you're using a cable be sure to use the port labeled "USB" on the circuitboard. 1. Wait for the Pi to show up on the computer as a USB drive. 1. Copy any music you'd like to the drive labeled MUSIC. From 7bc57b102597bcb76433dc46a464976aad0cc1ce Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Tue, 30 Oct 2018 00:35:47 -0700 Subject: [PATCH 09/38] grammar police --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 89a6ffc..eabba21 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Required: * A Micro SD card, at least 8 GB in size, and an adapter (if necessary) to connect the card to your computer. * A mechanism to connect the Pi to the Tesla. Either: * A USB A/Micro B cable: [Adafruit](https://www.adafruit.com/product/898) or [Amazon](https://www.amazon.com/gp/product/B013G4EAEI/), or - * A USB A Add-on Board if you want to plug your Pi into your Tesla like a USB drive instead of using a cable. [Amazon](https://www.amazon.com/gp/product/B07BK2BR6C/) + * A USB A Add-on Board if you want to plug your Pi into your Tesla like a USB drive instead of using a cable. [Amazon](https://www.amazon.com/gp/product/B07BK2BR6C/), or * A PCB kit if you want the lowest profile possible and you're able to solder. [Sparkfun](https://www.sparkfun.com/products/14526) Optional: From bb9347b1153de9906b4876aabbacc7a5ad6a3c98 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Tue, 30 Oct 2018 16:44:38 -0700 Subject: [PATCH 10/38] since this is an undocumented configuration variable we'll move this into the main cifs config --- run/cifs_archive/configure-archive.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run/cifs_archive/configure-archive.sh b/run/cifs_archive/configure-archive.sh index f6c4fe4..a3e4ebd 100644 --- a/run/cifs_archive/configure-archive.sh +++ b/run/cifs_archive/configure-archive.sh @@ -12,6 +12,8 @@ function configure_archive () { mkdir "$archive_path" fi + local cifs_version="${cifs_version:-3.0}" + local credentials_file_path="/root/.teslaCamArchiveCredentials" echo "username=$shareuser" > "$credentials_file_path" echo "password=$sharepassword" >> "$credentials_file_path" From 7c3a5f4b94e175acf851be09dabc181cfb99bff3 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Tue, 30 Oct 2018 18:05:35 -0700 Subject: [PATCH 11/38] change this function to be more generic and taken in server name as an argument instead of a environment variable --- run/get-archiveserver-ip-address.sh | 3 --- run/lookup-ip-address.sh | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 run/get-archiveserver-ip-address.sh create mode 100644 run/lookup-ip-address.sh diff --git a/run/get-archiveserver-ip-address.sh b/run/get-archiveserver-ip-address.sh deleted file mode 100644 index 8a3936e..0000000 --- a/run/get-archiveserver-ip-address.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/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 '()')" \ No newline at end of file diff --git a/run/lookup-ip-address.sh b/run/lookup-ip-address.sh new file mode 100644 index 0000000..41b8f5a --- /dev/null +++ b/run/lookup-ip-address.sh @@ -0,0 +1,3 @@ +#!/bin/bash -eu + +echo "$(ping -c 1 -w 1 $1 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')" \ No newline at end of file From 777db26f27785725dc0bdf32a078e5fedb584826 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Tue, 30 Oct 2018 22:53:51 -0700 Subject: [PATCH 12/38] testing to see if verify-archive works as expected --- run/cifs_archive/verify-archive-configuration.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/run/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh index 684a42b..4db1830 100644 --- a/run/cifs_archive/verify-archive-configuration.sh +++ b/run/cifs_archive/verify-archive-configuration.sh @@ -24,9 +24,14 @@ function check_archive_mountable () { mkdir "$test_mount_location" fi - local tmp_credentials_file_path="/root/.teslaCamArchiveCredentials" + local cifs_version="${cifs_version:-3.0}" + + local tmp_credentials_file_path="/tmp/.teslaCamArchiveCredentials" + echo "username=$shareuser" > "$credentials_file_path" + echo "password=$sharepassword" >> "$credentials_file_path" local mount_failed=false + echo "//$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 -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 ] @@ -40,8 +45,8 @@ function check_archive_mountable () { umount "$test_mount_location" } +echo "install dir: $INSTALL_DIR" +ARCHIVE_SERVER_IP_ADDRESS="$( $INSTALL_DIR/lookup-ip-address.sh "$archiveserver" )" + check_archive_server_reachable - -ARCHIVE_SERVER_IP_ADDRESS="$( /root/bin/get-archiveserver-ip-address.sh )" - check_archive_mountable "$ARCHIVE_SERVER_IP_ADDRESS" From 9c0c8ad09c0dc384ced8d5400bfa2cbb1f3d8e89 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Tue, 30 Oct 2018 22:59:51 -0700 Subject: [PATCH 13/38] bug fix --- run/cifs_archive/verify-archive-configuration.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/run/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh index 4db1830..6968f02 100644 --- a/run/cifs_archive/verify-archive-configuration.sh +++ b/run/cifs_archive/verify-archive-configuration.sh @@ -27,8 +27,8 @@ function check_archive_mountable () { local cifs_version="${cifs_version:-3.0}" local tmp_credentials_file_path="/tmp/.teslaCamArchiveCredentials" - echo "username=$shareuser" > "$credentials_file_path" - echo "password=$sharepassword" >> "$credentials_file_path" + echo "username=$shareuser" > "$tmp_credentials_file_path" + echo "password=$sharepassword" >> "$tmp_credentials_file_path" local mount_failed=false echo "//$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" @@ -45,7 +45,6 @@ function check_archive_mountable () { umount "$test_mount_location" } -echo "install dir: $INSTALL_DIR" ARCHIVE_SERVER_IP_ADDRESS="$( $INSTALL_DIR/lookup-ip-address.sh "$archiveserver" )" check_archive_server_reachable From 9dd3b135c5e709197671a5db09c2b76c09217483 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Tue, 30 Oct 2018 23:11:41 -0700 Subject: [PATCH 14/38] - removing echo - using new ip lookup function --- run/cifs_archive/configure-archive.sh | 2 +- run/cifs_archive/verify-archive-configuration.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/run/cifs_archive/configure-archive.sh b/run/cifs_archive/configure-archive.sh index a3e4ebd..f4204a9 100644 --- a/run/cifs_archive/configure-archive.sh +++ b/run/cifs_archive/configure-archive.sh @@ -23,6 +23,6 @@ function configure_archive () { echo "Configured the archive." } -ARCHIVE_SERVER_IP_ADDRESS="$( /root/bin/get-archiveserver-ip-address.sh )" +ARCHIVE_SERVER_IP_ADDRESS="$( $INSTALL_DIR/lookup-ip-address.sh "$archiveserver" )" configure_archive "$ARCHIVE_SERVER_IP_ADDRESS" \ No newline at end of file diff --git a/run/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh index 6968f02..6b6a7a1 100644 --- a/run/cifs_archive/verify-archive-configuration.sh +++ b/run/cifs_archive/verify-archive-configuration.sh @@ -31,7 +31,6 @@ function check_archive_mountable () { echo "password=$sharepassword" >> "$tmp_credentials_file_path" local mount_failed=false - echo "//$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 -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 ] From d908f7caed75b23ad8ebe7a885dff53a191f23f8 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 00:00:05 -0700 Subject: [PATCH 15/38] addig rclone verification step --- run/rclone_archive/verify-archive-configuration.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/run/rclone_archive/verify-archive-configuration.sh b/run/rclone_archive/verify-archive-configuration.sh index 95dbbf8..7b89e75 100644 --- a/run/rclone_archive/verify-archive-configuration.sh +++ b/run/rclone_archive/verify-archive-configuration.sh @@ -1 +1,12 @@ -#!/bin/bash -eu \ No newline at end of file +#!/bin/bash -eu + +function verify_configuration () { + echo "Verifying rlcone configuration..." + if ! rclone lsd "$RCLONE_DRIVE": | grep -q "$RCLONE_PATH" + then + echo "STOP: Could not find the $RCLONE_DRIVE:$RCLONE_PATH" + exit 1 + fi +} + +verify_configuration \ No newline at end of file From 5e2b0812464c6d986ad60626e330ac87745e1306 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 00:25:45 -0700 Subject: [PATCH 16/38] only move fake-hwclock.data if it's not already a symlink take out rclone specific logic out of here and move into rclone_archive --- setup/pi/make-root-fs-readonly.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/setup/pi/make-root-fs-readonly.sh b/setup/pi/make-root-fs-readonly.sh index aeafeb0..ea88422 100644 --- a/setup/pi/make-root-fs-readonly.sh +++ b/setup/pi/make-root-fs-readonly.sh @@ -33,25 +33,19 @@ if [ ! -e "/mutable/etc" ] then mkdir -p /mutable/etc fi -if [ -e "/etc/fake-hwclock.data" ] + +if [ ! -L "/etc/fake-hwclock.data" ] && [ -e "/etc/fake-hwclock.data" ] then echo "Moving fake-hwclock data" - cp /etc/fake-hwclock.data /mutable/etc/fake-hwclock.data - rm /etc/fake-hwclock.data + mv /etc/fake-hwclock.data /mutable/etc/fake-hwclock.data ln -s /mutable/etc/fake-hwclock.data /etc/fake-hwclock.data fi -# Move rclone configs if it exists so we can write to it +# Create a configs directory for others to use if [ ! -e "/mutable/configs" ] then mkdir -p /mutable/configs fi -if [ -e "/root/.config/rclone/rclone.conf" ] -then - echo "Moving rclone configs" - mv /root/.config/rclone /mutable/configs - ln -s /mutable/configs/rclone /root/.config/rclone -fi # Move /var/spool to /tmp rm -rf /var/spool From 34690ca9d408d66cb7adb48245204bc09c9954c1 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 00:36:27 -0700 Subject: [PATCH 17/38] add logic to move config file into /mutable as part of configuring the archive --- run/rclone_archive/configure-archive.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/run/rclone_archive/configure-archive.sh b/run/rclone_archive/configure-archive.sh index 13e291b..f204c94 100644 --- a/run/rclone_archive/configure-archive.sh +++ b/run/rclone_archive/configure-archive.sh @@ -1,10 +1,17 @@ #!/bin/bash -eu function configure_archive () { - echo "Configuring the archive for Rclone..." + echo "Configuring rclone archive..." echo "drive=$RCLONE_DRIVE" > /root/.teslaCamRcloneConfig echo "path=$RCLONE_PATH" >> /root/.teslaCamRcloneConfig + + if [ ! -L "/root/.config/rclone" ] && [ -e "/root/.config/rclone" ] + then + echo "Moving rclone configs in /mutable" + mv /root/.config/rclone /mutable/configs + ln -s /mutable/configs/rclone /root/.config/rclone + fi } configure_archive \ No newline at end of file From fd4d161f1a28227dd96f80175248bef1104da138 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 00:37:11 -0700 Subject: [PATCH 18/38] also check for configuration file as part of verification step --- run/rclone_archive/verify-archive-configuration.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/run/rclone_archive/verify-archive-configuration.sh b/run/rclone_archive/verify-archive-configuration.sh index 7b89e75..38c5303 100644 --- a/run/rclone_archive/verify-archive-configuration.sh +++ b/run/rclone_archive/verify-archive-configuration.sh @@ -2,6 +2,12 @@ function verify_configuration () { echo "Verifying rlcone configuration..." + if ! [ -e "/root/.config/rclone/rclone.conf" ] + then + echo "STOP: rclone config was not found. did you configure rclone correctly?" + exit 1 + fi + if ! rclone lsd "$RCLONE_DRIVE": | grep -q "$RCLONE_PATH" then echo "STOP: Could not find the $RCLONE_DRIVE:$RCLONE_PATH" From 203ad8b1b5eadad4a2587c443a63e5ac4c696c4a Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 01:11:24 -0700 Subject: [PATCH 19/38] cleaning up config functions. --- run/rclone_archive/configure-archive.sh | 2 ++ run/rsync_archive/configure-archive.sh | 9 ++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/run/rclone_archive/configure-archive.sh b/run/rclone_archive/configure-archive.sh index f204c94..fd9eb84 100644 --- a/run/rclone_archive/configure-archive.sh +++ b/run/rclone_archive/configure-archive.sh @@ -12,6 +12,8 @@ function configure_archive () { mv /root/.config/rclone /mutable/configs ln -s /mutable/configs/rclone /root/.config/rclone fi + + echo "done" } configure_archive \ No newline at end of file diff --git a/run/rsync_archive/configure-archive.sh b/run/rsync_archive/configure-archive.sh index 4fcb84c..9d94ff5 100644 --- a/run/rsync_archive/configure-archive.sh +++ b/run/rsync_archive/configure-archive.sh @@ -1,16 +1,11 @@ #!/bin/bash -eu function configure_archive () { - local archive_server_ip_address="$1" + echo "Configuring the rsync archive..." - 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" \ No newline at end of file +configure_archive \ No newline at end of file From aae15da2e51f031c8cc285bf5d7d01d3a5924c5c Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 01:40:20 -0700 Subject: [PATCH 20/38] case fix because i'm ocd --- run/rclone_archive/configure-archive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/rclone_archive/configure-archive.sh b/run/rclone_archive/configure-archive.sh index fd9eb84..6523b2c 100644 --- a/run/rclone_archive/configure-archive.sh +++ b/run/rclone_archive/configure-archive.sh @@ -13,7 +13,7 @@ function configure_archive () { ln -s /mutable/configs/rclone /root/.config/rclone fi - echo "done" + echo "Done" } configure_archive \ No newline at end of file From b93550e4dea1a01061b0faff63c6e54e0568fb9e Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 01:42:25 -0700 Subject: [PATCH 21/38] splitting up usb configuration from script and archive configuration / installation. this will allow a user to run configuration multiple times. --- setup/pi/configure.sh | 216 ++++++++++++++++++++++++++++++++++++++++ setup/pi/setup-teslausb | 135 +------------------------ 2 files changed, 217 insertions(+), 134 deletions(-) create mode 100644 setup/pi/configure.sh diff --git a/setup/pi/configure.sh b/setup/pi/configure.sh new file mode 100644 index 0000000..e9336aa --- /dev/null +++ b/setup/pi/configure.sh @@ -0,0 +1,216 @@ +#!/bin/bash -eu + +REPO=${REPO:-cimryan} +BRANCH=${BRANCH:-master} +INSTALL_DIR=${INSTALL_DIR:-/root/bin} + +upgrade=false #TODO: create an option to just refresh the scripts +debug_on=false + +function debug() { + $debug_on && echo "$1" + return 0 +} + +function check_variable () { + local var_name="$1" + if [ -z "${!var_name+x}" ] + then + echo "STOP: Define the variable $var_name like this: export $var_name=value" + exit 1 + fi +} + +function get_script () { + local local_path="$1" + local name="$2" + local remote_path="${3:-}" + + echo "Starting download for $local_path/$name" + curl -o "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" + chmod +x "$local_path/$name" + echo "Done" +} + +function parse_command_line() { + echo -n "Parsing command line: " + + local OPTIND=1 # Reset in case getopts has been used previously in the shell. + while getopts "du" opt; do + case "$opt" in + d) debug_on=true + ;; + u) upgrade=true + #TODO: just upgrade all the scripts instead building new configs + echo "STOP: this option is not yet implemented" + exit 1 + ;; + esac + done + shift $((OPTIND-1)) + [ "${1:-}" = "--" ] && shift + + echo "done" +} + +function install_rc_local () { + local install_home="$1" + + if grep -q archiveloop /etc/rc.local + then + echo "Skipping rc.local installation" + return + fi + + echo "Configuring /etc/rc.local to run the archive scripts at startup..." + echo "#!/bin/bash -eu" > ~/rc.local + echo "archiveserver=\"${archiveserver}\"" >> ~/rc.local + echo "install_home=\"${install_home}\"" >> ~/rc.local + cat << 'EOF' >> ~/rc.local +LOGFILE=/tmp/rc.local.log + +function log () { + echo "$( date )" >> "$LOGFILE" + echo "$1" >> "$LOGFILE" +} + +log "Launching archival script..." +"$install_home"/archiveloop "$archiveserver" & +log "All done" +exit 0 +EOF + + cat ~/rc.local > /etc/rc.local + rm ~/rc.local + echo "Installed rc.local." +} + +function check_archive_configs () { + echo -n "Checking archive configs: " + + RSYNC_ENABLE="${RSYNC_ENABLE:-false}" + RCLONE_ENABLE="${RCLONE_ENABLE:-false}" + if [ "$RSYNC_ENABLE" = true ] && [ "$RCLONE_ENABLE" = true ] + then + echo "STOP: Can't enable rsync and rclone at the same time" + exit 1 + fi + + if [ "$RSYNC_ENABLE" = true ] + then + check_variable "RSYNC_USER" + check_variable "RSYNC_SERVER" + check_variable "RSYNC_PATH" + export archiveserver="$RSYNC_SERVER" + + elif [ "$RCLONE_ENABLE" = true ] + then + check_variable "RCLONE_DRIVE" + check_variable "RCLONE_PATH" + export archiveserver="8.8.8.8" # since it's a cloud hosted drive we'll just set this to google dns + else + # default to cifs + check_variable "sharename" + check_variable "shareuser" + check_variable "sharepassword" + check_variable "archiveserver" + fi + + echo "done" +} + +function get_archive_module () { + + if [ "$RSYNC_ENABLE" = true ] + then + archive_module="run/rsync_archive" + elif [ "$RCLONE_ENABLE" = true ] + then + archive_module="run/rclone_archive" + else + archive_module="run/cifs_archive" + fi + + echo $archive_module +} + +function install_archive_scripts () { + local install_path="$1" + local archive_module="$2" + + echo "Installing base archive scripts into $install_path" + get_script $install_path archiveloop run + get_script $install_path remountfs_rw run + get_script $install_path lookup-ip-address.sh run + + echo "Installing archive module scripts ($archive_module)" + + get_script $install_path verify-archive-configuration.sh $archive_module + get_script $install_path configure-archive.sh $archive_module + get_script $install_path archive-clips.sh $archive_module + get_script $install_path connect-archive.sh $archive_module + get_script $install_path disconnect-archive.sh $archive_module +} + +function check_and_configure_pushover () { + if [ ! -z "${pushover_enabled+x}" ] + then + if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] + then + echo "STOP: You're trying to setup Pushover but didn't provide your User and/or App key." + echo "Define the variables like this:" + echo "export pushover_user_key=put_your_userkey_here" + echo "export pushover_app_key=put_your_appkey_here" + exit 1 + elif [ "${pushover_user_key}" = "put_your_userkey_here" ] || [ "${pushover_app_key}" = "put_your_appkey_here" ] + then + echo "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." + exit 1 + else + echo "Enabling pushover" + echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials + echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials + echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials + fi + else + echo "Pushover not configured." + fi +} + +function install_pushover_scripts() { + local install_path="$1" + get_script $install_path send-pushover run +} + +if ! [ $(id -u) = 0 ] +then + echo "STOP: Run sudo -i." + exit 1 +fi + +if [ ! -e "$INSTALL_DIR" ] +then + mkdir "$INSTALL_DIR" +fi + +parse_command_line "$@" +debug "Getting files from $REPO:$BRANCH" +debug "- debug mode = $debug_on" +debug "- upgrade only = $upgrade" + +check_and_configure_pushover +install_pushover_scripts "$INSTALL_DIR" + +check_archive_configs + +archive_module="$( get_archive_module )" +debug "Archive module: $archive_module" + +install_archive_scripts $INSTALL_DIR $archive_module +"$INSTALL_DIR"/verify-archive-configuration.sh +"$INSTALL_DIR"/configure-archive.sh + +install_rc_local "$INSTALL_DIR" + + + diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 0b52fe1..00bad1d 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -1,6 +1,5 @@ #!/bin/bash -eu -USER_ENABLED_PUSHOVER=${USER_ENABLED_PUSHOVER:-false} SETUP_LOGFILE=/boot/teslausb-headless-setup.log REPO=${REPO:-cimryan} BRANCH=${BRANCH:-master} @@ -8,7 +7,6 @@ HEADLESS_SETUP=${HEADLESS_SETUP:-false} USE_LED_FOR_SETUP_PROGRESS=true - if ! [ $(id -u) = 0 ] then setup_progress "STOP: Run sudo -i." @@ -90,66 +88,6 @@ function check_variable () { fi } -function check_pushover_enabled () { - if [ ! -z "${pushover_enabled+x}" ] - then - if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] - then - setup_progress "STOP: You're trying to setup Pushover but didn't provide your User and/or App key." - setup_progress "Define the variables like this:" - setup_progress "export pushover_user_key=put_your_userkey_here" - setup_progress "export pushover_app_key=put_your_appkey_here" - exit 1 - elif [ "${pushover_user_key}" = "put_your_userkey_here" ] || [ "${pushover_app_key}" = "put_your_appkey_here" ] - then - setup_progress "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." - exit 1 - else - USER_ENABLED_PUSHOVER=true - echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials - echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials - echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials - fi - fi -} - -function check_archive_configs () { - - RSYNC_ENABLE="${RSYNC_ENABLE:-false}" - RCLONE_ENABLE="${RCLONE_ENABLE:-false}" - - if [ "$RSYNC_ENABLE" = true ] && [ "$RCLONE_ENABLE" = true ] - then - setup_progress "STOP: Cannot enable rsync and rclone at the same time" - exit 1 - fi - - if [ "$RSYNC_ENABLE" = true ] - then - check_variable "RSYNC_USER" - check_variable "RSYNC_SERVER" - export archiveserver="$RSYNC_SERVER" - check_variable "RSYNC_PATH" - export archive_module="run/rsync_archive" - elif [ "$RCLONE_ENABLE" = true ] - then - check_variable "RCLONE_DRIVE" - check_variable "RCLONE_PATH" - # since it's a cloud hosted drive we'll just set this to google dns - export archiveserver="8.8.8.8" - export archive_module="run/rclone_archive" - else # Else for now, TODO allow both for more redundancy? - check_variable "sharename" - check_variable "shareuser" - check_variable "sharepassword" - - export cifs_version="${cifs_version:-3.0}" - export archive_module="run/cifs_archive" - fi - - check_variable "archiveserver" -} - function check_available_space () { setup_progress "Verifying that there is sufficient space available on the MicroSD card..." @@ -179,6 +117,7 @@ function get_ancillary_setup_scripts () { get_script /tmp create-backingfiles-partition.sh setup/pi get_script /tmp create-backingfiles.sh setup/pi get_script /tmp make-root-fs-readonly.sh setup/pi + get_script /root configure.sh setup/pi } function fix_cmdline_txt_modules_load () @@ -223,59 +162,6 @@ function create_usb_drive_backing_files () { fi } -function configure_archive_scripts () { - setup_progress "Configuring the archive scripts..." - - get_script /root/bin archiveloop run - get_script /root/bin remountfs_rw run - - setup_progress "Configured the archive scripts." -} - -function install_archive_scripts () { - check_variable "archive_module" - setup_progress "Installing scripts for archive module: $archive_module" - - local install_path="/root/bin" - get_script $install_path verify-archive-configuration.sh $archive_module - get_script $install_path configure-archive.sh $archive_module - get_script $install_path archive-clips.sh $archive_module - get_script $install_path connect-archive.sh $archive_module - get_script $install_path disconnect-archive.sh $archive_module -} - -function configure_pushover_scripts() { - get_script /root/bin send-pushover run -} - -function configure_rc_local () { - if grep -q archiveloop /etc/rc.local - then - return - fi - - setup_progress "Configuring /etc/rc.local to run the archive scripts at startup..." - echo "#!/bin/bash -eu" > ~/rc.local - echo "archiveserver=\"${archiveserver}\"" >> ~/rc.local -cat << 'EOF' >> ~/rc.local -LOGFILE=/tmp/rc.local.log - -function log () { - echo "$( date )" >> "$LOGFILE" - echo "$1" >> "$LOGFILE" -} - -log "Launching archival script..." -/root/bin/archiveloop "$archiveserver" & -log "All done" -exit 0 -EOF - - cat ~/rc.local > /etc/rc.local - rm ~/rc.local - setup_progress "Configured rc.local." -} - function configure_hostname () { # Headless image already has hostname set if [ ! $HEADLESS_SETUP = "true" ] @@ -307,35 +193,18 @@ headless_setup_progress_flash 1 setup_progress "Verifying environment variables..." check_variable "campercent" -check_archive_configs -check_pushover_enabled # Flash for Stage 3 headless (grab scripts) headless_setup_progress_flash 2 setup_progress "Downloading additional setup scripts." -if [ ! -e /root/bin ] -then - mkdir /root/bin -fi - -get_script /root/bin get-archiveserver-ip-address.sh run - -install_archive_scripts -/root/bin/configure-archive.sh -/root/bin/verify-archive-configuration.sh - check_available_space get_ancillary_setup_scripts pushd ~ -configure_archive_scripts - -configure_pushover_scripts - fix_cmdline_txt_modules_load echo "" >> /etc/fstab @@ -345,8 +214,6 @@ headless_setup_progress_flash 3 create_usb_drive_backing_files -configure_rc_local - configure_hostname # Flash for stage 5 headless (Mark success, FS readonly) From 6dc1b79813784a8c062c2d14e9b024f6469c2dc1 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 02:07:18 -0700 Subject: [PATCH 22/38] bug fix - removing resolv.conf causes dns errors until you reboot. this is safer. --- setup/pi/make-root-fs-readonly.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup/pi/make-root-fs-readonly.sh b/setup/pi/make-root-fs-readonly.sh index ea88422..4ac638b 100644 --- a/setup/pi/make-root-fs-readonly.sh +++ b/setup/pi/make-root-fs-readonly.sh @@ -55,8 +55,7 @@ ln -s /tmp /var/spool sed -i "s/spool\s*0755/spool 1777/g" /usr/lib/tmpfiles.d/var.conf >/dev/null # Move dhcpd.resolv.conf to tmpfs -touch /tmp/dhcpcd.resolv.conf -rm /etc/resolv.conf +mv /etc/resolv.conf /tmp/dhcpcd.resolv.conf ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf # Update /etc/fstab From 1e063e4aed1a5fc644effae69e034b60a1900604 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 02:28:38 -0700 Subject: [PATCH 23/38] adding new step to configure --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index eabba21..4ed3acd 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Follow the instructions corresponding to the technology you'd like to use to hos wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/pi/setup-teslausb chmod +x setup-teslausb ./setup-teslausb + /root/configure.sh ``` 1. Run this command: ``` From 9687859297ae1757483f680cdff2c08e244228ac Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 03:26:39 -0700 Subject: [PATCH 24/38] typo --- run/rclone_archive/configure-archive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/rclone_archive/configure-archive.sh b/run/rclone_archive/configure-archive.sh index 6523b2c..5740157 100644 --- a/run/rclone_archive/configure-archive.sh +++ b/run/rclone_archive/configure-archive.sh @@ -8,7 +8,7 @@ function configure_archive () { if [ ! -L "/root/.config/rclone" ] && [ -e "/root/.config/rclone" ] then - echo "Moving rclone configs in /mutable" + echo "Moving rclone configs into /mutable" mv /root/.config/rclone /mutable/configs ln -s /mutable/configs/rclone /root/.config/rclone fi From 0d682af4bfa54052f62800d38da7884989974b25 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Wed, 31 Oct 2018 03:27:26 -0700 Subject: [PATCH 25/38] let's clean up after ourselves --- setup/pi/setup-teslausb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 23de664..460e8f2 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -172,10 +172,12 @@ function configure_hostname () { local new_host_name="teslausb" cp /etc/hosts ~ sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts + rm ~/hosts cp /etc/hostname ~ sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname setup_progress "Configured the hostname." + rm ~/hostname fi } From f2277bdf3ff34f164d552187718e1c2921d465d9 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 31 Oct 2018 16:43:58 -0700 Subject: [PATCH 26/38] Changing the declaration of "optional" on the README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eabba21..dec63a5 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,8 @@ On the next boot, the Pi hostname will become `teslausb`, so future `ssh` sessio Your Pi is now ready to be plugged into your Tesla. If you want to add music to the Pi, follow the instructions in the next section. -## (Optional) Add music to the Pi -> Note: If you set `campercent` to 100% this drive will not show up +## Optional: Add music to the Pi +> Note: If you set `campercent` to `100` then skip this step. Connect the Pi to a computer. If you're using a cable be sure to use the port labeled "USB" on the circuitboard. 1. Wait for the Pi to show up on the computer as a USB drive. @@ -104,7 +104,7 @@ Connect the Pi to a computer. If you're using a cable be sure to use the port la 1. Unplug the Pi from the computer. 1. Plug the Pi into your Tesla. -## Making changes to the system after setup +## Optional: Making changes to the system after setup The setup process configures the Pi with read-only file systems for the operating system but with read-write access through the USB interface. This means that you'll be able to record dashcam video and add and remove music files but you won't be able to make changes to files on / or on /boot. This is to protect against From d7587578395b6f43069ee1232d04de5215878f1b Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Fri, 2 Nov 2018 12:25:10 -0700 Subject: [PATCH 27/38] remove command line support and corresponding debugs --- setup/pi/configure.sh | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/setup/pi/configure.sh b/setup/pi/configure.sh index e9336aa..5da1c18 100644 --- a/setup/pi/configure.sh +++ b/setup/pi/configure.sh @@ -4,13 +4,6 @@ REPO=${REPO:-cimryan} BRANCH=${BRANCH:-master} INSTALL_DIR=${INSTALL_DIR:-/root/bin} -upgrade=false #TODO: create an option to just refresh the scripts -debug_on=false - -function debug() { - $debug_on && echo "$1" - return 0 -} function check_variable () { local var_name="$1" @@ -32,27 +25,6 @@ function get_script () { echo "Done" } -function parse_command_line() { - echo -n "Parsing command line: " - - local OPTIND=1 # Reset in case getopts has been used previously in the shell. - while getopts "du" opt; do - case "$opt" in - d) debug_on=true - ;; - u) upgrade=true - #TODO: just upgrade all the scripts instead building new configs - echo "STOP: this option is not yet implemented" - exit 1 - ;; - esac - done - shift $((OPTIND-1)) - [ "${1:-}" = "--" ] && shift - - echo "done" -} - function install_rc_local () { local install_home="$1" @@ -193,10 +165,7 @@ then mkdir "$INSTALL_DIR" fi -parse_command_line "$@" -debug "Getting files from $REPO:$BRANCH" -debug "- debug mode = $debug_on" -debug "- upgrade only = $upgrade" +echo "Getting files from $REPO:$BRANCH" check_and_configure_pushover install_pushover_scripts "$INSTALL_DIR" @@ -204,7 +173,7 @@ install_pushover_scripts "$INSTALL_DIR" check_archive_configs archive_module="$( get_archive_module )" -debug "Archive module: $archive_module" +echo "Using archive module: $archive_module" install_archive_scripts $INSTALL_DIR $archive_module "$INSTALL_DIR"/verify-archive-configuration.sh From aefdb082d07ede95e067006c2e2729042d2eb6bf Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Fri, 2 Nov 2018 15:24:25 -0700 Subject: [PATCH 28/38] refactoring to add back write configs script --- run/cifs_archive/configure-archive.sh | 3 +-- run/cifs_archive/verify-archive-configuration.sh | 5 ++--- run/cifs_archive/write-archive-configs-to.sh | 6 ++++++ run/rclone_archive/configure-archive.sh | 4 ++-- run/rclone_archive/write-archive-configs-to.sh | 6 ++++++ run/rsync_archive/configure-archive.sh | 5 ++--- run/rsync_archive/write-archive-configs-to.sh | 7 +++++++ setup/pi/configure.sh | 4 ++-- 8 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 run/cifs_archive/write-archive-configs-to.sh create mode 100644 run/rclone_archive/write-archive-configs-to.sh create mode 100644 run/rsync_archive/write-archive-configs-to.sh diff --git a/run/cifs_archive/configure-archive.sh b/run/cifs_archive/configure-archive.sh index f4204a9..a9b7fb5 100644 --- a/run/cifs_archive/configure-archive.sh +++ b/run/cifs_archive/configure-archive.sh @@ -15,8 +15,7 @@ function configure_archive () { local cifs_version="${cifs_version:-3.0}" local credentials_file_path="/root/.teslaCamArchiveCredentials" - echo "username=$shareuser" > "$credentials_file_path" - echo "password=$sharepassword" >> "$credentials_file_path" + /root/bin/write-archive-configs-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 diff --git a/run/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh index 6b6a7a1..bf8b9f2 100644 --- a/run/cifs_archive/verify-archive-configuration.sh +++ b/run/cifs_archive/verify-archive-configuration.sh @@ -26,9 +26,8 @@ function check_archive_mountable () { local cifs_version="${cifs_version:-3.0}" - local tmp_credentials_file_path="/tmp/.teslaCamArchiveCredentials" - echo "username=$shareuser" > "$tmp_credentials_file_path" - echo "password=$sharepassword" >> "$tmp_credentials_file_path" + local tmp_credentials_file_path="/tmp/teslaCamArchiveCredentials" + /root/bin/write-archive-configs-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 diff --git a/run/cifs_archive/write-archive-configs-to.sh b/run/cifs_archive/write-archive-configs-to.sh new file mode 100644 index 0000000..082af81 --- /dev/null +++ b/run/cifs_archive/write-archive-configs-to.sh @@ -0,0 +1,6 @@ +#!/bin/bash -eu + +FILE_PATH="$1" + +echo "username=$shareuser" > "$FILE_PATH" +echo "password=$sharepassword" >> "$FILE_PATH" \ No newline at end of file diff --git a/run/rclone_archive/configure-archive.sh b/run/rclone_archive/configure-archive.sh index 5740157..c4e307f 100644 --- a/run/rclone_archive/configure-archive.sh +++ b/run/rclone_archive/configure-archive.sh @@ -3,8 +3,8 @@ function configure_archive () { echo "Configuring rclone archive..." - echo "drive=$RCLONE_DRIVE" > /root/.teslaCamRcloneConfig - echo "path=$RCLONE_PATH" >> /root/.teslaCamRcloneConfig + local config_file_path="/root/.teslaCamRcloneConfig" + /root/bin/write-archive-configs-to.sh "$config_file_path" if [ ! -L "/root/.config/rclone" ] && [ -e "/root/.config/rclone" ] then diff --git a/run/rclone_archive/write-archive-configs-to.sh b/run/rclone_archive/write-archive-configs-to.sh new file mode 100644 index 0000000..b8ccef6 --- /dev/null +++ b/run/rclone_archive/write-archive-configs-to.sh @@ -0,0 +1,6 @@ +#!/bin/bash -eu + +FILE_PATH="$1" + +echo "drive=$RCLONE_DRIVE" > "$FILE_PATH" +echo "path=$RCLONE_PATH" >> "$FILE_PATH" \ No newline at end of file diff --git a/run/rsync_archive/configure-archive.sh b/run/rsync_archive/configure-archive.sh index 9d94ff5..bb77faa 100644 --- a/run/rsync_archive/configure-archive.sh +++ b/run/rsync_archive/configure-archive.sh @@ -3,9 +3,8 @@ function configure_archive () { echo "Configuring the rsync archive..." - echo "user=$RSYNC_USER" > /root/.teslaCamRsyncConfig - echo "server=$RSYNC_SERVER" >> /root/.teslaCamRsyncConfig - echo "path=$RSYNC_PATH" >> /root/.teslaCamRsyncConfig + local config_file_path="/root/.teslaCamRsyncConfig" + /root/bin/write-archive-configs-to.sh "$config_file_path" } configure_archive \ No newline at end of file diff --git a/run/rsync_archive/write-archive-configs-to.sh b/run/rsync_archive/write-archive-configs-to.sh new file mode 100644 index 0000000..43237f6 --- /dev/null +++ b/run/rsync_archive/write-archive-configs-to.sh @@ -0,0 +1,7 @@ + #!/bin/bash -eu + +FILE_PATH="$1" + +echo "user=$RSYNC_USER" > "$FILE_PATH" +echo "server=$RSYNC_SERVER" >> "$FILE_PATH" +echo "path=$RSYNC_PATH" >> "$FILE_PATH" \ No newline at end of file diff --git a/setup/pi/configure.sh b/setup/pi/configure.sh index 5da1c18..4f30e21 100644 --- a/setup/pi/configure.sh +++ b/setup/pi/configure.sh @@ -115,13 +115,13 @@ function install_archive_scripts () { get_script $install_path remountfs_rw run get_script $install_path lookup-ip-address.sh run - echo "Installing archive module scripts ($archive_module)" - + echo "Installing archive module scripts" get_script $install_path verify-archive-configuration.sh $archive_module get_script $install_path configure-archive.sh $archive_module get_script $install_path archive-clips.sh $archive_module get_script $install_path connect-archive.sh $archive_module get_script $install_path disconnect-archive.sh $archive_module + get_script $install_path write-archive-configs-to.sh $archive_module } function check_and_configure_pushover () { From fd7be5871b83d600090b1ad82aa4b01dc32136b0 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Fri, 2 Nov 2018 15:39:13 -0700 Subject: [PATCH 29/38] bug fix - INSTALL_DIR was not getting propagated to child script --- setup/pi/configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/pi/configure.sh b/setup/pi/configure.sh index 4f30e21..36ef23f 100644 --- a/setup/pi/configure.sh +++ b/setup/pi/configure.sh @@ -2,8 +2,8 @@ REPO=${REPO:-cimryan} BRANCH=${BRANCH:-master} -INSTALL_DIR=${INSTALL_DIR:-/root/bin} +export INSTALL_DIR=${INSTALL_DIR:-/root/bin} function check_variable () { local var_name="$1" From 83c661be63ff2dcda0a5b8ec97db0852c296c77f Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Fri, 2 Nov 2018 15:42:53 -0700 Subject: [PATCH 30/38] remove errant tab --- run/rsync_archive/write-archive-configs-to.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/rsync_archive/write-archive-configs-to.sh b/run/rsync_archive/write-archive-configs-to.sh index 43237f6..ae9a1f3 100644 --- a/run/rsync_archive/write-archive-configs-to.sh +++ b/run/rsync_archive/write-archive-configs-to.sh @@ -1,4 +1,4 @@ - #!/bin/bash -eu +#!/bin/bash -eu FILE_PATH="$1" From efdab385303153f11b1a4ce2c53e80ecad93ffae Mon Sep 17 00:00:00 2001 From: cimryan Date: Fri, 2 Nov 2018 19:47:29 -0700 Subject: [PATCH 31/38] Move the verification of the available space just after the verification of the variables. --- setup/pi/setup-teslausb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 460e8f2..9faa514 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -197,13 +197,13 @@ setup_progress "Verifying environment variables..." check_variable "campercent" +check_available_space + # Flash for Stage 3 headless (grab scripts) headless_setup_progress_flash 2 setup_progress "Downloading additional setup scripts." -check_available_space - get_ancillary_setup_scripts pushd ~ From b9efb5006fe708745ba7bdf512b79fd9b95a583d Mon Sep 17 00:00:00 2001 From: cimryan Date: Fri, 2 Nov 2018 19:52:26 -0700 Subject: [PATCH 32/38] Express stage 2 progress in terms of the process rather than the implementation. --- doc/OneStepSetup.md | 2 +- setup/pi/setup-teslausb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/OneStepSetup.md b/doc/OneStepSetup.md index 5cfe7ed..c97ccc6 100644 --- a/doc/OneStepSetup.md +++ b/doc/OneStepSetup.md @@ -42,7 +42,7 @@ A sample conf file is located in the `boot` folder on the SD card. | Stage (number of flashes) | Activity | |---|---| -| 2 | Verify setup variables | +| 2 | Verify the requested configuration is creatable | | 3 | Grab scripts to start/continue setup | | 4 | Create partition and files to store camera clips/music) | | 5 | Setup completed; remounting filesystems as read-only and rebooting | diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 9faa514..1318e42 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -190,10 +190,10 @@ headless_setup_populate_variables # If USE_LED_FOR_SETUP_PROGRESS = true. setup_led_off -# Flash for stage 2 headless (verify variables) +# Flash for stage 2 headless (verify requested configuration) headless_setup_progress_flash 1 -setup_progress "Verifying environment variables..." +setup_progress "Verifying that the requested configuration is valid..." check_variable "campercent" From 1099f8ada86ff2891530017c82a7e05e52a718b2 Mon Sep 17 00:00:00 2001 From: cimryan Date: Fri, 2 Nov 2018 21:41:59 -0700 Subject: [PATCH 33/38] hygiene. --- setup/pi/configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/pi/configure.sh b/setup/pi/configure.sh index 36ef23f..a976c88 100644 --- a/setup/pi/configure.sh +++ b/setup/pi/configure.sh @@ -145,7 +145,7 @@ function check_and_configure_pushover () { echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials fi else - echo "Pushover not configured." + echo "Pushover not configured." fi } From bab44a79b744a8e215907fed71df472bf908766f Mon Sep 17 00:00:00 2001 From: cimryan Date: Fri, 2 Nov 2018 22:04:31 -0700 Subject: [PATCH 34/38] Split the implementation of check_and_configure_pushover into separate check and configure steps. --- setup/pi/configure.sh | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/setup/pi/configure.sh b/setup/pi/configure.sh index a976c88..cc6874c 100644 --- a/setup/pi/configure.sh +++ b/setup/pi/configure.sh @@ -124,7 +124,8 @@ function install_archive_scripts () { get_script $install_path write-archive-configs-to.sh $archive_module } -function check_and_configure_pushover () { + +function check_pushover_configuration () { if [ ! -z "${pushover_enabled+x}" ] then if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] @@ -138,17 +139,28 @@ function check_and_configure_pushover () { then echo "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." exit 1 - else - echo "Enabling pushover" - echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials - echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials - echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials fi + fi +} + +function configure_pushover () { + if [ ! -z "${pushover_enabled+x}" ] + then + echo "Enabling pushover" + echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials + echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials + echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials else echo "Pushover not configured." fi } +function check_and_configure_pushover () { + check_pushover_configuration + + configure_pushover +} + function install_pushover_scripts() { local install_path="$1" get_script $install_path send-pushover run From fe7ab50ab181cd83f8b18c514648c1287ee91591 Mon Sep 17 00:00:00 2001 From: cimryan Date: Fri, 2 Nov 2018 22:44:28 -0700 Subject: [PATCH 35/38] Extract verify-configuration.sh from setup-teslausb --- setup/pi/setup-teslausb | 10 +++++++--- setup/pi/verify-configuration.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 setup/pi/verify-configuration.sh diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 1318e42..85aa667 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -102,6 +102,12 @@ function check_available_space () { setup_progress "There is sufficient space available." } +function verify_configuration () { + get_script /tmp verify-configuration.sh setup/pi + + /tmp/verify-configuration.sh +} + function get_script () { local local_path="$1" local name="$2" @@ -195,9 +201,7 @@ headless_setup_progress_flash 1 setup_progress "Verifying that the requested configuration is valid..." -check_variable "campercent" - -check_available_space +verify_configuration # Flash for Stage 3 headless (grab scripts) headless_setup_progress_flash 2 diff --git a/setup/pi/verify-configuration.sh b/setup/pi/verify-configuration.sh new file mode 100644 index 0000000..6ee926c --- /dev/null +++ b/setup/pi/verify-configuration.sh @@ -0,0 +1,28 @@ +#!/bin/bash -eu + +function check_variable () { + local var_name="$1" + if [ -z "${!var_name+x}" ] + then + setup_progress "STOP: Define the variable $var_name like this: export $var_name=value" + exit 1 + fi +} + +function check_available_space () { + setup_progress "Verifying that there is sufficient space available on the MicroSD card..." + + local available_space="$( parted -m /dev/mmcblk0 u b print free | tail -1 | cut -d ":" -f 4 | sed 's/B//g' )" + + if [ "$available_space" -lt 4294967296 ] + then + setup_progress "STOP: The MicroSD card is too small." + exit 1 + fi + + setup_progress "There is sufficient space available." +} + +check_variable "campercent" + +check_available_space From aa8e9adbee0d073dca11766b13e6aa8df5b56f49 Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 3 Nov 2018 10:11:16 -0700 Subject: [PATCH 36/38] Configure archiving by default as part of the setup-teslausb script, but make it possible to skip. --- README.md | 1 - setup/pi/setup-teslausb | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 88f3c70..dec63a5 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,6 @@ Follow the instructions corresponding to the technology you'd like to use to hos wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/pi/setup-teslausb chmod +x setup-teslausb ./setup-teslausb - /root/configure.sh ``` 1. Run this command: ``` diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 85aa667..ba2468d 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -4,7 +4,7 @@ REPO=${REPO:-cimryan} BRANCH=${BRANCH:-master} HEADLESS_SETUP=${HEADLESS_SETUP:-false} USE_LED_FOR_SETUP_PROGRESS=true - +CONFIGURE_ARCHIVING=${CONFIGURE_ARCHIVING:-true} if ! [ $(id -u) = 0 ] then @@ -228,6 +228,11 @@ headless_setup_progress_flash 4 headless_setup_mark_setup_success +if [ "$CONFIGURE_ARCHIVING" = true ] +then + /root/configure.sh +fi + make_root_fs_readonly # If USE_LED_FOR_SETUP_PROGRESS = true. From 9c37d42b4d431da252969a73e91fb0317d12fbf2 Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 3 Nov 2018 10:41:33 -0700 Subject: [PATCH 37/38] Export declarations used in verify-configuration.s --- setup/pi/setup-teslausb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index ba2468d..611fb0b 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -191,6 +191,9 @@ function make_root_fs_readonly () { /tmp/make-root-fs-readonly.sh } +export -f setup_progress +export HEADLESS_SETUP + headless_setup_populate_variables # If USE_LED_FOR_SETUP_PROGRESS = true. From f0b6cae2ea7cc69e1004312f0055d8a87963db5c Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 3 Nov 2018 10:44:29 -0700 Subject: [PATCH 38/38] Pass --fail to curl Ensure that the setup process will stop early if a script can't be retreived. --- setup/pi/setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 611fb0b..c478e5b 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -113,7 +113,7 @@ function get_script () { local name="$2" local remote_path="${3:-}" - curl -o "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" + curl --fail -o "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" # wget -O "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" chmod +x "$local_path/$name" setup_progress "Downloaded $local_path/$name ..."