From 002d1e6f6cc79ffa83c0b04e0958c774c0496a51 Mon Sep 17 00:00:00 2001 From: Gocnak Date: Sat, 20 Oct 2018 03:26:08 -0400 Subject: [PATCH 01/45] Initial rsync support (untested) Currently untested, but the main idea is there Currently it's either the normal archive server or rsync; not both, which is something to consider when adding things like gdrive and s3 (make it more modular?) --- README.md | 14 +++++++--- SetupRSync.md | 36 +++++++++++++++++++++++++ windows_archive/archive-rsync | 12 +++++++++ windows_archive/archive-teslacam-clips | 17 +++++++++--- windows_archive/setup-teslausb | 37 +++++++++++++++++++++----- 5 files changed, 103 insertions(+), 13 deletions(-) create mode 100644 SetupRSync.md create mode 100644 windows_archive/archive-rsync diff --git a/README.md b/README.md index c672958..9394781 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,10 @@ Set up a share on a Windows (or macOS using Sharing, or Linux using Samba) machi Get the IP address of the archive machine. You'll need this later, so write it down, somewhere. You can do this by opening a command prompt on the archive machine and typing ipconfig. Get the IP address from the line labeled "IPv4 Address". These instructions will assume that the IP address of the archive server is 192.168.0.41. -### TODO Other hosting solutions +### Hosting via SFTP/rsync +Since sftp/rsync is accessing a computer through SSH, the only requirement for hosting an SFTP/rsync server is to have a box running Linux. An example can be another Raspberry Pi connected to your local network with a USB storage drive plugged in. The official Raspberry Pi site has a good example on [how to mount an external drive](https://www.raspberrypi.org/documentation/configuration/external-storage.md). You will need the username and host/IP of the storage server, as well as the path for the files to go in, and the storage server will need to allow SSH. + +### ***TODO: Other hosting solutions*** ## Set up the Raspberry Pi There are four phases to setting up the Pi: @@ -89,13 +92,18 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s ping 192.168.0.41 ``` 1. If you can't ping the archive server by IP address from the Pi, you should go do whatever you need to on your network to fix that. If you can't reach the archive server by name, from the Pi but you can by IP address, then use its IP address, below, in place of its name. -1. Run these commands, subsituting your values. The last line is the percent of the drive you want to allocate for dashcam storage. The remaining percentage will be allocated for music. +1. Determine how much, as a percentage of the drive you want to allocate to recording dashcam footage by using: + ``` + export campercent= + ``` + For example, using `export campercent=100` would allocate 100% of the space to recording footage from your car. `export campercent=50` would be only allocate half of the space for dashcam footage, and allow the other half to be used by music. +1. If you are trying to archive on an SFTP/rsync server, then follow these [instructions](SetupRSync.md), and skip the next step. +1. Run these commands, subsituting your values for your shared drive: ``` export archiveserver=Nautilus export sharename=SailfishCam export shareuser=sailfish export sharepassword=pa$$w0rd - export campercent=100 ``` 1. If you'd like to receive a text message when your Pi finishes archiving clips follow these [Instructions](ConfigureNotificationsForArchive.md). 1. Run these commands: diff --git a/SetupRSync.md b/SetupRSync.md new file mode 100644 index 0000000..9e4888f --- /dev/null +++ b/SetupRSync.md @@ -0,0 +1,36 @@ +# Introduction +This guide will show you how to utilize [rsync](https://rsync.samba.org/) to archive your saved TeslaCam footage on a remote storage server. In my case, I use this for a networked pi storage server. + +This guide makes the following assumptions: +1. You are running your own ftp/rsync server that you have admin rights to, or can at least add a public key to its `~/.ssh/authorized_keys` file +2. You have **NOT** run the `setup-teslacam` script yet +# Step 1: Authentication +Similar to sftp, rsync by default utilizes ssh to connect to a remote server and transfer files. This guide will use a generated ssh keypair, hence the first assumption above. + +On your teslausb pi, run `ssh-keygen` to generate an ssh key. Add the contents of the newly generated `~/.ssh/id_rsa.pub` file from your teslausb pi to the storage server's `~/.ssh/authorized_keys` file. This will allow a nice and easy connection through rsync, no passwords needed! + +# Step 2: Exports +To be able to configure the teslausb pi use rsync, you'll need to export a few things. On your teslausb pi, run: + +``` +export RSYNC_ENABLE=true +export RSYNC_USER= +export RSYNC_SERVER= +export RSYNC_PATH= +``` + +Explanations for each: +* `RSYNC_ENABLE`: `true` for enabling rsync +* `RSYNC_USER`: The user on the FTP server +* `RSYNC_SERVER`: The IP address/hostname of the destination machine +* `RSYNC_PATH`: The path on the destination machine where the files will be saved + +An example (of my) config is listed below: + +``` +export RSYNC_ENABLE=true +export RSYNC_USER=pi +export RSYNC_SERVER=192.168.1.254 +export RSYNC_PATH=/mnt/PIHDD/TeslaCam/ +``` +***Note: RSYNC_ENABLE=true is going to disable the default archive server. Perhaps future releases will allow both to be defined and function at the same time, for redundancy, but for now just pick one that you'll want the most.*** \ No newline at end of file diff --git a/windows_archive/archive-rsync b/windows_archive/archive-rsync new file mode 100644 index 0000000..8881d21 --- /dev/null +++ b/windows_archive/archive-rsync @@ -0,0 +1,12 @@ +#!/bin/bash -eu + +function log () { + echo "$( date )" >> "$LOG_FILE" + echo "$1" >> "$LOG_FILE" +} + +source /root/.teslaCamRsyncConfig + +rsync -au /mnt/archive $user@$server:$path + +log "Successfully synced files through rsync!" \ No newline at end of file diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index c6be29a..6383c94 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -81,11 +81,22 @@ function move_clips_to_archive () { done log "Moved $move_count file(s)." - if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $move_count > 0 ] + + if [ $move_count > 0] then - log "Sending Pushover message for copied files." - /root/bin/send-pushover $move_count + if [ -r "/root/.teslaCamRsyncConfig" ] + then + log "Archiving through rsync..." + /root/bin/archive-rsync + fi + + if [ -r "/root/.teslaCamPushoverCredentials" ] + then + log "Sending Pushover message for copied files." + /root/bin/send-pushover $move_count + fi fi + log "Finished moving clips to archive." } diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index f72dc25..1410dca 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -109,11 +109,20 @@ function create_usb_drive_backing_files () { function configure_archive () { echo "Configuring the archive..." 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 + 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 + echo "Configuring for a shared drive..." + 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 "password=$sharepassword" >> /root/.teslaCamArchiveCredentials + echo "username=$shareuser" > /root/.teslaCamArchiveCredentials + echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials + fi echo "Configured the archive." } @@ -131,6 +140,12 @@ function configure_archive_scripts () { pushd /root/bin wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips chmod +x archive-teslacam-clips + + if [ $RSYNC_ENABLE = true ] + then + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-rsync + chmod +x archive-rsync + fi popd echo "Configured the archive scripts." @@ -193,10 +208,18 @@ function make_root_fs_readonly () { echo "Verifying environment variables..." +if [ $RSYNC_ENABLE = true ] +then + check_variable "RSYNC_USER" + check_variable "RSYNC_SERVER" + archiveserver = $RSYNC_SERVER + check_variable "RSYNC_PATH" +else # Else for now, TODO allow both for more redundancy? + check_variable "sharename" + check_variable "shareuser" + check_variable "sharepassword" +fi check_variable "archiveserver" -check_variable "sharename" -check_variable "shareuser" -check_variable "sharepassword" check_variable "campercent" check_pushover_enabled From b60b78795339d122a1ea65276c514424b795882c Mon Sep 17 00:00:00 2001 From: Gocnak Date: Sat, 20 Oct 2018 04:27:44 -0400 Subject: [PATCH 02/45] Minor fixes Archive isn't mounted for rsync, it's just a folder --- windows_archive/archive-teslacam-clips | 7 +++++-- windows_archive/setup-teslausb | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index 6383c94..a9c6b4d 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -96,7 +96,7 @@ function move_clips_to_archive () { /root/bin/send-pushover $move_count fi fi - + log "Finished moving clips to archive." } @@ -132,7 +132,10 @@ function unmount_cam_drive () { log "Starting..." -ensure_archive_is_mounted +if [ ! -r "/root/.teslaCamRsyncConfig" ] +then + ensure_archive_is_mounted +fi disconnect_usb_drives_from_host diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 1410dca..428b3cf 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -212,7 +212,7 @@ if [ $RSYNC_ENABLE = true ] then check_variable "RSYNC_USER" check_variable "RSYNC_SERVER" - archiveserver = $RSYNC_SERVER + export archiveserver=$RSYNC_SERVER check_variable "RSYNC_PATH" else # Else for now, TODO allow both for more redundancy? check_variable "sharename" From de3371f00caa060780fcee8d82114b3de0fa8212 Mon Sep 17 00:00:00 2001 From: Gocnak Date: Sat, 20 Oct 2018 05:30:57 -0400 Subject: [PATCH 03/45] rsync will not be using the mnt/archive folder It'll instead bypass and just call itself on its own --- windows_archive/archive-rsync | 14 ++++++++++++-- windows_archive/archive-teslacam-clips | 23 ++++++++++------------- windows_archive/setup-teslausb | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/windows_archive/archive-rsync b/windows_archive/archive-rsync index 8881d21..b076721 100644 --- a/windows_archive/archive-rsync +++ b/windows_archive/archive-rsync @@ -7,6 +7,16 @@ function log () { source /root/.teslaCamRsyncConfig -rsync -au /mnt/archive $user@$server:$path +nfiles=$(rsync -auh --stats /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') -log "Successfully synced files through rsync!" \ No newline at end of file +if [ $nfiles > 0 ] +then + if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $nfiles > 0] + then + log "Sending Pushover message for copied files." + /root/bin/send-pushover $nfiles + fi + log "Successfully synced files through rsync!" +else + log "No files to archive through rsync!" +fi \ No newline at end of file diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index a9c6b4d..23bdf4d 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -82,19 +82,10 @@ function move_clips_to_archive () { done log "Moved $move_count file(s)." - if [ $move_count > 0] + if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $move_count > 0] then - if [ -r "/root/.teslaCamRsyncConfig" ] - then - log "Archiving through rsync..." - /root/bin/archive-rsync - fi - - if [ -r "/root/.teslaCamPushoverCredentials" ] - then - log "Sending Pushover message for copied files." - /root/bin/send-pushover $move_count - fi + log "Sending Pushover message for copied files." + /root/bin/send-pushover $move_count fi log "Finished moving clips to archive." @@ -143,7 +134,13 @@ fix_errors_on_cam_drive ensure_cam_drive_is_mounted -move_clips_to_archive +if [ -r "/root/.teslaCamRsyncConfig" ] +then + log "Archiving through rsync..." + /root/bin/archive-rsync +else + move_clips_to_archive +fi unmount_cam_drive diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 428b3cf..4fa2540 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -108,7 +108,6 @@ function create_usb_drive_backing_files () { function configure_archive () { echo "Configuring the archive..." - mkdir /mnt/archive if [ $RSYNC_ENABLE = true ] then echo "Configuring for Rsync..." @@ -117,6 +116,7 @@ function configure_archive () { echo "path=$RSYNC_PATH" > /root/.teslaCamRsyncConfig else echo "Configuring for a shared drive..." + 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 From 1648a1993fa2d83ac9602a38b48476f75069c3e9 Mon Sep 17 00:00:00 2001 From: Gocnak Date: Sat, 20 Oct 2018 06:45:08 -0400 Subject: [PATCH 04/45] More minor fixes Fixed rsync user and server being overwritten Added log file outputs for archive-rsync --- windows_archive/archive-rsync | 4 +++- windows_archive/setup-teslausb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/windows_archive/archive-rsync b/windows_archive/archive-rsync index b076721..d163640 100644 --- a/windows_archive/archive-rsync +++ b/windows_archive/archive-rsync @@ -1,5 +1,7 @@ #!/bin/bash -eu +LOG_FILE=/tmp/archive-rsync.log + function log () { echo "$( date )" >> "$LOG_FILE" echo "$1" >> "$LOG_FILE" @@ -7,7 +9,7 @@ function log () { source /root/.teslaCamRsyncConfig -nfiles=$(rsync -auh --stats /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') +nfiles=$(rsync -auvh --stats --log-file=/tmp/archive-rsync-cmd.log /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') if [ $nfiles > 0 ] then diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 4fa2540..829f631 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -112,8 +112,8 @@ function configure_archive () { then echo "Configuring for Rsync..." echo "user=$RSYNC_USER" > /root/.teslaCamRsyncConfig - echo "server=$RSYNC_SERVER" > /root/.teslaCamRsyncConfig - echo "path=$RSYNC_PATH" > /root/.teslaCamRsyncConfig + echo "server=$RSYNC_SERVER" >> /root/.teslaCamRsyncConfig + echo "path=$RSYNC_PATH" >> /root/.teslaCamRsyncConfig else echo "Configuring for a shared drive..." mkdir /mnt/archive From f335f236115586ea4ba06cd173721d6614442ffb Mon Sep 17 00:00:00 2001 From: Gocnak Date: Sat, 20 Oct 2018 22:58:30 -0400 Subject: [PATCH 05/45] Updated instructions to prevent bizarre deadend Need to make sure you use the root user to generate the ssh key, and make sure to authorize the connection initially --- README.md | 8 ++++---- SetupRSync.md | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9394781..220645a 100644 --- a/README.md +++ b/README.md @@ -92,13 +92,13 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s ping 192.168.0.41 ``` 1. If you can't ping the archive server by IP address from the Pi, you should go do whatever you need to on your network to fix that. If you can't reach the archive server by name, from the Pi but you can by IP address, then use its IP address, below, in place of its name. -1. Determine how much, as a percentage of the drive you want to allocate to recording dashcam footage by using: +1. Determine how much, as a percentage, of the drive you want to allocate to recording dashcam footage by using: ``` export campercent= ``` - For example, using `export campercent=100` would allocate 100% of the space to recording footage from your car. `export campercent=50` would be only allocate half of the space for dashcam footage, and allow the other half to be used by music. -1. If you are trying to archive on an SFTP/rsync server, then follow these [instructions](SetupRSync.md), and skip the next step. -1. Run these commands, subsituting your values for your shared drive: + For example, using `export campercent=100` would allocate 100% of the space to recording footage from your car, and would not create a separate music partition. `export campercent=50` would be only allocate half of the space for a dashcam footage drive, and allocates the other half to be a music storage drive. +1. If you are trying to archive on an SFTP/rsync server, then follow these [instructions](SetupRSync.md) and skip step 7. Otherwise, skip this step. +1. If you are trying to archive on a shared drive, run these commands, subsituting your values for your shared drive: ``` export archiveserver=Nautilus export sharename=SailfishCam diff --git a/SetupRSync.md b/SetupRSync.md index 9e4888f..7106a7a 100644 --- a/SetupRSync.md +++ b/SetupRSync.md @@ -3,11 +3,16 @@ This guide will show you how to utilize [rsync](https://rsync.samba.org/) to arc This guide makes the following assumptions: 1. You are running your own ftp/rsync server that you have admin rights to, or can at least add a public key to its `~/.ssh/authorized_keys` file +1. The ftp/rsync server has rsync installed (raspbian automatically does) 2. You have **NOT** run the `setup-teslacam` script yet # Step 1: Authentication Similar to sftp, rsync by default utilizes ssh to connect to a remote server and transfer files. This guide will use a generated ssh keypair, hence the first assumption above. -On your teslausb pi, run `ssh-keygen` to generate an ssh key. Add the contents of the newly generated `~/.ssh/id_rsa.pub` file from your teslausb pi to the storage server's `~/.ssh/authorized_keys` file. This will allow a nice and easy connection through rsync, no passwords needed! +1. On your teslausb pi, run `ssh-keygen` to generate an ssh key **for the ROOT user!** If you followed the previous steps, you should have already ran `sudo -i` to become the root user on the telsausb pi. If you didn't, run `sudo -i` and re-run `ssh-keygen`. You can be sure that it is generating for root if it asks to store the key in `/root/.ssh/` (versus something like `/home/pi/.ssh`). + +1. Add the contents of the newly generated `/root/.ssh/id_rsa.pub` file from your teslausb pi to the storage server's `~/.ssh/authorized_keys` file. This will allow a nice and easy connection through rsync, no passwords needed! + +1. Lastly, you will need to authorize the connection to the FTP/Rsync server and test that the key works, so try connecting to the server (through ssh), and **if it asks if you wish to continue connecting, make sure to type `yes`!** If you do not do this, rsync will fail to connect and thus fail to archive your clips. # Step 2: Exports To be able to configure the teslausb pi use rsync, you'll need to export a few things. On your teslausb pi, run: @@ -33,4 +38,6 @@ export RSYNC_USER=pi export RSYNC_SERVER=192.168.1.254 export RSYNC_PATH=/mnt/PIHDD/TeslaCam/ ``` -***Note: RSYNC_ENABLE=true is going to disable the default archive server. Perhaps future releases will allow both to be defined and function at the same time, for redundancy, but for now just pick one that you'll want the most.*** \ No newline at end of file +***Note: RSYNC_ENABLE=true is going to disable the default archive server. Perhaps future releases will allow both to be defined and function at the same time, for redundancy, but for now just pick one that you'll want the most.*** + +You should be ready to run the setup script now, so return back to step 8 of the [Main Instructions](README.md). \ No newline at end of file From 664e47b1c05358cc7c074aed2d936b82a1ec7762 Mon Sep 17 00:00:00 2001 From: Stephen Gordon Date: Tue, 23 Oct 2018 07:47:23 -0400 Subject: [PATCH 06/45] Create the TeslaCam directory as part of the SD card setup --- windows_archive/setup-teslausb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 5910eab..b9da36e 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -103,6 +103,12 @@ function create_usb_drive_backing_files () { /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" } +function create_teslacam_directory () { + mount /mnt/cam + mkdir /mnt/cam/TeslaCam + umount /mnt/cam +} + function configure_archive () { echo "Configuring the archive..." mkdir /mnt/archive @@ -216,6 +222,8 @@ echo "" >> /etc/fstab create_usb_drive_backing_files +create_teslacam_directory + configure_archive configure_rc_local From 7eaead43aef881286ca2c8848058861805841b3f Mon Sep 17 00:00:00 2001 From: Stephen Gordon Date: Tue, 23 Oct 2018 09:13:25 -0400 Subject: [PATCH 07/45] Remove instructions about manually creating the TeslaCam directory --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index c672958..e963075 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,6 @@ After reboot, the Pi hostname will become `teslausb`, so future `ssh` sessions w ### Get the Pi set up for your Tesla. If you set up the Pi with a keyboard and a monitor disconnect it and connect it to a PC. 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 PC as a USB drive. -1. Create a directory named TeslaCam at the root of the drive labeled CAM. 1. Copy any music you'd like to the drive labeled MUSIC. 1. Eject the drives. 1. Unplug the Pi from the PC. From b71d7d77d6641df75c4e3babe6dc12cd8708161c Mon Sep 17 00:00:00 2001 From: Stephen Gordon Date: Tue, 23 Oct 2018 09:39:18 -0400 Subject: [PATCH 08/45] More changes to the readme instructions. Connecting the Pi to a PC after setup-teslausb is run is only required when adding music to the Pi --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e963075..2771d94 100644 --- a/README.md +++ b/README.md @@ -106,12 +106,14 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s ``` 1. Run this command: ``` - reboot + shutdown -h now ``` -After reboot, the Pi hostname will become `teslausb`, so future `ssh` sessions will be `ssh pi@teslausb.local`. +On the next boot, the Pi hostname will become `teslausb`, so future `ssh` sessions will be `ssh pi@teslausb.local`. -### Get the Pi set up for your Tesla. +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 If you set up the Pi with a keyboard and a monitor disconnect it and connect it to a PC. 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 PC as a USB drive. 1. Copy any music you'd like to the drive labeled MUSIC. From cc89acefce2286862c2e8e24f2c4e6370c7ea5c4 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 16:40:41 -0700 Subject: [PATCH 09/45] Halt is preferred. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2771d94..0b941a4 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s ``` 1. Run this command: ``` - shutdown -h now + halt ``` On the next boot, the Pi hostname will become `teslausb`, so future `ssh` sessions will be `ssh pi@teslausb.local`. From 5b75897c7d480df27ef266272c99e63efd499695 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 18:18:35 -0700 Subject: [PATCH 10/45] Move creation of the TeslaCam directory to create-backingfiles.sh The create-backingfiles.sh file already contains the responsibility for defining the mount points, which this step needs. --- windows_archive/create-backingfiles.sh | 8 ++++++++ windows_archive/setup-teslausb | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/windows_archive/create-backingfiles.sh b/windows_archive/create-backingfiles.sh index a406df4..69f19b4 100644 --- a/windows_archive/create-backingfiles.sh +++ b/windows_archive/create-backingfiles.sh @@ -21,6 +21,12 @@ function add_drive () { echo "$filename $mountpoint vfat noauto,users,umask=000 0 0" >> /etc/fstab } +function create_teslacam_directory () { + mount /mnt/cam + mkdir /mnt/cam/TeslaCam + umount /mnt/cam +} + FREE_1K_BLOCKS="$(df --output=avail --block-size=1K /backingfiles/ | tail -n 1)" CAM_DISK_SIZE="$(( $FREE_1K_BLOCKS * $CAM_PERCENT / 100 ))" @@ -36,3 +42,5 @@ then else echo "options g_mass_storage file=$CAM_DISK_FILE_NAME removable=1 ro=0 stall=0 iSerialNumber=123456" > "$G_MASS_STORAGE_CONF_FILE_NAME" fi + +create_teslacam_directory diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 3fe1526..c50b31b 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -139,12 +139,6 @@ function create_usb_drive_backing_files () { /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" } -function create_teslacam_directory () { - mount /mnt/cam - mkdir /mnt/cam/TeslaCam - umount /mnt/cam -} - function configure_archive () { local archive_server_ip_address="$1" @@ -276,8 +270,6 @@ echo "" >> /etc/fstab create_usb_drive_backing_files -create_teslacam_directory - configure_archive "$ARCHIVE_SERVER_IP_ADDRESS" configure_rc_local From a7a9110160505b167f5ef4e601d9efc114942871 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 18:29:26 -0700 Subject: [PATCH 11/45] Just three phases to setting up the Pi, now. --- README.md | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0b941a4..6f3c49e 100644 --- a/README.md +++ b/README.md @@ -58,11 +58,10 @@ Get the IP address of the archive machine. You'll need this later, so write it d ### TODO Other hosting solutions ## Set up the Raspberry Pi -There are four phases to setting up the Pi: +There are three phases to setting up the Pi: 1. Get the OS onto the micro sd card. 1. Get a shell on the Pi. 1. Set up the USB storage functionality. -1. Get the Pi set up for your Tesla. ### Get the OS onto the micro SD card @@ -73,13 +72,17 @@ There are four phases to setting up the Pi: ### Get a shell on the Pi If you used a Windows computer to flash the OS onto the MicroSD card, follow these [Instructions](GetShellWithoutMonitorOnWindows.md). + If you used a Mac or a Linux computer, follow these [Instructions](GetShellWithoutMonitorOnLinux.md). ### Set up the USB storage functionality Now that you have Wifi up and running, it's time to set up the USB storage and scripts that will manage the dashcam and (optionally) music storage. -1. SSH to the Pi and run `sudo -i` +1. SSH to the Pi and run + ``` + sudo -i + ``` 1. Try to ping your archive server from the Pi. In this example the server is named `nautilus`. ``` ping -c 3 nautilus @@ -108,29 +111,30 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s ``` halt ``` +1. Disconnect the Pi from the computer. On the next boot, the Pi hostname will become `teslausb`, so future `ssh` sessions will be `ssh pi@teslausb.local`. -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. +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 -If you set up the Pi with a keyboard and a monitor disconnect it and connect it to a PC. 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 PC as a USB drive. +## (Optional) Add music to the Pi +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. 1. Eject the drives. 1. Unplug the Pi from the PC. 1. Plug the Pi into your Tesla. ## 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 corruption of the operating system when the Tesla cuts power to the Pi. +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 +corruption of the operating system when the Tesla cuts power to the Pi. To make changes to the system partitions: ``` ssh pi@teslausb. sudo -i -mount / -o remount,rw -mount /boot -o remount,rw +/root/bin/remountfs_rw ``` Then make whatever changes you need to. The next time the system boots the partitions will once again be read-only. From c563f287ba383ca5fe45d99bc455b9b276339368 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 20:26:27 -0700 Subject: [PATCH 12/45] Make send-pushover safe to always invoke, and always invoke it. Split CIFS archiving to archive-cifs.sh --- windows_archive/archive-cifs.sh | 18 +++++++++++++++ windows_archive/archive-rsync | 24 +++++++------------- windows_archive/archive-teslacam-clips | 31 +++++--------------------- windows_archive/send-pushover | 19 +++++++++++----- windows_archive/setup-teslausb | 3 --- 5 files changed, 44 insertions(+), 51 deletions(-) create mode 100644 windows_archive/archive-cifs.sh diff --git a/windows_archive/archive-cifs.sh b/windows_archive/archive-cifs.sh new file mode 100644 index 0000000..ec3b4c0 --- /dev/null +++ b/windows_archive/archive-cifs.sh @@ -0,0 +1,18 @@ +#!/bin/bash -eu + +log "Moving clips to archive..." + +local move_count=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." + move_count=$((move_count + 1)) +done +log "Moved $move_count file(s)." + +/root/bin/send-pushover "$num_files_moved" + +log "Finished moving clips to archive." diff --git a/windows_archive/archive-rsync b/windows_archive/archive-rsync index d163640..29f5a55 100644 --- a/windows_archive/archive-rsync +++ b/windows_archive/archive-rsync @@ -1,24 +1,16 @@ #!/bin/bash -eu -LOG_FILE=/tmp/archive-rsync.log - -function log () { - echo "$( date )" >> "$LOG_FILE" - echo "$1" >> "$LOG_FILE" -} +log "Archiving through rsync..." source /root/.teslaCamRsyncConfig -nfiles=$(rsync -auvh --stats --log-file=/tmp/archive-rsync-cmd.log /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') +num_files_moved=$(rsync -auvh --stats --log-file=/tmp/archive-rsync-cmd.log /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') -if [ $nfiles > 0 ] +/root/bin/send-pushover "$num_files_moved" + +if [ $num_files_moved > 0 ] then - if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $nfiles > 0] - then - log "Sending Pushover message for copied files." - /root/bin/send-pushover $nfiles - fi - log "Successfully synced files through rsync!" + log "Successfully synced files through rsync." else - log "No files to archive through rsync!" -fi \ No newline at end of file + log "No files to archive through rsync." +fi diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index c98d637..94e42d2 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -1,35 +1,13 @@ #!/bin/bash -eu -LOG_FILE=/tmp/archive-teslacam-clips.log -ARCHIVE_MOUNT=/mnt/archive +export LOG_FILE=/tmp/archive-teslacam-clips.log +export ARCHIVE_MOUNT=/mnt/archive function log () { echo "$( date )" >> "$LOG_FILE" echo "$1" >> "$LOG_FILE" } -function move_clips_to_archive () { - log "Moving clips to archive..." - local move_count=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." - move_count=$((move_count + 1)) - - done - log "Moved $move_count file(s)." - - if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $move_count > 0] - then - log "Sending Pushover message for copied files." - /root/bin/send-pushover $move_count - fi - - log "Finished moving clips to archive." -} - function disconnect_usb_drives_from_host () { log "Disconnecting usb from host..." modprobe -r g_mass_storage @@ -42,6 +20,8 @@ function ensure_archive_is_mounted () { log "Ensured cam archive is mounted." } +export -f log + log "Starting..." if [ ! -r "/root/.teslaCamRsyncConfig" ] @@ -57,10 +37,9 @@ fix_errors_in_cam_file if [ -r "/root/.teslaCamRsyncConfig" ] then - log "Archiving through rsync..." /root/bin/archive-rsync else - move_clips_to_archive + /root/bin/archive-cifs.sh fi unmount_cam_file diff --git a/windows_archive/send-pushover b/windows_archive/send-pushover index 6948c06..442833e 100644 --- a/windows_archive/send-pushover +++ b/windows_archive/send-pushover @@ -1,14 +1,21 @@ #!/bin/bash -eu +local num_files_moved="$1" + function log () { echo "$( date )" >> "$LOG_FILE" echo "$1" >> "$LOG_FILE" } -source /root/.teslaCamPushoverCredentials +if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $num_files_moved > 0] +then + log "Sending Pushover message for moved files." -curl -F "token=$pushover_app_key" \ --F "user=$pushover_user_key" \ --F "title=Dashcam Copy Complete" \ --F "message=$1 file(s) were copied." \ -https://api.pushover.net/1/messages + source /root/.teslaCamPushoverCredentials + + curl -F "token=$pushover_app_key" \ + -F "user=$pushover_user_key" \ + -F "title=Dashcam Copy Complete" \ + -F "message=$num_files_moved file(s) were copied." \ + https://api.pushover.net/1/messages +fi diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 9a0e2ee..a2460b2 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -199,13 +199,10 @@ function configure_archive_scripts () { } function configure_pushover_scripts() { -if [ ${USER_ENABLED_PUSHOVER} = "true" ] -then pushd /root/bin wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover chmod +x send-pushover popd -fi } function configure_rc_local () { From a174e74bb8033357f074874b4f3888fde0c0a5d5 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 20:32:28 -0700 Subject: [PATCH 13/45] Rename archive-rsync to archive-rsync.sh --- windows_archive/{archive-rsync => archive-rsync.sh} | 0 windows_archive/archive-teslacam-clips | 2 +- windows_archive/setup-teslausb | 7 +++++-- 3 files changed, 6 insertions(+), 3 deletions(-) rename windows_archive/{archive-rsync => archive-rsync.sh} (100%) diff --git a/windows_archive/archive-rsync b/windows_archive/archive-rsync.sh similarity index 100% rename from windows_archive/archive-rsync rename to windows_archive/archive-rsync.sh diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index 94e42d2..a79a1e3 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -37,7 +37,7 @@ fix_errors_in_cam_file if [ -r "/root/.teslaCamRsyncConfig" ] then - /root/bin/archive-rsync + /root/bin/archive-rsync.sh else /root/bin/archive-cifs.sh fi diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index a2460b2..d36a7be 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -185,8 +185,11 @@ function configure_archive_scripts () { if [ $RSYNC_ENABLE = true ] then - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-rsync - chmod +x archive-rsync + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-rsync.sh + chmod +x archive-rsync.sh + else + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-cifs.sh + chmod +x archive-cifs.sh fi popd echo "Configured the archive scripts." From 21b22ba4cca821ebf4471f6bcebc503be5f9adfb Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 20:50:04 -0700 Subject: [PATCH 14/45] Prepare for abstract connect, disconnect, archive. --- windows_archive/archive-teslacam-clips | 19 +++++++++++-------- windows_archive/connect-archive-cifs.sh | 9 +++++++++ windows_archive/connect-archive-rsync.sh | 2 ++ windows_archive/disconnect-archive-cifs.sh | 2 ++ windows_archive/disconnect-archive-rsync.sh | 2 ++ windows_archive/setup-teslausb | 16 ++++++++++++++-- 6 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 windows_archive/connect-archive-cifs.sh create mode 100644 windows_archive/connect-archive-rsync.sh create mode 100644 windows_archive/disconnect-archive-cifs.sh create mode 100644 windows_archive/disconnect-archive-rsync.sh diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index a79a1e3..e2b1322 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -14,19 +14,15 @@ function disconnect_usb_drives_from_host () { log "Disconnected usb from host." } -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." -} - export -f log log "Starting..." -if [ ! -r "/root/.teslaCamRsyncConfig" ] +if [ -r "/root/.teslaCamRsyncConfig" ] then - ensure_archive_is_mounted + /root/bin/connect-archive-rsync.sh +else + /root/bin/connect-archive-cifs.sh fi disconnect_usb_drives_from_host @@ -42,6 +38,13 @@ else /root/bin/archive-cifs.sh fi +if [ -r "/root/.teslaCamRsyncConfig" ] +then + /root/bin/disconnect-archive-rsync.sh +else + /root/bin/disconnect-archive-cifs.sh +fi + unmount_cam_file connect_usb_drives_to_host diff --git a/windows_archive/connect-archive-cifs.sh b/windows_archive/connect-archive-cifs.sh new file mode 100644 index 0000000..c93f12f --- /dev/null +++ b/windows_archive/connect-archive-cifs.sh @@ -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 diff --git a/windows_archive/connect-archive-rsync.sh b/windows_archive/connect-archive-rsync.sh new file mode 100644 index 0000000..cfcbd8e --- /dev/null +++ b/windows_archive/connect-archive-rsync.sh @@ -0,0 +1,2 @@ +#!/bin/bash -eu +# Nothing to do. \ No newline at end of file diff --git a/windows_archive/disconnect-archive-cifs.sh b/windows_archive/disconnect-archive-cifs.sh new file mode 100644 index 0000000..dee089a --- /dev/null +++ b/windows_archive/disconnect-archive-cifs.sh @@ -0,0 +1,2 @@ +#!/bin/bash -eu +# Nothing to do. It's okay to leave the archive mounted. \ No newline at end of file diff --git a/windows_archive/disconnect-archive-rsync.sh b/windows_archive/disconnect-archive-rsync.sh new file mode 100644 index 0000000..cfcbd8e --- /dev/null +++ b/windows_archive/disconnect-archive-rsync.sh @@ -0,0 +1,2 @@ +#!/bin/bash -eu +# Nothing to do. \ No newline at end of file diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index d36a7be..1620a21 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -86,7 +86,7 @@ function check_archive_mountable () { 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 + exit 1 fi umount "$test_mount_location" @@ -187,9 +187,21 @@ function configure_archive_scripts () { then wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-rsync.sh chmod +x archive-rsync.sh + + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/connect-archive-rsync.sh + chmod +x connect-archive-rsync.sh + + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/disconnect-archive-rsync.sh + chmod +x disconnect-archive-rsync.sh else wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-cifs.sh - chmod +x archive-cifs.sh + chmod +x archive-cifs.sh + + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/connect-archive-cifs.sh + chmod +x connect-archive-cifs.sh + + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/disconnect-archive-cifs.sh + chmod +x disconnect-archive-cifs.sh fi popd echo "Configured the archive scripts." From f84d727d9a7727be75ce66399d54e0885984fda3 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 20:54:16 -0700 Subject: [PATCH 15/45] Move rsync files to rsync_archive --- {windows_archive => rsync_archive}/archive-rsync.sh | 0 {windows_archive => rsync_archive}/connect-archive-rsync.sh | 0 .../disconnect-archive-rsync.sh | 0 windows_archive/setup-teslausb | 6 +++--- 4 files changed, 3 insertions(+), 3 deletions(-) rename {windows_archive => rsync_archive}/archive-rsync.sh (100%) rename {windows_archive => rsync_archive}/connect-archive-rsync.sh (100%) rename {windows_archive => rsync_archive}/disconnect-archive-rsync.sh (100%) diff --git a/windows_archive/archive-rsync.sh b/rsync_archive/archive-rsync.sh similarity index 100% rename from windows_archive/archive-rsync.sh rename to rsync_archive/archive-rsync.sh diff --git a/windows_archive/connect-archive-rsync.sh b/rsync_archive/connect-archive-rsync.sh similarity index 100% rename from windows_archive/connect-archive-rsync.sh rename to rsync_archive/connect-archive-rsync.sh diff --git a/windows_archive/disconnect-archive-rsync.sh b/rsync_archive/disconnect-archive-rsync.sh similarity index 100% rename from windows_archive/disconnect-archive-rsync.sh rename to rsync_archive/disconnect-archive-rsync.sh diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 1620a21..a5194ef 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -185,13 +185,13 @@ function configure_archive_scripts () { if [ $RSYNC_ENABLE = true ] then - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-rsync.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/archive-rsync.sh chmod +x archive-rsync.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/connect-archive-rsync.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/connect-archive-rsync.sh chmod +x connect-archive-rsync.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/disconnect-archive-rsync.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/disconnect-archive-rsync.sh chmod +x disconnect-archive-rsync.sh else wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-cifs.sh From 8dc3b4ea699ffca052e30c175c0be55384461631 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 20:57:58 -0700 Subject: [PATCH 16/45] Abstract archive-clips.sh --- rsync_archive/{archive-rsync.sh => archive-clips.sh} | 0 windows_archive/{archive-cifs.sh => archive-clips.sh} | 0 windows_archive/archive-teslacam-clips | 7 +------ windows_archive/setup-teslausb | 8 ++++---- 4 files changed, 5 insertions(+), 10 deletions(-) rename rsync_archive/{archive-rsync.sh => archive-clips.sh} (100%) rename windows_archive/{archive-cifs.sh => archive-clips.sh} (100%) diff --git a/rsync_archive/archive-rsync.sh b/rsync_archive/archive-clips.sh similarity index 100% rename from rsync_archive/archive-rsync.sh rename to rsync_archive/archive-clips.sh diff --git a/windows_archive/archive-cifs.sh b/windows_archive/archive-clips.sh similarity index 100% rename from windows_archive/archive-cifs.sh rename to windows_archive/archive-clips.sh diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index e2b1322..99b31fd 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -31,12 +31,7 @@ ensure_cam_file_is_mounted fix_errors_in_cam_file -if [ -r "/root/.teslaCamRsyncConfig" ] -then - /root/bin/archive-rsync.sh -else - /root/bin/archive-cifs.sh -fi +/root/bin/archive-clips.sh if [ -r "/root/.teslaCamRsyncConfig" ] then diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index a5194ef..87e3d0c 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -185,8 +185,8 @@ function configure_archive_scripts () { if [ $RSYNC_ENABLE = true ] then - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/archive-rsync.sh - chmod +x archive-rsync.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/archive-clips.sh + chmod +x archive-clips.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/connect-archive-rsync.sh chmod +x connect-archive-rsync.sh @@ -194,8 +194,8 @@ function configure_archive_scripts () { wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/disconnect-archive-rsync.sh chmod +x disconnect-archive-rsync.sh else - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-cifs.sh - chmod +x archive-cifs.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-clips.sh + chmod +x archive-clips.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/connect-archive-cifs.sh chmod +x connect-archive-cifs.sh From 4c4e5ad93b24d9a2ef1bb3c18ed3aaff2eaa94c9 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 21:01:02 -0700 Subject: [PATCH 17/45] Abstract connect-archive.sh and disconnect-archive.sh --- ...nnect-archive-rsync.sh => connect-archive.sh} | 0 ...ct-archive-rsync.sh => disconnect-archive.sh} | 0 windows_archive/archive-teslacam-clips | 14 ++------------ ...onnect-archive-cifs.sh => connect-archive.sh} | 0 ...ect-archive-cifs.sh => disconnect-archive.sh} | 0 windows_archive/setup-teslausb | 16 ++++++++-------- 6 files changed, 10 insertions(+), 20 deletions(-) rename rsync_archive/{connect-archive-rsync.sh => connect-archive.sh} (100%) rename rsync_archive/{disconnect-archive-rsync.sh => disconnect-archive.sh} (100%) rename windows_archive/{connect-archive-cifs.sh => connect-archive.sh} (100%) rename windows_archive/{disconnect-archive-cifs.sh => disconnect-archive.sh} (100%) diff --git a/rsync_archive/connect-archive-rsync.sh b/rsync_archive/connect-archive.sh similarity index 100% rename from rsync_archive/connect-archive-rsync.sh rename to rsync_archive/connect-archive.sh diff --git a/rsync_archive/disconnect-archive-rsync.sh b/rsync_archive/disconnect-archive.sh similarity index 100% rename from rsync_archive/disconnect-archive-rsync.sh rename to rsync_archive/disconnect-archive.sh diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index 99b31fd..a29be15 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -18,12 +18,7 @@ export -f log log "Starting..." -if [ -r "/root/.teslaCamRsyncConfig" ] -then - /root/bin/connect-archive-rsync.sh -else - /root/bin/connect-archive-cifs.sh -fi +/root/bin/connect-archive.sh disconnect_usb_drives_from_host @@ -33,12 +28,7 @@ fix_errors_in_cam_file /root/bin/archive-clips.sh -if [ -r "/root/.teslaCamRsyncConfig" ] -then - /root/bin/disconnect-archive-rsync.sh -else - /root/bin/disconnect-archive-cifs.sh -fi +/root/bin/disconnect-archive.sh unmount_cam_file diff --git a/windows_archive/connect-archive-cifs.sh b/windows_archive/connect-archive.sh similarity index 100% rename from windows_archive/connect-archive-cifs.sh rename to windows_archive/connect-archive.sh diff --git a/windows_archive/disconnect-archive-cifs.sh b/windows_archive/disconnect-archive.sh similarity index 100% rename from windows_archive/disconnect-archive-cifs.sh rename to windows_archive/disconnect-archive.sh diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 87e3d0c..3a7f533 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -188,20 +188,20 @@ function configure_archive_scripts () { wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/archive-clips.sh chmod +x archive-clips.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/connect-archive-rsync.sh - chmod +x connect-archive-rsync.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/connect-archive.sh + chmod +x connect-archive.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/disconnect-archive-rsync.sh - chmod +x disconnect-archive-rsync.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/disconnect-archive.sh + chmod +x disconnect-archive.sh else wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-clips.sh chmod +x archive-clips.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/connect-archive-cifs.sh - chmod +x connect-archive-cifs.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/connect-archive.sh + chmod +x connect-archive.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/disconnect-archive-cifs.sh - chmod +x disconnect-archive-cifs.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/disconnect-archive.sh + chmod +x disconnect-archive.sh fi popd echo "Configured the archive scripts." From 9261cc9b2017dff227ad15a6c7232000be4f7c84 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 21:02:19 -0700 Subject: [PATCH 18/45] Extract duplicate chmod calls. --- windows_archive/setup-teslausb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 3a7f533..f232a2c 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -186,23 +186,22 @@ function configure_archive_scripts () { if [ $RSYNC_ENABLE = true ] then wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/archive-clips.sh - chmod +x archive-clips.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/connect-archive.sh - chmod +x connect-archive.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/disconnect-archive.sh - chmod +x disconnect-archive.sh else wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-clips.sh - chmod +x archive-clips.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/connect-archive.sh - chmod +x connect-archive.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/disconnect-archive.sh - chmod +x disconnect-archive.sh fi + + chmod +x archive-clips.sh + chmod +x connect-archive.sh + chmod +x disconnect-archive.sh + popd echo "Configured the archive scripts." From 1685fa78f7e69153bf47f0c965e89496b8a8d216 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:05:25 -0700 Subject: [PATCH 19/45] Move CIFS-specific functions out of setup-teslausb. --- get-archiveserver-ip-address.sh | 3 + rsync_archive/configure-archive.sh | 16 +++ rsync_archive/verify-archive-configuration.sh | 1 + windows_archive/archiveloop | 4 +- windows_archive/configure-archive.sh | 28 ++++ windows_archive/setup-teslausb | 122 +++++------------- .../verify-archive-configuration.sh | 49 +++++++ .../write-archive-credentials-to.sh | 6 + 8 files changed, 133 insertions(+), 96 deletions(-) create mode 100644 get-archiveserver-ip-address.sh create mode 100644 rsync_archive/configure-archive.sh create mode 100644 rsync_archive/verify-archive-configuration.sh create mode 100644 windows_archive/configure-archive.sh create mode 100644 windows_archive/verify-archive-configuration.sh create mode 100644 windows_archive/write-archive-credentials-to.sh diff --git a/get-archiveserver-ip-address.sh b/get-archiveserver-ip-address.sh new file mode 100644 index 0000000..8a3936e --- /dev/null +++ b/get-archiveserver-ip-address.sh @@ -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 '()')" \ No newline at end of file diff --git a/rsync_archive/configure-archive.sh b/rsync_archive/configure-archive.sh new file mode 100644 index 0000000..4fcb84c --- /dev/null +++ b/rsync_archive/configure-archive.sh @@ -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" \ No newline at end of file diff --git a/rsync_archive/verify-archive-configuration.sh b/rsync_archive/verify-archive-configuration.sh new file mode 100644 index 0000000..95dbbf8 --- /dev/null +++ b/rsync_archive/verify-archive-configuration.sh @@ -0,0 +1 @@ +#!/bin/bash -eu \ No newline at end of file diff --git a/windows_archive/archiveloop b/windows_archive/archiveloop index 257eba9..006540e 100644 --- a/windows_archive/archiveloop +++ b/windows_archive/archiveloop @@ -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 diff --git a/windows_archive/configure-archive.sh b/windows_archive/configure-archive.sh new file mode 100644 index 0000000..e49b897 --- /dev/null +++ b/windows_archive/configure-archive.sh @@ -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" \ No newline at end of file diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index f232a2c..8fabc08 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -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 @@ -196,8 +113,10 @@ function configure_archive_scripts () { wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/connect-archive.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/disconnect-archive.sh - fi - + 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 + + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/write-archive-credentials-to.sh + chmod +x write-archive-credentials-to.sh +fi -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 '()')" +chmod +x verify-archive-configuration.sh +chmod +x configure-archive.sh -check_archive_mountable "$ARCHIVE_SERVER_IP_ADDRESS" +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 diff --git a/windows_archive/verify-archive-configuration.sh b/windows_archive/verify-archive-configuration.sh new file mode 100644 index 0000000..8724361 --- /dev/null +++ b/windows_archive/verify-archive-configuration.sh @@ -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" diff --git a/windows_archive/write-archive-credentials-to.sh b/windows_archive/write-archive-credentials-to.sh new file mode 100644 index 0000000..c80ff38 --- /dev/null +++ b/windows_archive/write-archive-credentials-to.sh @@ -0,0 +1,6 @@ +#!/bin/bash -eu + +local file_path="$1" + +echo "username=$shareuser" > "$file_path" +echo "password=$sharepassword" >> "$file_path" From d1cd47cbda9e73b7f695f9d7eca6c1775e4152aa Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:11:05 -0700 Subject: [PATCH 20/45] Move archiveloop, archive-teslacam-clips, and remountfs_rw to the top level. --- .../archive-teslacam-clips => archive-teslacam-clips | 0 windows_archive/archiveloop => archiveloop | 0 windows_archive/remountfs_rw => remountfs_rw | 0 windows_archive/setup-teslausb | 9 ++++----- 4 files changed, 4 insertions(+), 5 deletions(-) rename windows_archive/archive-teslacam-clips => archive-teslacam-clips (100%) rename windows_archive/archiveloop => archiveloop (100%) rename windows_archive/remountfs_rw => remountfs_rw (100%) diff --git a/windows_archive/archive-teslacam-clips b/archive-teslacam-clips similarity index 100% rename from windows_archive/archive-teslacam-clips rename to archive-teslacam-clips diff --git a/windows_archive/archiveloop b/archiveloop similarity index 100% rename from windows_archive/archiveloop rename to archiveloop diff --git a/windows_archive/remountfs_rw b/remountfs_rw similarity index 100% rename from windows_archive/remountfs_rw rename to remountfs_rw diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 8fabc08..1a00641 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -96,9 +96,9 @@ function configure_archive_scripts () { mkdir /root/bin pushd /root/bin - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/archiveloop - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/archive-teslacam-clips if [ $RSYNC_ENABLE = true ] then @@ -124,11 +124,10 @@ function configure_archive_scripts () { popd echo "Configured the archive scripts." - pushd /root - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw + pushd /root/bin + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/remountfs_rw chmod +x remountfs_rw popd - echo "Downloaded script to remount filesystems read/write if needed (/root/remountfs_rw)." } function configure_pushover_scripts() { From 50f0b3788d2f1ca3bdac4939eb92216a3a666c1d Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:16:59 -0700 Subject: [PATCH 21/45] Eliminate redundant checks of cifs_version. --- windows_archive/configure-archive.sh | 2 -- windows_archive/setup-teslausb | 22 +++++++++---------- .../verify-archive-configuration.sh | 2 -- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/windows_archive/configure-archive.sh b/windows_archive/configure-archive.sh index e49b897..96638f7 100644 --- a/windows_archive/configure-archive.sh +++ b/windows_archive/configure-archive.sh @@ -1,7 +1,5 @@ #!/bin/bash -eu -cifs_version="${cifs_version:-3}" - function configure_archive () { local archive_server_ip_address="$1" diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 1a00641..b6300ce 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -178,22 +178,20 @@ function make_root_fs_readonly () { echo "Verifying environment variables..." -if [ ! -n "${cifs_version+x}" ] -then - cifs_version=3 -fi - if [ $RSYNC_ENABLE = true ] then - check_variable "RSYNC_USER" - check_variable "RSYNC_SERVER" - export archiveserver=$RSYNC_SERVER - check_variable "RSYNC_PATH" + check_variable "RSYNC_USER" + check_variable "RSYNC_SERVER" + export archiveserver=$RSYNC_SERVER + check_variable "RSYNC_PATH" else # Else for now, TODO allow both for more redundancy? - check_variable "sharename" - check_variable "shareuser" - check_variable "sharepassword" + check_variable "sharename" + check_variable "shareuser" + check_variable "sharepassword" + + export cifs_version="${cifs_version:-3}" fi + check_variable "archiveserver" check_variable "campercent" diff --git a/windows_archive/verify-archive-configuration.sh b/windows_archive/verify-archive-configuration.sh index 8724361..b64d9f0 100644 --- a/windows_archive/verify-archive-configuration.sh +++ b/windows_archive/verify-archive-configuration.sh @@ -1,7 +1,5 @@ #!/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 From 3566132c18cc397c4a1c1848e753a9acd4a4c1f6 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:20:35 -0700 Subject: [PATCH 22/45] Set archiveserver in rc.local. --- windows_archive/setup-teslausb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index b6300ce..edee190 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -141,6 +141,8 @@ function configure_rc_local () { echo "Configuring /etc/rc.local to run the archive scripts at startup..." echo "#!/bin/bash -eu" > ~/rc.local tail -n +2 /etc/rc.local | sed '$d' >> ~/rc.local + + echo "archiveserver=\"${archiveserver}\"" >> ~/rc.local cat << 'EOF' >> ~/rc.local LOGFILE=/tmp/rc.local.log From 59fff033ac0484c9090d3669b8b3e444e6a53232 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:22:20 -0700 Subject: [PATCH 23/45] Move setup-teslausb to top level. --- README.md | 2 +- windows_archive/setup-teslausb => setup-teslausb | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename windows_archive/setup-teslausb => setup-teslausb (100%) diff --git a/README.md b/README.md index 9017c01..ab60119 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s 1. If you'd like to receive a text message when your Pi finishes archiving clips follow these [Instructions](ConfigureNotificationsForArchive.md). 1. Run these commands: ``` - wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/setup-teslausb + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup-teslausb chmod +x setup-teslausb ./setup-teslausb ``` diff --git a/windows_archive/setup-teslausb b/setup-teslausb similarity index 100% rename from windows_archive/setup-teslausb rename to setup-teslausb From e4e24d008de4a0dc4bec6f108a3b1701d855b669 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:24:16 -0700 Subject: [PATCH 24/45] Move create-backingfiles-partition.sh, create-backingfiles.sh, make-root-fs-readonly.sh to top level. --- ...ngfiles-partition.sh => create-backingfiles-partition.sh | 0 .../create-backingfiles.sh => create-backingfiles.sh | 0 .../make-root-fs-readonly.sh => make-root-fs-readonly.sh | 0 setup-teslausb | 6 +++--- 4 files changed, 3 insertions(+), 3 deletions(-) rename windows_archive/create-backingfiles-partition.sh => create-backingfiles-partition.sh (100%) rename windows_archive/create-backingfiles.sh => create-backingfiles.sh (100%) rename windows_archive/make-root-fs-readonly.sh => make-root-fs-readonly.sh (100%) diff --git a/windows_archive/create-backingfiles-partition.sh b/create-backingfiles-partition.sh similarity index 100% rename from windows_archive/create-backingfiles-partition.sh rename to create-backingfiles-partition.sh diff --git a/windows_archive/create-backingfiles.sh b/create-backingfiles.sh similarity index 100% rename from windows_archive/create-backingfiles.sh rename to create-backingfiles.sh diff --git a/windows_archive/make-root-fs-readonly.sh b/make-root-fs-readonly.sh similarity index 100% rename from windows_archive/make-root-fs-readonly.sh rename to make-root-fs-readonly.sh diff --git a/setup-teslausb b/setup-teslausb index edee190..31723d7 100644 --- a/setup-teslausb +++ b/setup-teslausb @@ -60,11 +60,11 @@ function check_available_space () { function get_ancillary_setup_scripts () { pushd /tmp - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/create-backingfiles-partition.sh chmod +x ./create-backingfiles-partition.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/create-backingfiles.sh chmod +x ./create-backingfiles.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/make-root-fs-readonly.sh chmod +x ./make-root-fs-readonly.sh popd } From b60397ee291dab767d746c8d1ac2d6ec02fd33af Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:26:39 -0700 Subject: [PATCH 25/45] Move send-pushover to top level. --- windows_archive/send-pushover => send-pushover | 0 setup-teslausb | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename windows_archive/send-pushover => send-pushover (100%) diff --git a/windows_archive/send-pushover b/send-pushover similarity index 100% rename from windows_archive/send-pushover rename to send-pushover diff --git a/setup-teslausb b/setup-teslausb index 31723d7..338989b 100644 --- a/setup-teslausb +++ b/setup-teslausb @@ -132,7 +132,7 @@ function configure_archive_scripts () { function configure_pushover_scripts() { pushd /root/bin - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/send-pushover chmod +x send-pushover popd } From ffa8f8980d5c2d4ea1889ed1f0130cbbb552280f Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:28:13 -0700 Subject: [PATCH 26/45] Move setup-piForHeadlessConfig.ps1 to top level. --- GetShellWithoutMonitorOnWindows.md | 2 +- ...tup-piForHeadlessConfig.ps1 => setup-piForHeadlessConfig.ps1 | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename windows_archive/setup-piForHeadlessConfig.ps1 => setup-piForHeadlessConfig.ps1 (100%) diff --git a/GetShellWithoutMonitorOnWindows.md b/GetShellWithoutMonitorOnWindows.md index 86a8773..205c0b2 100644 --- a/GetShellWithoutMonitorOnWindows.md +++ b/GetShellWithoutMonitorOnWindows.md @@ -14,7 +14,7 @@ 1. Run the following commands: ``` cd ~ - wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/setup-piForHeadlessConfig.ps1 -OutFile setup-piForHeadlessConfig.ps1 + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup-piForHeadlessConfig.ps1 -OutFile setup-piForHeadlessConfig.ps1 ./setup-piForHeadlessConfig.ps1 -Verbose ``` 1. Enter the single letter of the "boot" drive and press Enter. diff --git a/windows_archive/setup-piForHeadlessConfig.ps1 b/setup-piForHeadlessConfig.ps1 similarity index 100% rename from windows_archive/setup-piForHeadlessConfig.ps1 rename to setup-piForHeadlessConfig.ps1 From 07006c31c1b2dd5790354f5ed4b709f32a3ec55e Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:29:21 -0700 Subject: [PATCH 27/45] Move setup-piForHeadlessConfig.sh to top level. --- .../setup-piForHeadlessConfig.sh => setup-piForHeadlessConfig.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename mac_linux_archive/setup-piForHeadlessConfig.sh => setup-piForHeadlessConfig.sh (100%) mode change 100755 => 100644 diff --git a/mac_linux_archive/setup-piForHeadlessConfig.sh b/setup-piForHeadlessConfig.sh old mode 100755 new mode 100644 similarity index 100% rename from mac_linux_archive/setup-piForHeadlessConfig.sh rename to setup-piForHeadlessConfig.sh From e61eb737bc793af44b08bd76e97f49a012edee21 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:33:59 -0700 Subject: [PATCH 28/45] Rename windows_archive -> cifs_archive --- {windows_archive => cifs_archive}/archive-clips.sh | 0 .../configure-archive.sh | 0 {windows_archive => cifs_archive}/connect-archive.sh | 0 .../disconnect-archive.sh | 0 .../verify-archive-configuration.sh | 0 .../write-archive-credentials-to.sh | 0 setup-teslausb | 12 ++++++------ 7 files changed, 6 insertions(+), 6 deletions(-) rename {windows_archive => cifs_archive}/archive-clips.sh (100%) rename {windows_archive => cifs_archive}/configure-archive.sh (100%) rename {windows_archive => cifs_archive}/connect-archive.sh (100%) rename {windows_archive => cifs_archive}/disconnect-archive.sh (100%) rename {windows_archive => cifs_archive}/verify-archive-configuration.sh (100%) rename {windows_archive => cifs_archive}/write-archive-credentials-to.sh (100%) diff --git a/windows_archive/archive-clips.sh b/cifs_archive/archive-clips.sh similarity index 100% rename from windows_archive/archive-clips.sh rename to cifs_archive/archive-clips.sh diff --git a/windows_archive/configure-archive.sh b/cifs_archive/configure-archive.sh similarity index 100% rename from windows_archive/configure-archive.sh rename to cifs_archive/configure-archive.sh diff --git a/windows_archive/connect-archive.sh b/cifs_archive/connect-archive.sh similarity index 100% rename from windows_archive/connect-archive.sh rename to cifs_archive/connect-archive.sh diff --git a/windows_archive/disconnect-archive.sh b/cifs_archive/disconnect-archive.sh similarity index 100% rename from windows_archive/disconnect-archive.sh rename to cifs_archive/disconnect-archive.sh diff --git a/windows_archive/verify-archive-configuration.sh b/cifs_archive/verify-archive-configuration.sh similarity index 100% rename from windows_archive/verify-archive-configuration.sh rename to cifs_archive/verify-archive-configuration.sh diff --git a/windows_archive/write-archive-credentials-to.sh b/cifs_archive/write-archive-credentials-to.sh similarity index 100% rename from windows_archive/write-archive-credentials-to.sh rename to cifs_archive/write-archive-credentials-to.sh diff --git a/setup-teslausb b/setup-teslausb index 338989b..65e6fc5 100644 --- a/setup-teslausb +++ b/setup-teslausb @@ -108,11 +108,11 @@ function configure_archive_scripts () { wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/disconnect-archive.sh else - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-clips.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/archive-clips.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/connect-archive.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/connect-archive.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/disconnect-archive.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/disconnect-archive.sh fi chmod +x archiveloop @@ -205,10 +205,10 @@ 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 + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/verify-archive-configuration.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/configure-archive.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/write-archive-credentials-to.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/write-archive-credentials-to.sh chmod +x write-archive-credentials-to.sh fi From 32e94acd2a3f86e806479f1d71703c64b14b04d0 Mon Sep 17 00:00:00 2001 From: cimryan Date: Tue, 23 Oct 2018 22:38:34 -0700 Subject: [PATCH 29/45] More generic instructions for setting up file share. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ab60119..dc6690b 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,12 @@ Download and install: * [Etcher](http://etcher.io) ## Create your archive -### Hosting on Windows -Set up a share on a Windows (or macOS using Sharing, or Linux using Samba) machine to host the archive. These instructions assume that you created a share named "SailfishCam" on the server "Nautilus". It is recommended that you create a new user. Grant the user you'll be using read/write access to the share. These instructions will assume that the user you've created is named "sailfish" and that the password for this user is "pa$$w0rd". +### Hosting on Windows File Shares, MacOS Sharing, or Samba on Linux +Set up a share to host the archive. These instructions assume that you created a share named "SailfishCam" on the server "Nautilus". It is recommended that you create a new user. Grant the user you'll be using read/write access to the share. These instructions will assume that the user you've created is named "sailfish" and that the password for this user is "pa$$w0rd". -Get the IP address of the archive machine. You'll need this later, so write it down, somewhere. You can do this by opening a command prompt on the archive machine and typing ipconfig. Get the IP address from the line labeled "IPv4 Address". These instructions will assume that the IP address of the archive server is 192.168.0.41. +Get the IP address of the archive machine. You'll need this later, so write it down, somewhere. +* On Windows you can do this by opening a command prompt on the archive machine and typing ipconfig. Get the IP address from the line labeled "IPv4 Address". These instructions will assume that the IP address of the archive server is 192.168.0.41. +* On MacOS or Linux open a terminal and type ifconfig. ### Hosting via SFTP/rsync Since sftp/rsync is accessing a computer through SSH, the only requirement for hosting an SFTP/rsync server is to have a box running Linux. An example can be another Raspberry Pi connected to your local network with a USB storage drive plugged in. The official Raspberry Pi site has a good example on [how to mount an external drive](https://www.raspberrypi.org/documentation/configuration/external-storage.md). You will need the username and host/IP of the storage server, as well as the path for the files to go in, and the storage server will need to allow SSH. From bd53fe082283c991b3884d10422ed166923696ba Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 07:33:02 -0700 Subject: [PATCH 30/45] Closer to setup-teslausb being re-runnable. --- setup-teslausb | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/setup-teslausb b/setup-teslausb index 65e6fc5..bc73edd 100644 --- a/setup-teslausb +++ b/setup-teslausb @@ -73,7 +73,7 @@ function fix_cmdline_txt_modules_load () { echo "Fixing the modules-load parameter in /boot/cmdline.txt..." cp /boot/cmdline.txt ~ - cat ~/cmdline.txt | sed 's/[[:space:]]\+modules-load=[^ [:space:]]\+//' | sed 's/rootwait/rootwait modules-load=dwc2/' > /boot/cmdline.txt + cat ~/cmdline.txt | sed 's/ modules-load=dwc2,g_ether/ modules-load=dwc2/' > /boot/cmdline.txt rm ~/cmdline.txt echo "Fixed cmdline.txt." } @@ -81,19 +81,31 @@ function fix_cmdline_txt_modules_load () BACKINGFILES_MOUNTPOINT=/backingfiles function create_usb_drive_backing_files () { - mkdir "$BACKINGFILES_MOUNTPOINT" - /tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" + if [! -e "$BACKINGFILES_MOUNTPOINT" ] + then + mkdir "$BACKINGFILES_MOUNTPOINT" + fi - echo "Mounting the partition for the backing files..." - mount /backingfiles - echo "Mounted the partition for the backing files." + if [! -e /dev/mmcblk0p3 ] + then + /tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" + fi + + if ! findmnt --mountpoint /backingfiles + then + echo "Mounting the partition for the backing files..." + mount /backingfiles + echo "Mounted the partition for the backing files." + fi - /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" + if [! -e /backingfiles/* ] + then + /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" + fi } function configure_archive_scripts () { echo "Configuring the archive scripts..." - mkdir /root/bin pushd /root/bin wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/archiveloop @@ -138,8 +150,14 @@ function configure_pushover_scripts() { } function configure_rc_local () { + if grep -q archiveloop /etc/rc.local + then + return + fi + echo "Configuring /etc/rc.local to run the archive scripts at startup..." echo "#!/bin/bash -eu" > ~/rc.local + # Get everything but the last two lines tail -n +2 /etc/rc.local | sed '$d' >> ~/rc.local echo "archiveserver=\"${archiveserver}\"" >> ~/rc.local @@ -180,11 +198,13 @@ function make_root_fs_readonly () { echo "Verifying environment variables..." -if [ $RSYNC_ENABLE = true ] +RSYNC_ENABLE="${RSYNC_ENABLE:-false}" + +if [ "$RSYNC_ENABLE" = true ] then check_variable "RSYNC_USER" check_variable "RSYNC_SERVER" - export archiveserver=$RSYNC_SERVER + export archiveserver="$RSYNC_SERVER" check_variable "RSYNC_PATH" else # Else for now, TODO allow both for more redundancy? check_variable "sharename" @@ -199,8 +219,13 @@ check_variable "campercent" check_pushover_enabled +if [ ! -e /root/bin ] +then + mkdir /root/bin +fi + pushd /root/bin -if [ $RSYNC_ENABLE = true ] +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 From 8d8ecce249ed5c4d00c1cb11eb7cfa2ab997e957 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 07:40:01 -0700 Subject: [PATCH 31/45] Fix references to write-archive-credentials-to.sh --- cifs_archive/configure-archive.sh | 2 +- cifs_archive/verify-archive-configuration.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cifs_archive/configure-archive.sh b/cifs_archive/configure-archive.sh index 96638f7..eff994f 100644 --- a/cifs_archive/configure-archive.sh +++ b/cifs_archive/configure-archive.sh @@ -14,7 +14,7 @@ function configure_archive () { local credentials_file_path="/root/.teslaCamArchiveCredentials" - /root/bin/write_archive_credentials_to.sh "$credentials_file_path" + /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 diff --git a/cifs_archive/verify-archive-configuration.sh b/cifs_archive/verify-archive-configuration.sh index b64d9f0..614e88b 100644 --- a/cifs_archive/verify-archive-configuration.sh +++ b/cifs_archive/verify-archive-configuration.sh @@ -26,7 +26,7 @@ function check_archive_mountable () { local tmp_credentials_file_path="/tmp/teslaCamArchiveCredentials" - /root/bin/write_archive_credentials_to.sh "$tmp_credentials_file_path" + /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 d3c31cc83c611b71f85accef698d823e1c580694 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 18:00:17 -0700 Subject: [PATCH 32/45] Remove "local". --- cifs_archive/write-archive-credentials-to.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cifs_archive/write-archive-credentials-to.sh b/cifs_archive/write-archive-credentials-to.sh index c80ff38..edce256 100644 --- a/cifs_archive/write-archive-credentials-to.sh +++ b/cifs_archive/write-archive-credentials-to.sh @@ -1,6 +1,6 @@ #!/bin/bash -eu -local file_path="$1" +FILE_PATH="$1" -echo "username=$shareuser" > "$file_path" -echo "password=$sharepassword" >> "$file_path" +echo "username=$shareuser" > "$FILE_PATH" +echo "password=$sharepassword" >> "$FILE_PATH" From 2b7d15537268c5e5ac746bde355860ee8b698663 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 18:35:10 -0700 Subject: [PATCH 33/45] Overwrite local scripts with remote scripts. --- setup-teslausb | 86 ++++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 55 deletions(-) diff --git a/setup-teslausb b/setup-teslausb index bc73edd..39b3bf5 100644 --- a/setup-teslausb +++ b/setup-teslausb @@ -58,15 +58,19 @@ function check_available_space () { echo "There is sufficient space available." } +function get_script () { + local local_path="$1" + local name="$2" + local remote_path="${3:-}" + + wget -O "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" + chmod +x "$local_path/$name" +} + function get_ancillary_setup_scripts () { - pushd /tmp - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/create-backingfiles-partition.sh - chmod +x ./create-backingfiles-partition.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/create-backingfiles.sh - chmod +x ./create-backingfiles.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/make-root-fs-readonly.sh - chmod +x ./make-root-fs-readonly.sh - popd + get_script /tmp create-backingfiles-partition.sh + get_script /tmp create-backingfiles.sh + get_script /tmp make-root-fs-readonly.sh } function fix_cmdline_txt_modules_load () @@ -81,12 +85,12 @@ function fix_cmdline_txt_modules_load () BACKINGFILES_MOUNTPOINT=/backingfiles function create_usb_drive_backing_files () { - if [! -e "$BACKINGFILES_MOUNTPOINT" ] + if [ ! -e "$BACKINGFILES_MOUNTPOINT" ] then mkdir "$BACKINGFILES_MOUNTPOINT" fi - if [! -e /dev/mmcblk0p3 ] + if [ ! -e /dev/mmcblk0p3 ] then /tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" fi @@ -107,46 +111,27 @@ function create_usb_drive_backing_files () { function configure_archive_scripts () { echo "Configuring the archive scripts..." - pushd /root/bin - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/archiveloop - - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/archive-teslacam-clips + get_script /root/bin archiveloop + get_script /root/bin archive-teslacam-clips if [ $RSYNC_ENABLE = true ] then - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/archive-clips.sh - - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/connect-archive.sh - - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/rsync_archive/disconnect-archive.sh + get_script /root/bin archive-clips.sh rsync_archive + get_script /root/bin connect-archive.sh rsync_archive + get_script /root/bin disconnect-archive.sh rsync_archive else - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/archive-clips.sh - - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/connect-archive.sh - - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/disconnect-archive.sh + get_script /root/bin archive-clips.sh cifs_archive + get_script /root/bin connect-archive.sh cifs_archive + get_script /root/bin disconnect-archive.sh cifs_archive fi + + get_script /root/bin remountfs_rw - chmod +x archiveloop - chmod +x archive-teslacam-clips - chmod +x archive-clips.sh - chmod +x connect-archive.sh - chmod +x disconnect-archive.sh - - popd echo "Configured the archive scripts." - - pushd /root/bin - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/remountfs_rw - chmod +x remountfs_rw - popd } function configure_pushover_scripts() { - pushd /root/bin - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/send-pushover - chmod +x send-pushover - popd + get_script /root/bin send-pushover } function configure_rc_local () { @@ -224,26 +209,17 @@ then mkdir /root/bin fi -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 + get_script /root/bin verify-archive-configuration.sh rsync_archive + get_script /root/bin configure-archive.sh rsync_archive else - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/verify-archive-configuration.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/configure-archive.sh - - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/cifs_archive/write-archive-credentials-to.sh - chmod +x write-archive-credentials-to.sh + get_script /root/bin verify-archive-configuration.sh cifs_archive + get_script /root/bin configure-archive.sh cifs_archive + get_script /root/bin write-archive-credentials-to.sh cifs_archive fi -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 +get_script /root/bin get-archiveserver-ip-address.sh /root/bin/verify-archive-configuration.sh From cdcb9cd92018da639c532610961907715d29ddb3 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 19:07:46 -0700 Subject: [PATCH 34/45] Check for actual backing files before deciding whether or not to create them. --- setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-teslausb b/setup-teslausb index 39b3bf5..a48ada8 100644 --- a/setup-teslausb +++ b/setup-teslausb @@ -102,7 +102,7 @@ function create_usb_drive_backing_files () { echo "Mounted the partition for the backing files." fi - if [! -e /backingfiles/* ] + if [! -e /backingfiles/*.bin ] then /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" fi From b57d7690622c1973a93961d1f63108d685b4f399 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 19:18:38 -0700 Subject: [PATCH 35/45] Don't duplicate the content in rc.local. --- setup-teslausb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/setup-teslausb b/setup-teslausb index a48ada8..4d0cb87 100644 --- a/setup-teslausb +++ b/setup-teslausb @@ -142,9 +142,6 @@ function configure_rc_local () { echo "Configuring /etc/rc.local to run the archive scripts at startup..." echo "#!/bin/bash -eu" > ~/rc.local - # Get everything but the last two lines - tail -n +2 /etc/rc.local | sed '$d' >> ~/rc.local - echo "archiveserver=\"${archiveserver}\"" >> ~/rc.local cat << 'EOF' >> ~/rc.local LOGFILE=/tmp/rc.local.log @@ -160,7 +157,7 @@ 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." } From eb8f664bf53fa8ba110005cf91a5c7e81a7673ba Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 19:28:44 -0700 Subject: [PATCH 36/45] Fix negation in check for existing backing files. --- setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-teslausb b/setup-teslausb index 4d0cb87..8c0d6b1 100644 --- a/setup-teslausb +++ b/setup-teslausb @@ -102,7 +102,7 @@ function create_usb_drive_backing_files () { echo "Mounted the partition for the backing files." fi - if [! -e /backingfiles/*.bin ] + if [ ! -e /backingfiles/*.bin ] then /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" fi From 0fccd133fb5994b2d942bfd08d26725265d0eacc Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 19:47:45 -0700 Subject: [PATCH 37/45] Remove bogus local declaration in archive-clips.sh --- cifs_archive/archive-clips.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cifs_archive/archive-clips.sh b/cifs_archive/archive-clips.sh index ec3b4c0..e1b3a17 100644 --- a/cifs_archive/archive-clips.sh +++ b/cifs_archive/archive-clips.sh @@ -2,7 +2,7 @@ log "Moving clips to archive..." -local move_count=0 +move_count=0 for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do [ -e "$file_name" ] || continue From 8d2d6f9cb82682266452c34bc266467fddb46292 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 19:50:22 -0700 Subject: [PATCH 38/45] Use the right variable for the number of files moved. --- cifs_archive/archive-clips.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cifs_archive/archive-clips.sh b/cifs_archive/archive-clips.sh index e1b3a17..26b634f 100644 --- a/cifs_archive/archive-clips.sh +++ b/cifs_archive/archive-clips.sh @@ -2,17 +2,17 @@ log "Moving clips to archive..." -move_count=0 +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." - move_count=$((move_count + 1)) + NUM_FILES_MOVED=$((NUM_FILES_MOVED + 1)) done -log "Moved $move_count file(s)." +log "Moved $NUM_FILES_MOVED file(s)." -/root/bin/send-pushover "$num_files_moved" +/root/bin/send-pushover "$NUM_FILES_MOVED" log "Finished moving clips to archive." From 2915ca8e0143a4145b4fc401678c74f00db6aabf Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 19:55:56 -0700 Subject: [PATCH 39/45] Remove bogus local declaration in send-pushover --- send-pushover | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/send-pushover b/send-pushover index 442833e..3a6192a 100644 --- a/send-pushover +++ b/send-pushover @@ -1,13 +1,13 @@ #!/bin/bash -eu -local num_files_moved="$1" +NUM_FILES_MOVED="$1" function log () { echo "$( date )" >> "$LOG_FILE" echo "$1" >> "$LOG_FILE" } -if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $num_files_moved > 0] +if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $NUM_FILES_MOVED > 0] then log "Sending Pushover message for moved files." @@ -16,6 +16,6 @@ then curl -F "token=$pushover_app_key" \ -F "user=$pushover_user_key" \ -F "title=Dashcam Copy Complete" \ - -F "message=$num_files_moved file(s) were copied." \ + -F "message=$NUM_FILES_MOVED file(s) were copied." \ https://api.pushover.net/1/messages fi From 16db32e200376bd33a219b4b28cbde618da75359 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 20:18:56 -0700 Subject: [PATCH 40/45] Add an "experimental" disclaimer to rsync support until someone can test it. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dc6690b..8f8c5fa 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ Get the IP address of the archive machine. You'll need this later, so write it d * On MacOS or Linux open a terminal and type ifconfig. ### Hosting via SFTP/rsync +**EXPERIMENTAL - Hosting the archive on SFTP hasn't been thoroughly tested** + Since sftp/rsync is accessing a computer through SSH, the only requirement for hosting an SFTP/rsync server is to have a box running Linux. An example can be another Raspberry Pi connected to your local network with a USB storage drive plugged in. The official Raspberry Pi site has a good example on [how to mount an external drive](https://www.raspberrypi.org/documentation/configuration/external-storage.md). You will need the username and host/IP of the storage server, as well as the path for the files to go in, and the storage server will need to allow SSH. ### ***TODO: Other hosting solutions*** From ef10b2ec67967dfaee527f215e260a5053dc7ac7 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 20:44:14 -0700 Subject: [PATCH 41/45] Move setup-piForHeadlessConfigAddWifi.ps1 to windows_setup --- .../setup-piForHeadlessConfigAddWifi.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {windows_archive => windows_setup}/setup-piForHeadlessConfigAddWifi.ps1 (100%) diff --git a/windows_archive/setup-piForHeadlessConfigAddWifi.ps1 b/windows_setup/setup-piForHeadlessConfigAddWifi.ps1 similarity index 100% rename from windows_archive/setup-piForHeadlessConfigAddWifi.ps1 rename to windows_setup/setup-piForHeadlessConfigAddWifi.ps1 From e875763e58188c2d383b3507a35ad9e462125f1f Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 20:55:29 -0700 Subject: [PATCH 42/45] Separate files into those used for setup and those used at runtime. Files used for both will go in the run tree. --- .../ConfigureNotificationsForArchive.md | 0 .../GetShellWithoutMonitorOnLinux.md | 0 .../GetShellWithoutMonitorOnWindows.md | 0 SetupRSync.md => doc/SetupRSync.md | 0 archive-teslacam-clips => run/archive-teslacam-clips | 0 archiveloop => run/archiveloop | 0 {cifs_archive => run/cifs_archive}/archive-clips.sh | 0 {cifs_archive => run/cifs_archive}/configure-archive.sh | 0 {cifs_archive => run/cifs_archive}/connect-archive.sh | 0 {cifs_archive => run/cifs_archive}/disconnect-archive.sh | 0 .../cifs_archive}/verify-archive-configuration.sh | 0 .../cifs_archive}/write-archive-credentials-to.sh | 0 .../get-archiveserver-ip-address.sh | 0 remountfs_rw => run/remountfs_rw | 0 {rsync_archive => run/rsync_archive}/archive-clips.sh | 0 {rsync_archive => run/rsync_archive}/configure-archive.sh | 0 {rsync_archive => run/rsync_archive}/connect-archive.sh | 0 {rsync_archive => run/rsync_archive}/disconnect-archive.sh | 0 .../rsync_archive}/verify-archive-configuration.sh | 0 send-pushover => run/send-pushover | 0 .../macos_linux/setup-piForHeadlessConfig.sh | 0 .../pi/create-backingfiles-partition.sh | 0 create-backingfiles.sh => setup/pi/create-backingfiles.sh | 0 make-root-fs-readonly.sh => setup/pi/make-root-fs-readonly.sh | 0 setup-teslausb => setup/pi/setup-teslausb | 0 .../windows/setup-piForHeadlessConfig.ps1 | 0 .../windows}/setup-piForHeadlessConfigAddWifi.ps1 | 0 27 files changed, 0 insertions(+), 0 deletions(-) rename ConfigureNotificationsForArchive.md => doc/ConfigureNotificationsForArchive.md (100%) rename GetShellWithoutMonitorOnLinux.md => doc/GetShellWithoutMonitorOnLinux.md (100%) rename GetShellWithoutMonitorOnWindows.md => doc/GetShellWithoutMonitorOnWindows.md (100%) rename SetupRSync.md => doc/SetupRSync.md (100%) rename archive-teslacam-clips => run/archive-teslacam-clips (100%) rename archiveloop => run/archiveloop (100%) rename {cifs_archive => run/cifs_archive}/archive-clips.sh (100%) rename {cifs_archive => run/cifs_archive}/configure-archive.sh (100%) rename {cifs_archive => run/cifs_archive}/connect-archive.sh (100%) rename {cifs_archive => run/cifs_archive}/disconnect-archive.sh (100%) rename {cifs_archive => run/cifs_archive}/verify-archive-configuration.sh (100%) rename {cifs_archive => run/cifs_archive}/write-archive-credentials-to.sh (100%) rename get-archiveserver-ip-address.sh => run/get-archiveserver-ip-address.sh (100%) rename remountfs_rw => run/remountfs_rw (100%) rename {rsync_archive => run/rsync_archive}/archive-clips.sh (100%) rename {rsync_archive => run/rsync_archive}/configure-archive.sh (100%) rename {rsync_archive => run/rsync_archive}/connect-archive.sh (100%) rename {rsync_archive => run/rsync_archive}/disconnect-archive.sh (100%) rename {rsync_archive => run/rsync_archive}/verify-archive-configuration.sh (100%) rename send-pushover => run/send-pushover (100%) rename setup-piForHeadlessConfig.sh => setup/macos_linux/setup-piForHeadlessConfig.sh (100%) rename create-backingfiles-partition.sh => setup/pi/create-backingfiles-partition.sh (100%) rename create-backingfiles.sh => setup/pi/create-backingfiles.sh (100%) rename make-root-fs-readonly.sh => setup/pi/make-root-fs-readonly.sh (100%) rename setup-teslausb => setup/pi/setup-teslausb (100%) rename setup-piForHeadlessConfig.ps1 => setup/windows/setup-piForHeadlessConfig.ps1 (100%) rename {windows_setup => setup/windows}/setup-piForHeadlessConfigAddWifi.ps1 (100%) diff --git a/ConfigureNotificationsForArchive.md b/doc/ConfigureNotificationsForArchive.md similarity index 100% rename from ConfigureNotificationsForArchive.md rename to doc/ConfigureNotificationsForArchive.md diff --git a/GetShellWithoutMonitorOnLinux.md b/doc/GetShellWithoutMonitorOnLinux.md similarity index 100% rename from GetShellWithoutMonitorOnLinux.md rename to doc/GetShellWithoutMonitorOnLinux.md diff --git a/GetShellWithoutMonitorOnWindows.md b/doc/GetShellWithoutMonitorOnWindows.md similarity index 100% rename from GetShellWithoutMonitorOnWindows.md rename to doc/GetShellWithoutMonitorOnWindows.md diff --git a/SetupRSync.md b/doc/SetupRSync.md similarity index 100% rename from SetupRSync.md rename to doc/SetupRSync.md diff --git a/archive-teslacam-clips b/run/archive-teslacam-clips similarity index 100% rename from archive-teslacam-clips rename to run/archive-teslacam-clips diff --git a/archiveloop b/run/archiveloop similarity index 100% rename from archiveloop rename to run/archiveloop diff --git a/cifs_archive/archive-clips.sh b/run/cifs_archive/archive-clips.sh similarity index 100% rename from cifs_archive/archive-clips.sh rename to run/cifs_archive/archive-clips.sh diff --git a/cifs_archive/configure-archive.sh b/run/cifs_archive/configure-archive.sh similarity index 100% rename from cifs_archive/configure-archive.sh rename to run/cifs_archive/configure-archive.sh diff --git a/cifs_archive/connect-archive.sh b/run/cifs_archive/connect-archive.sh similarity index 100% rename from cifs_archive/connect-archive.sh rename to run/cifs_archive/connect-archive.sh diff --git a/cifs_archive/disconnect-archive.sh b/run/cifs_archive/disconnect-archive.sh similarity index 100% rename from cifs_archive/disconnect-archive.sh rename to run/cifs_archive/disconnect-archive.sh diff --git a/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh similarity index 100% rename from cifs_archive/verify-archive-configuration.sh rename to run/cifs_archive/verify-archive-configuration.sh diff --git a/cifs_archive/write-archive-credentials-to.sh b/run/cifs_archive/write-archive-credentials-to.sh similarity index 100% rename from cifs_archive/write-archive-credentials-to.sh rename to run/cifs_archive/write-archive-credentials-to.sh diff --git a/get-archiveserver-ip-address.sh b/run/get-archiveserver-ip-address.sh similarity index 100% rename from get-archiveserver-ip-address.sh rename to run/get-archiveserver-ip-address.sh diff --git a/remountfs_rw b/run/remountfs_rw similarity index 100% rename from remountfs_rw rename to run/remountfs_rw diff --git a/rsync_archive/archive-clips.sh b/run/rsync_archive/archive-clips.sh similarity index 100% rename from rsync_archive/archive-clips.sh rename to run/rsync_archive/archive-clips.sh diff --git a/rsync_archive/configure-archive.sh b/run/rsync_archive/configure-archive.sh similarity index 100% rename from rsync_archive/configure-archive.sh rename to run/rsync_archive/configure-archive.sh diff --git a/rsync_archive/connect-archive.sh b/run/rsync_archive/connect-archive.sh similarity index 100% rename from rsync_archive/connect-archive.sh rename to run/rsync_archive/connect-archive.sh diff --git a/rsync_archive/disconnect-archive.sh b/run/rsync_archive/disconnect-archive.sh similarity index 100% rename from rsync_archive/disconnect-archive.sh rename to run/rsync_archive/disconnect-archive.sh diff --git a/rsync_archive/verify-archive-configuration.sh b/run/rsync_archive/verify-archive-configuration.sh similarity index 100% rename from rsync_archive/verify-archive-configuration.sh rename to run/rsync_archive/verify-archive-configuration.sh diff --git a/send-pushover b/run/send-pushover similarity index 100% rename from send-pushover rename to run/send-pushover diff --git a/setup-piForHeadlessConfig.sh b/setup/macos_linux/setup-piForHeadlessConfig.sh similarity index 100% rename from setup-piForHeadlessConfig.sh rename to setup/macos_linux/setup-piForHeadlessConfig.sh diff --git a/create-backingfiles-partition.sh b/setup/pi/create-backingfiles-partition.sh similarity index 100% rename from create-backingfiles-partition.sh rename to setup/pi/create-backingfiles-partition.sh diff --git a/create-backingfiles.sh b/setup/pi/create-backingfiles.sh similarity index 100% rename from create-backingfiles.sh rename to setup/pi/create-backingfiles.sh diff --git a/make-root-fs-readonly.sh b/setup/pi/make-root-fs-readonly.sh similarity index 100% rename from make-root-fs-readonly.sh rename to setup/pi/make-root-fs-readonly.sh diff --git a/setup-teslausb b/setup/pi/setup-teslausb similarity index 100% rename from setup-teslausb rename to setup/pi/setup-teslausb diff --git a/setup-piForHeadlessConfig.ps1 b/setup/windows/setup-piForHeadlessConfig.ps1 similarity index 100% rename from setup-piForHeadlessConfig.ps1 rename to setup/windows/setup-piForHeadlessConfig.ps1 diff --git a/windows_setup/setup-piForHeadlessConfigAddWifi.ps1 b/setup/windows/setup-piForHeadlessConfigAddWifi.ps1 similarity index 100% rename from windows_setup/setup-piForHeadlessConfigAddWifi.ps1 rename to setup/windows/setup-piForHeadlessConfigAddWifi.ps1 From 5db24b3af04222ed92b24997d1a30f2fa9390760 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 21:19:16 -0700 Subject: [PATCH 43/45] Fix references to file locations, and simplify llinux/macos instructions. --- README.md | 10 +++--- doc/GetShellWithoutMonitorOnLinux.md | 42 +++++++++++--------------- doc/GetShellWithoutMonitorOnWindows.md | 2 +- setup/pi/setup-teslausb | 38 +++++++++++------------ 4 files changed, 42 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 8f8c5fa..fa902c4 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,9 @@ There are three phases to setting up the Pi: > Note: you don't need to uncompress the zip file you downloaded. ### Get a shell on the Pi -If you used a Windows computer to flash the OS onto the MicroSD card, follow these [Instructions](GetShellWithoutMonitorOnWindows.md). +If you used a Windows computer to flash the OS onto the MicroSD card, follow these [Instructions](doc/GetShellWithoutMonitorOnWindows.md). -If you used a Mac or a Linux computer, follow these [Instructions](GetShellWithoutMonitorOnLinux.md). +If you used a Mac or a Linux computer, follow these [Instructions](doc/GetShellWithoutMonitorOnLinux.md). ### Set up the USB storage functionality @@ -104,7 +104,7 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s export campercent= ``` For example, using `export campercent=100` would allocate 100% of the space to recording footage from your car, and would not create a separate music partition. `export campercent=50` would be only allocate half of the space for a dashcam footage drive, and allocates the other half to be a music storage drive. -1. If you are trying to archive on an SFTP/rsync server, then follow these [instructions](SetupRSync.md) and skip step 7. Otherwise, skip this step. +1. If you are trying to archive on an SFTP/rsync server, then follow these [instructions](doc/SetupRSync.md) and skip step 7. Otherwise, skip this step. 1. If you are trying to archive on a shared drive, run these commands, subsituting your values for your shared drive: ``` export archiveserver=Nautilus @@ -112,10 +112,10 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s export shareuser=sailfish export sharepassword=pa$$w0rd ``` -1. If you'd like to receive a text message when your Pi finishes archiving clips follow these [Instructions](ConfigureNotificationsForArchive.md). +1. If you'd like to receive a text message when your Pi finishes archiving clips follow these [Instructions](doc/ConfigureNotificationsForArchive.md). 1. Run these commands: ``` - wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup-teslausb + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/pi/setup-teslausb chmod +x setup-teslausb ./setup-teslausb ``` diff --git a/doc/GetShellWithoutMonitorOnLinux.md b/doc/GetShellWithoutMonitorOnLinux.md index 2013114..2439691 100644 --- a/doc/GetShellWithoutMonitorOnLinux.md +++ b/doc/GetShellWithoutMonitorOnLinux.md @@ -1,43 +1,35 @@ -# Setting up the Pi without a monitor using a Mac or Linux +# Getting a shell on the Pi without a monitor using a Mac or Linux -You can setup the Pi to connect to your Wifi network, and also provide the option to connect over USB networking (Rasberry Pi Zero W or other recent Pi's). +These instructions will configure a Raspberry Pi so that you can proceed with the next step of setting it up as a smart USB drive for your Tesla. Specifically, these intructions will configure your Pi to join your wireless network and also enable you to ssh to the Pi, either over your wireless network or through a USB connection. - -**What is USB networking?** -Basically what you're doing is using the Pi's capability to emulate a network connection over USB. So you need to get the Pi (the guest) set up to load the proper modules to do so, and then connect from your machine (the host) using a shell (like iTerm+SSH on macOS). It's an alternative to Wifi if needed. - -## Use the update script to setup Wifi and USB networking - -A [script](https://raw.githubusercontent.com/cimryan/teslausb/master/mac_linux_archive/setup-piForHeadlessConfig.sh is provided to automatically update your SD card so the first time you boot it on your Pi, USB networking and Wifi will automatically be configured. - -If you prefer not to run the script, it's also a useful reference for the steps you'll need to take. - -> It's important you do these steps **before you boot the Pi the first time with the SD card inserted**. +**Important:** Do these steps before you boot the Pi for the first time. 1. Ensure you've flashed your Raspbian image to your SD card. 1. If the `boot` folder isn't showing on your computer, eject and re-insert the SD card into your computer, **not the Raspberry Pi**. -1. Change to the directory where the SD card's `boot` folder (containing `cmdline.txt`) is located. On a Mac, this will be `/Volumes/boot`. On Linux the location may vary. +1. Change to the directory where the SD card's `boot` folder (containing `cmdline.txt`) is located. On a Mac, this will be `/Volumes/boot`. On Linux the location may vary; on recent Ubuntu installations it will be /media/$USER/boot 1. Run the following commands: ``` - wget https://raw.githubusercontent.com/cimryan/teslausb/master/mac_linux_archive/setup-piForHeadlessConfig.sh + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/macos_linux/setup-piForHeadlessConfig.sh chmod +x setup-piForHeadlessConfig.sh ``` 1. Set your SSID (Wifi network name) and WIFIPASS environment variables. The script will insert them into the `wpa_supplicant.conf` when creating it: - ``` export SSID=your_ssid_here export WIFIPASS=your_wifi_password_here ``` -1. Run the script: - `./setup-piForHeadlessConfig.sh` +1. If you're using a Mac, run this command + ``` + ./setup-piForHeadlessConfig.sh /Volumes/boot + ``` +1. If you're using Ubuntu, run this command: + ``` + ./setup-piForHeadlessConfig.sh /media/$USER/boot + ``` + > If you're using another Linux distribution figure out the path to where the boot partitio of the SD card is mounted and specify that path, instead. 1. If all goes well, the script will report: - `-- Files updated and ready for Wifi and SSH over USB --` + ``` + -- Files updated and ready for Wifi and SSH over USB -- + ``` 1. Eject the SD card safely, insert into your Pi, and reboot. If the Pi is connected over USB to your host, and/or if the Wifi setup went correctly, you should be able to `ssh pi@raspberrypi.local`. The default password is `raspberry`. > Note: If you receive an error indicating that the host id has changed, edit your computer's `~/.ssh/known_hosts` file. Find the line with the IP address of your Pi, or labeled "raspberrypi.local" and delete the entire line. You're especially likely to encounter this error if you're following these instructions for a second time. - -## Manual/other resources - -* [Gist (text file) showing example steps to setup USB networking](https://gist.github.com/gbaman/975e2db164b3ca2b51ae11e45e8fd40a) - -If manually configuring the Pi vs using the update script, be sure to delete the `init=/usr/lib/raspi-config/init_resize.sh` parameter from cmdline.txt to prevent the os partition from being expanded to fill the drive. diff --git a/doc/GetShellWithoutMonitorOnWindows.md b/doc/GetShellWithoutMonitorOnWindows.md index 205c0b2..83aa360 100644 --- a/doc/GetShellWithoutMonitorOnWindows.md +++ b/doc/GetShellWithoutMonitorOnWindows.md @@ -14,7 +14,7 @@ 1. Run the following commands: ``` cd ~ - wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup-piForHeadlessConfig.ps1 -OutFile setup-piForHeadlessConfig.ps1 + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/windows/setup-piForHeadlessConfig.ps1 -OutFile setup-piForHeadlessConfig.ps1 ./setup-piForHeadlessConfig.ps1 -Verbose ``` 1. Enter the single letter of the "boot" drive and press Enter. diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 8c0d6b1..abf884a 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -68,9 +68,9 @@ function get_script () { } function get_ancillary_setup_scripts () { - get_script /tmp create-backingfiles-partition.sh - get_script /tmp create-backingfiles.sh - get_script /tmp make-root-fs-readonly.sh + 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 } function fix_cmdline_txt_modules_load () @@ -111,27 +111,27 @@ function create_usb_drive_backing_files () { function configure_archive_scripts () { echo "Configuring the archive scripts..." - get_script /root/bin archiveloop - get_script /root/bin archive-teslacam-clips + get_script /root/bin archiveloop run + get_script /root/bin archive-teslacam-clips run if [ $RSYNC_ENABLE = true ] then - get_script /root/bin archive-clips.sh rsync_archive - get_script /root/bin connect-archive.sh rsync_archive - get_script /root/bin disconnect-archive.sh rsync_archive + 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 else - get_script /root/bin archive-clips.sh cifs_archive - get_script /root/bin connect-archive.sh cifs_archive - get_script /root/bin disconnect-archive.sh cifs_archive + 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 + get_script /root/bin remountfs_rw run echo "Configured the archive scripts." } function configure_pushover_scripts() { - get_script /root/bin send-pushover + get_script /root/bin send-pushover run } function configure_rc_local () { @@ -208,15 +208,15 @@ fi if [ "$RSYNC_ENABLE" = true ] then - get_script /root/bin verify-archive-configuration.sh rsync_archive - get_script /root/bin configure-archive.sh rsync_archive + get_script /root/bin verify-archive-configuration.sh run/rsync_archive + get_script /root/bin configure-archive.sh run/rsync_archive else - get_script /root/bin verify-archive-configuration.sh cifs_archive - get_script /root/bin configure-archive.sh cifs_archive - get_script /root/bin write-archive-credentials-to.sh cifs_archive + 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 -get_script /root/bin get-archiveserver-ip-address.sh +get_script /root/bin get-archiveserver-ip-address.sh run /root/bin/verify-archive-configuration.sh From 27ed80059b1da48bb7af1fe4425ac76e44e3775d Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 21:20:35 -0700 Subject: [PATCH 44/45] Rename setup-piForHeadlessConfigAddWifi --- .../{setup-piForHeadlessConfigAddWifi.ps1 => add-wifi.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename setup/windows/{setup-piForHeadlessConfigAddWifi.ps1 => add-wifi.ps1} (100%) diff --git a/setup/windows/setup-piForHeadlessConfigAddWifi.ps1 b/setup/windows/add-wifi.ps1 similarity index 100% rename from setup/windows/setup-piForHeadlessConfigAddWifi.ps1 rename to setup/windows/add-wifi.ps1 From c607860052210dcfe24b0e326504f5666b685b0b Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 22:33:51 -0700 Subject: [PATCH 45/45] Extract common functionality to WpaSupplicantConf.psm1 --- doc/GetShellWithoutMonitorOnWindows.md | 1 + setup/windows/WpaSupplicantConf.psm1 | 91 +++++++++++++++++++++ setup/windows/add-wifi.ps1 | 17 +--- setup/windows/setup-piForHeadlessConfig.ps1 | 25 +----- 4 files changed, 98 insertions(+), 36 deletions(-) create mode 100644 setup/windows/WpaSupplicantConf.psm1 diff --git a/doc/GetShellWithoutMonitorOnWindows.md b/doc/GetShellWithoutMonitorOnWindows.md index 83aa360..0142aeb 100644 --- a/doc/GetShellWithoutMonitorOnWindows.md +++ b/doc/GetShellWithoutMonitorOnWindows.md @@ -15,6 +15,7 @@ ``` cd ~ wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/windows/setup-piForHeadlessConfig.ps1 -OutFile setup-piForHeadlessConfig.ps1 + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/windows/WpaSupplicantConf.psm1 -OutFile WpaSupplicantConf.psm1 ./setup-piForHeadlessConfig.ps1 -Verbose ``` 1. Enter the single letter of the "boot" drive and press Enter. diff --git a/setup/windows/WpaSupplicantConf.psm1 b/setup/windows/WpaSupplicantConf.psm1 new file mode 100644 index 0000000..93b9f7a --- /dev/null +++ b/setup/windows/WpaSupplicantConf.psm1 @@ -0,0 +1,91 @@ +function Write-Header { +param( + [string]$driveLetter + ) +$header=@" +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev +update_config=1 +"@ + + Set-WpaSupplicantConfContent "$driveLetter" "$header" +} + +function Add-Network { +param( + [string]$driveLetter, + [string]$wifiSSID, + [string]$wifiPSK + ) + + $network=@" + + +network={ + ssid="$wifiSSID" + psk="$wifiPSK" +} +"@ + + Add-WpaSupplicantConfContent "$driveLetter" "$network" +} + +function Set-WpaSupplicantConfContent { +param( + [string]$driveLetter, + [string]$content + ) + + $wpaSupplicantConfPath = Get-WpaSupplicantConfPath $driveLetter + $encodedContent = Encode-Content $content + Set-Content -Value $encodedContent -Encoding Byte -Path "$wpaSupplicantConfPath" +} + +function Add-WpaSupplicantConfContent { +param( + [string]$driveLetter, + [string]$content + ) + + $wpaSupplicantConfPath = Get-WpaSupplicantConfPath $driveLetter + $encodedContent = Encode-Content $content + Add-Content -Value $encodedContent -Encoding Byte -Path "$wpaSupplicantConfPath" +} + +function Verify-WpaSupplicantConfPath { +param( + [string]$driveLetter + ) + + $drivePath="${driveLetter}:" + $configPath = "$drivePath\config.txt" + $cmdlinePath = "$drivePath\cmdline.txt" + $sshPath = "$drivePath\ssh" + + if ((![System.IO.File]::Exists($configPath) -or + (![System.IO.File]::Exists($cmdlinePath)))) { + Write-Error "Didn't find cmdline.txt and config.txt on drive $drivePath." + exit 1 + } +} + +function Encode-Content { +param( + [string]$content + ) + $utf8 = New-Object System.Text.UTF8Encoding $false + + return $utf8.GetBytes($content) +} + +function Get-WpaSupplicantConfPath { +param( + [string]$driveLetter + ) + + Verify-WpaSupplicantConfPath $driveLetter + + return "${driveLetter}:\wpa_supplicant.conf" +} + +Export-ModuleMember -Function Write-Header +Export-ModuleMember -Function Add-Network \ No newline at end of file diff --git a/setup/windows/add-wifi.ps1 b/setup/windows/add-wifi.ps1 index ef2d69f..cd1b06e 100644 --- a/setup/windows/add-wifi.ps1 +++ b/setup/windows/add-wifi.ps1 @@ -11,21 +11,8 @@ Param [string]$wifiPSK ) -$drivePath="${driveLetter}:" +Import-Module -Name ".\WpaSupplicantConf.psm1" -Force -$wpaSupplicantConfPath="$drivePath\wpa_supplicant.conf" - -$wpaSupplicantConfContent=@" - - -network={ - ssid="$wifiSSID" - psk="$wifiPSK" -} -"@ - -$utf8 = New-Object System.Text.UTF8Encoding $false - -Add-Content -Value $utf8.GetBytes($wpaSupplicantConfContent) -Encoding Byte -Path "$wpaSupplicantConfPath" +Add-Network "$driveLetter" "$wifiSSID" "$wifiPSK" Write-Verbose "All done." diff --git a/setup/windows/setup-piForHeadlessConfig.ps1 b/setup/windows/setup-piForHeadlessConfig.ps1 index d2a1eea..a2a802c 100644 --- a/setup/windows/setup-piForHeadlessConfig.ps1 +++ b/setup/windows/setup-piForHeadlessConfig.ps1 @@ -11,6 +11,8 @@ Param [string]$wifiPSK ) +Import-Module -Name ".\WpaSupplicantConf.psm1" -Force + $drivePath="${driveLetter}:" $configPath = "$drivePath\config.txt" $cmdlinePath = "$drivePath\cmdline.txt" @@ -34,28 +36,9 @@ $cmdlinetxtContent.Replace("rootwait", "rootwait modules-load=dwc2,g_ether").Rep Write-Verbose "Enabling SSH ..." [System.IO.File]::CreateText($sshPath).Dispose() -# Sets up wifi credentials so wifi will be -# auto configured on first boot - -$wpaSupplicantConfPath="$drivePath\wpa_supplicant.conf" - Write-Verbose "(Re)creating WiFi configuration file $wpaSupplicantConfPath." -if ([System.IO.File]::Exists("$wpaSupplicantConfPath")) { - del "$wpaSupplicantConfPath" -} -$wpaSupplicantConfContent=@" -ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev -update_config=1 - -network={ - ssid="$wifiSSID" - psk="$wifiPSK" -} -"@ - -$utf8 = New-Object System.Text.UTF8Encoding $false - -Set-Content -Value $utf8.GetBytes($wpaSupplicantConfContent) -Encoding Byte -Path "$wpaSupplicantConfPath" +Write-Header "$driveLetter" +Add-Network "$driveLetter" "$wifiSSID" "$wifiPSK" Write-Verbose "All done." \ No newline at end of file