From 1d5d2d1641cbab9831af816f2ed8f36d6bef6d69 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 20 Oct 2018 11:58:10 -0500 Subject: [PATCH 01/67] Putting files in place for wget test --- headless-scripts/setup-piForHeadlessBuild.sh | 180 +++++++++++++++ headless-scripts/setup-teslausb-headless | 226 +++++++++++++++++++ 2 files changed, 406 insertions(+) create mode 100755 headless-scripts/setup-piForHeadlessBuild.sh create mode 100644 headless-scripts/setup-teslausb-headless diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh new file mode 100755 index 0000000..2b5491a --- /dev/null +++ b/headless-scripts/setup-piForHeadlessBuild.sh @@ -0,0 +1,180 @@ +#/bin/bash -eu + +# This script will modify the cmdline.txt file on a freshly flashed Raspbian Stretch/Lite +# It readies it for SSH, USB OTG, USB networking, and Wifi +# +# Pass it the path to the location at which the "boot" filesystem is mounted. +# E.g. on a Mac: +# ./setup-piForHeadlessConfig.sh /Volumes/boot +# or on Ubuntu: +# ./setup-piForHeadlessConfig.sh /media/$USER/boot +# cd /Volumes/boot (or wherever the boot folder is mounted) +# chmod +x setup-piForHeadlessConfig.sh +# ./setup-piForHeadlessConfig.sh +# +# Put the card in your Pi, and reboot! + +# Creates the ssh file if needed, since Raspbian now disables +# ssh by default if the file isn't present + +BOOT_DIR="$1" +RED='\033[0;31m' # Red for warning +NC='\033[0m' # No Color +GREEN='\033[0;32m' + +function stop_message () { + echo -e "${RED}${1} ${NC}" +} + +function good_message () { + echo -e "${GREEN}${1} ${NC}" +} + +function show_setup_var_instructions () { + + stop_message 'STOP: You need to specify your setup variables first. Create the file "teslausb_setup_variables.conf" with: ' + echo "" + echo ' export archiveserver=Nautilus' + echo ' export sharename=SailfishCam' + echo ' export shareuser=sailfish' + echo ' export sharepassword=pa$$w0rd' + echo ' export campercent=100' + echo "" + echo "Be sure to replace the values with your relevant choices." + exit 1 + +} + +function verify_file_exists () { + local file_name="$1" + local expected_path="$2" + + if [ ! -e "$expected_path/$file_name" ] + then + stop_message "STOP: Didn't find $file_name at $expected_path." + exit 1 + fi +} + +function verify_wifi_variables () { + if [ ! -n "${SSID+x}" ] || [ ! -n "${WIFIPASS+x}" ] + then + stop_message 'STOP: You need to specify your wifi name and password first. Run: ' + echo "" + echo ' export SSID=your_ssid' + echo ' export WIFIPASS=your_wifi_password' + echo "" + echo "Be sure to replace the values with your SSID (network name) and password." + exit 1 + fi +} + +function verify_setup_variables_file_exists () { + local file_name="$1" + local expected_path="$2" + + if [ ! -e "$expected_path/$file_name" ] + then + show_setup_var_instructions + exit 1 + fi +} + +function verify_setup_variables () { + if [ ! -n "${archiveserver+x}" ] + then + show_setup_var_instructions + fi +} + +function verify_pushover_variables () { + if [ ! -z "${pushover_enabled+x}" ] + then + if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] + then + stop_message "STOP: You're trying to setup Pushover but didn't provide your User and/or App key." + echo 'Define the variables in "teslausb_setup_variables.conf" like this:' + echo "" + echo " export pushover_user_key=put_your_userkey_here" + echo " export pushover_app_key=put_your_appkey_here" + exit 1 + elif [ "${pushover_user_key}" = "put_your_userkey_here" ] || [ "${pushover_app_key}" = "put_your_appkey_here" ] + then + stop_message "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." + echo 'Replace the default values in "teslausb_setup_variables.conf".' + exit 1 + else + user_enabled_pushover=true + echo "export pushover_enabled=true" > $BOOT_DIR/.teslaCamPushoverCredentials + echo "export pushover_user_key=$pushover_user_key" >> $BOOT_DIR/.teslaCamPushoverCredentials + echo "export pushover_app_key=$pushover_app_key" >> $BOOT_DIR/.teslaCamPushoverCredentials + fi + fi +} + + +verify_file_exists "cmdline.txt" "$BOOT_DIR" +verify_file_exists "config.txt" "$BOOT_DIR" +verify_setup_variables_file_exists "teslausb_setup_variables.conf" "$BOOT_DIR" + +source "$BOOT_DIR"/teslausb_setup_variables.conf + +verify_wifi_variables +verify_setup_variables +verify_pushover_variables + +CMDLINE_TXT_PATH="$BOOT_DIR/cmdline.txt" +CONFIG_TXT_PATH="$BOOT_DIR/config.txt" + +if ! grep -q "dtoverlay=dwc2" $CONFIG_TXT_PATH +then + echo "Updating $CONFIG_TXT_PATH ..." + echo "" >> "$CONFIG_TXT_PATH" + echo "dtoverlay=dwc2" >> "$CONFIG_TXT_PATH" +else + good_message "config.txt already contains the required dwc2 module" +fi + +if ! grep -q "dwc2,g_ether" $CMDLINE_TXT_PATH +then + echo "Updating $CMDLINE_TXT_PATH ..." + sed -i'.bak' -e "s/rootwait/rootwait modules-load=dwc2,g_ether/" -e "s@ init=/usr/lib/raspi-config/init_resize.sh@@" "$CMDLINE_TXT_PATH" +else + good_message "cmdline.txt already updated with modules and removed initial resize script." +fi + +if [ ! -e "$BOOT_DIR/ssh" ] +then + good_message "Ensuring SSH is setup..." + touch "$BOOT_DIR/ssh" +fi + +# Sets up wifi credentials so wifi will be +# auto configured on first boot + +WPA_SUPPLICANT_CONF_PATH="$BOOT_DIR/wpa_supplicant.conf" + +good_message "Adding Wifi setup file (wpa_supplicant.conf)." +if [ -r "$WPA_SUPPLICANT_CONF_PATH" ] +then + rm "$WPA_SUPPLICANT_CONF_PATH" +fi + +cat << EOF >> "$WPA_SUPPLICANT_CONF_PATH" +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev +update_config=1 + +network={ + ssid="$SSID" + psk="$WIFIPASS" + key_mgmt=WPA-PSK +} +EOF + +echo "" +good_message '-- Files updated and ready for headless setup --' +echo '' +good_message '-- You can now insert your SD card into the Pi for headless setup' +echo '' +echo "When done (this may take a vew minutes), the Pi should be available over SSH as pi@teslausb.local" +echo "" diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless new file mode 100644 index 0000000..23eefcd --- /dev/null +++ b/headless-scripts/setup-teslausb-headless @@ -0,0 +1,226 @@ +#!/bin/bash -eu + +REPO=rtgoodwin +BRANCH="headless-patch" +user_enabled_pushover=false +LOGFIlE=/boot/teslausb-headless-setup.log +setup_complete=false + +# if ! [ $(id -u) = 0 ] +# then +# echo "STOP: Run sudo -i." +# exit 1 +# fi + +function setup_log () { + echo "$( date )" >> "$LOGFILE" + echo "$1" >> "$LOGFILE" +} + +if [ ! -e /boot/TESLAUSB_SETUP_FINISHED ] +then + setup_log "Setting up teslausb functionality" + touch /boot/TESLA_USB_SETUP_STARTED +fi + +function mark_setup_failed () { + + +} + +function check_variable () { + local var_name="$1" + if [ -z "${!var_name+x}" ] + then + echo "STOP: Define the variable $var_name like this: export $var_name=value" + setup_log "SETUP FAILED: Define the variable $var_name as export $var_name=value in /boot/teslausb_setup_variables" + exit 1 + 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 check_available_space () { + echo "Verifying that there is sufficient space available on the MicroSD card..." + + local available_space="$( parted -m /dev/mmcblk0 u b print free | tail -1 | cut -d ":" -f 4 | sed 's/B//g' )" + + if [ "$available_space" -lt 4294967296 ] + then + echo "STOP: The MicroSD card is too small." + exit 1 + fi + + echo "There is sufficient space available." +} + +function get_ancillary_setup_scripts () { + pushd /tmp + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh + chmod +x ./create-backingfiles-partition.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh + chmod +x ./create-backingfiles.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh + chmod +x ./make-root-fs-readonly.sh + popd +} + +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 + rm ~/cmdline.txt + echo "Fixed cmdline.txt." +} + +BACKINGFILES_MOUNTPOINT=/backingfiles + +function create_usb_drive_backing_files () { + mkdir "$BACKINGFILES_MOUNTPOINT" + /tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" + + echo "Mounting the partition for the backing files..." + mount /backingfiles + echo "Mounted the partition for the backing files." + + /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" +} + +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 + + echo "username=$shareuser" > /root/.teslaCamArchiveCredentials + echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials + echo "Configured the archive." +} + +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/archive-teslacam-clips + chmod +x archive-teslacam-clips + popd + echo "Configured the archive scripts." + + pushd /root + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw + chmod +x remountfs_rw + popd + echo "Downloaded script to remount filesystems read/write if needed (/root/remountfs_rw)." +} + + +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 () { + 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 +cat << 'EOF' >> ~/rc.local +LOGFILE=/tmp/rc.local.log + +function log () { + echo "$( date )" >> "$LOGFILE" + echo "$1" >> "$LOGFILE" +} + +log "Launching archival script..." +/root/bin/archiveloop & +log "All done" +exit 0 +EOF + + cat ~/rc.local > /etc/rc.local + rm ~/rc.local + echo "Configured rc.local." +} + +function configure_hostname () { + echo "Configuring the hostname..." + + local new_host_name="teslausb" + cp /etc/hosts ~ + sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts + + cp /etc/hostname ~ + sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname + echo "Configured the hostname." +} + +function make_root_fs_readonly () { + /tmp/make-root-fs-readonly.sh +} + +echo "Verifying environment variables..." + +check_variable "archiveserver" +check_variable "sharename" +check_variable "shareuser" +check_variable "sharepassword" +check_variable "campercent" + +check_pushover_enabled + +check_archive_server_reachable + +check_available_space + +get_ancillary_setup_scripts + +pushd ~ + +configure_archive_scripts + +configure_pushover_scripts + +fix_cmdline_txt_modules_load + +echo "" >> /etc/fstab + +create_usb_drive_backing_files + +configure_archive + +configure_rc_local + +configure_hostname + +make_root_fs_readonly + +echo "All done." From e08e34c558ceffd0e4b54e1b5296d6b287ce9111 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 20 Oct 2018 18:25:30 -0500 Subject: [PATCH 02/67] More logging and automation --- headless-scripts/Readme.md | 41 +++++++++++++ headless-scripts/setup-piForHeadlessBuild.sh | 7 +-- headless-scripts/setup-teslausb-headless | 60 ++++++++++++++++---- 3 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 headless-scripts/Readme.md diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md new file mode 100644 index 0000000..dd80bc8 --- /dev/null +++ b/headless-scripts/Readme.md @@ -0,0 +1,41 @@ +# Flashable image to get started more quick + +# This is a WORK IN PROGRESS, NOT CURRENTLY WORKING. + +For now the image creation work is at [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). +* Assumes your Pi comes up on Wifi, with internet access. (But so does most of this guide.) USB networking still enabled for troubleshooting. +* At this point, I'm designing it to pull the setup scripts dynamically, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! + + + +1. Flash the image +1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, wifi, and push notifications if desired.) +1. Run the `setup-piForHeadlessBuild.sh` (note: **not** `setup-piForHeadlessSetup.sh`) +1. If all goes well, put card into Pi and boot. + +* A `/boot/teslausb-headless-setup.log` file will be created and stages logged. This takes the place of the "STOP" commands +* Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. May use a progress system so the script can pick back up if needed. (This is probably useful for the general/old way of setup too.) + + + +#### Modifications to pi-gen builder from master + +Built image on a Raspi running Stretch, for maximum Pi-ception. + +1. Add SKIP and SKIP_IMAGES files to stage3, 4, and 5 (if present). +1. Add a stage6. (There are stages0-5, but may be a stage5 in some cases. This will help keep a clean merge later.) +1. Copy the prerun.sh from `stage2`. Be SURE to mark `chmod +x` it. +1. Remove or rename the EXPORT_NOOBS files in all stages. We don't need a NOOBS image built. +1. In `stage6`, create a `00-tweaks` folder, with a `00-patches` folder and patch inside to patch `cmdline.txt` to remove the resize and add the needed modules. The build process uses `quilt` for patching. Note: the path for any patching you do at this stage is `stage6/rootfs/FILEPATH` where `rootfs` represents the Pi's `/`. So, `cmdline.txt` is `stage6/rootfs/boot/cmdline.txt`. +1. Add a patch for the `config.txt` file. +1. Add a file called `series` in the patches directory with the name of each `.diff` file in the order you want them applied. +1. Add a `files` folder in stage6 with modified `rc.local`. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time. (Still working on build logic here.) Files are moved into final locations in a `00-run.sh` script and the `install` command. See the script for details. +1. (Yes at this point you could suggest that just putting the end state files in place instead of patching would be good, but why not be idiomatic? :) ) +1. Run `sudo ./build.sh` from the `pi-gen` directory. +1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in stage2-stage5 present) and rerun `sudo CLEAN=1 ./build.sh` + +### Image creation TODOs +1. TODO: Patch the hostname to teslausb +1. TODO: I still see some errors during pi-gen about locale, may need to be fixed? stage0/01-locale/debconf en_US.UTF-8 +1. Aspirational TODO: Remove more packages etc to make the boot process faster? OR start from `stage1` if we don't need all of `stage2` + diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh index 2b5491a..20d03d6 100755 --- a/headless-scripts/setup-piForHeadlessBuild.sh +++ b/headless-scripts/setup-piForHeadlessBuild.sh @@ -128,7 +128,7 @@ CONFIG_TXT_PATH="$BOOT_DIR/config.txt" if ! grep -q "dtoverlay=dwc2" $CONFIG_TXT_PATH then - echo "Updating $CONFIG_TXT_PATH ..." + good_message "Updating $CONFIG_TXT_PATH ..." echo "" >> "$CONFIG_TXT_PATH" echo "dtoverlay=dwc2" >> "$CONFIG_TXT_PATH" else @@ -149,7 +149,7 @@ then touch "$BOOT_DIR/ssh" fi -# Sets up wifi credentials so wifi will be +# Sets up wifi credentials so wifi will be # auto configured on first boot WPA_SUPPLICANT_CONF_PATH="$BOOT_DIR/wpa_supplicant.conf" @@ -174,7 +174,6 @@ EOF echo "" good_message '-- Files updated and ready for headless setup --' echo '' -good_message '-- You can now insert your SD card into the Pi for headless setup' -echo '' +echo 'You can now insert your SD card into the Pi for headless setup. Plug in power to the Pi and it will boot and run.' echo "When done (this may take a vew minutes), the Pi should be available over SSH as pi@teslausb.local" echo "" diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless index 23eefcd..4cc855b 100644 --- a/headless-scripts/setup-teslausb-headless +++ b/headless-scripts/setup-teslausb-headless @@ -1,9 +1,9 @@ #!/bin/bash -eu -REPO=rtgoodwin -BRANCH="headless-patch" +REPO=cimryan +BRANCH=master user_enabled_pushover=false -LOGFIlE=/boot/teslausb-headless-setup.log +LOGFILE=/boot/teslausb-headless-setup.log setup_complete=false # if ! [ $(id -u) = 0 ] @@ -13,19 +13,28 @@ setup_complete=false # fi function setup_log () { - echo "$( date )" >> "$LOGFILE" - echo "$1" >> "$LOGFILE" + echo "$( date ) : $1" >> "$LOGFILE" } -if [ ! -e /boot/TESLAUSB_SETUP_FINISHED ] +if [ ! -e /boot/TESLAUSB_SETUP_FINISHED ] then setup_log "Setting up teslausb functionality" - touch /boot/TESLA_USB_SETUP_STARTED + touch /boot/TESLAUSB_SETUP_STARTED fi function mark_setup_failed () { + setup_log "ERROR: Setup Failed." + touch /boot/TESLAUSB_SETUP_FAILED +} - +function mark_setup_success () { + if [ -e /boot/TESLAUSB_SETUP_FAILED ] + then + rm /boot/TESLAUSB_SETUP_FAILED + rm /boot/TESLAUSB_SETUP_STARTED + fi + touch /boot/TESLAUSB_SETUP_FINISHED + setup_log "Setup completed. Remounting file systems read only (may cause a reboot)." } function check_variable () { @@ -38,8 +47,29 @@ function check_variable () { fi } - - +function check_pushover_enabled () { + if [ ! -z "${pushover_enabled+x}" ] + then + if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] + then + setup_log "ERROR: " + echo "STOP: You're trying to setup Pushover but didn't provide your User and/or App key." + echo "Define the variables like this:" + echo "export pushover_user_key=put_your_userkey_here" + echo "export pushover_app_key=put_your_appkey_here" + exit 1 + elif [ "${pushover_user_key}" = "put_your_userkey_here" ] || [ "${pushover_app_key}" = "put_your_appkey_here" ] + then + echo "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." + exit 1 + else + user_enabled_pushover=true + echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials + echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials + echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials + fi + fi +} function check_archive_server_reachable () { echo "Verifying that the archive server $archiveserver is reachable..." @@ -187,6 +217,14 @@ function make_root_fs_readonly () { /tmp/make-root-fs-readonly.sh } +if [ ! -e /boot/teslausb_setup_variables.conf ] +then + setup_log "ERROR: teslausb_setup_variables.conf file not found. Can't continue setup." + exit 1 +fi + +source /boot/teslausb_setup_variables.conf + echo "Verifying environment variables..." check_variable "archiveserver" @@ -221,6 +259,8 @@ configure_rc_local configure_hostname +mark_setup_success + make_root_fs_readonly echo "All done." From 4b761d34e05a297121071325f62f25e244f3295d Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 20 Oct 2018 19:11:41 -0500 Subject: [PATCH 03/67] Update headless-scripts/setup-teslausb-headless Added a reboot since resolv.conf and filesystem remount seem to need it. --- headless-scripts/setup-teslausb-headless | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless index 4cc855b..2a5fc3d 100644 --- a/headless-scripts/setup-teslausb-headless +++ b/headless-scripts/setup-teslausb-headless @@ -31,10 +31,10 @@ function mark_setup_success () { if [ -e /boot/TESLAUSB_SETUP_FAILED ] then rm /boot/TESLAUSB_SETUP_FAILED - rm /boot/TESLAUSB_SETUP_STARTED fi + rm /boot/TESLAUSB_SETUP_STARTED touch /boot/TESLAUSB_SETUP_FINISHED - setup_log "Setup completed. Remounting file systems read only (may cause a reboot)." + setup_log "Main setup completed. Remounting file systems read only." } function check_variable () { @@ -263,4 +263,7 @@ mark_setup_success make_root_fs_readonly -echo "All done." +setup_log "Filesystems made read-only. Rebooting." + +reboot + From 52ad4b21ad85ab2b540544cc94da5cd1bf3e33b1 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 11:02:49 -0500 Subject: [PATCH 04/67] Made more informative Output to setup log Easier to read main log function Add LED flashes for stage setup / failure Move all script downloads to frontend setup script --- headless-scripts/Readme.md | 9 +- headless-scripts/setup-piForHeadlessBuild.sh | 75 ++++++++- headless-scripts/setup-teslausb-headless | 168 ++++++++++--------- windows_archive/archive-teslacam-clips | 3 +- windows_archive/archiveloop | 3 +- windows_archive/send-pushover | 18 +- 6 files changed, 185 insertions(+), 91 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index dd80bc8..5c1effa 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -10,12 +10,16 @@ For now the image creation work is at [rtgoodwin's fork of pi-gen](https://githu 1. Flash the image 1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, wifi, and push notifications if desired.) -1. Run the `setup-piForHeadlessBuild.sh` (note: **not** `setup-piForHeadlessSetup.sh`) +1. Run the `setup-piForHeadlessBuild.sh` (note: **not** `setup-piForHeadlessSetup.sh`): +`curl https://raw.githubusercontent.com/rtgoodwin/teslausb/headless-patch/headless-scripts/setup-piForHeadlessBuild.sh -o setup-piForHeadlessBuild.sh` +`chmod +x setup-piForHeadlessBuild.sh` +`./setup-piForHeadlessBuild.sh .` 1. If all goes well, put card into Pi and boot. * A `/boot/teslausb-headless-setup.log` file will be created and stages logged. This takes the place of the "STOP" commands * Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. May use a progress system so the script can pick back up if needed. (This is probably useful for the general/old way of setup too.) - +* The Pi LED will flash patterns as it gets to each stage (labeled in the setup-teslausb-headless script). + * 10 flashes means setup failed! #### Modifications to pi-gen builder from master @@ -31,6 +35,7 @@ Built image on a Raspi running Stretch, for maximum Pi-ception. 1. Add a file called `series` in the patches directory with the name of each `.diff` file in the order you want them applied. 1. Add a `files` folder in stage6 with modified `rc.local`. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time. (Still working on build logic here.) Files are moved into final locations in a `00-run.sh` script and the `install` command. See the script for details. 1. (Yes at this point you could suggest that just putting the end state files in place instead of patching would be good, but why not be idiomatic? :) ) +1. Add a script to flash LEDs 1. Run `sudo ./build.sh` from the `pi-gen` directory. 1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in stage2-stage5 present) and rerun `sudo CLEAN=1 ./build.sh` diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh index 20d03d6..30e2ec1 100755 --- a/headless-scripts/setup-piForHeadlessBuild.sh +++ b/headless-scripts/setup-piForHeadlessBuild.sh @@ -21,6 +21,9 @@ BOOT_DIR="$1" RED='\033[0;31m' # Red for warning NC='\033[0m' # No Color GREEN='\033[0;32m' +scripts_downloaded=false +REPO=rtgoodwin +BRANCH=headless-patch function stop_message () { echo -e "${RED}${1} ${NC}" @@ -56,6 +59,17 @@ function verify_file_exists () { fi } +function verify_setup_file_exists () { + local file_name="$1" + local expected_path="$2" + + if [ ! -e "$expected_path/$file_name" ] + then + stop_message "STOP: Didn't find setup script $file_name at $expected_path. Try running the setup script again." + exit 1 + fi +} + function verify_wifi_variables () { if [ ! -n "${SSID+x}" ] || [ ! -n "${WIFIPASS+x}" ] then @@ -112,6 +126,58 @@ function verify_pushover_variables () { fi } +function download_scripts () { + mkdir "${BOOT_DIR}/teslausb_script_scripts" + if [ ! -d "${BOOT_DIR}/teslausb_script_scripts" ] + then + stop_message "ERROR: Failed to make teslausb_setup_scripts and download setup scripts. Ensure you have internet access and run this script again." + else + pushd "${BOOT_DIR}/teslausb_script_scripts" + + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/headless-patch/setup-teslausb-headless -O setup-teslausb-headless + verify_setup_file_exists "setup-teslausb-headless" "${BOOT_DIR}/teslausb_script_scripts" + chmod +x setup-teslausb-headless + good_message "Downloaded main setup script." + + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop -O archiveloop + # sed s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/ ~/archiveloop > /root/bin/archiveloop + sed -i'.bak' -e "s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/" archiveloop + verify_setup_file_exists "archiveloop" "${BOOT_DIR}/teslausb_script_scripts" + chmod +x archiveloop + + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips -O archive-teslacam-clips + verify_setup_file_exists "archive-teslacam-clips" "${BOOT_DIR}/teslausb_script_scripts" + chmod +x archive-teslacam-clips + good_message "Configured the archive scripts." + + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw -O remountfs_rw + verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_script_scripts" + chmod +x remountfs_rw + good_message "Downloaded script to remount filesystems read/write if needed (/root/bin/remountfs_rw)." + + if [ ${user_enabled_pushover} = "true" ] + then + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover + verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_script_scripts" + chmod +x send-pushover + good_message "Downloaded Pushover notification script." + fi + + good_message "Downloading ancillary setup scripts." + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh -O create-backingfiles-partition.sh + verify_setup_file_exists "create-backingfiles-partition.sh" "${BOOT_DIR}/teslausb_script_scripts" + chmod +x create-backingfiles-partition.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh -O create-backingfiles.sh + verify_setup_file_exists "create-backingfiles.sh" "${BOOT_DIR}/teslausb_script_scripts" + chmod +x create-backingfiles.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh -O make-root-fs-readonly.sh + verify_setup_file_exists "make-root-fs-readonly.sh" "${BOOT_DIR}/teslausb_script_scripts" + chmod +x make-root-fs-readonly.sh + popd + good_message "All scripts downloaded and configured." + fi + +} verify_file_exists "cmdline.txt" "$BOOT_DIR" verify_file_exists "config.txt" "$BOOT_DIR" @@ -171,9 +237,16 @@ network={ } EOF +good_message "Downloading setup scripts. They will be downloaded to ${BOOT_DIR}/teslausb_setup_scripts," +good_message "and moved to /root/teslausb_script_scripts during first boot and install." + +download_scripts + echo "" good_message '-- Files updated and ready for headless setup --' echo '' echo 'You can now insert your SD card into the Pi for headless setup. Plug in power to the Pi and it will boot and run.' -echo "When done (this may take a vew minutes), the Pi should be available over SSH as pi@teslausb.local" +echo "When done (this may take a vew minutes), the Pi should be available over SSH as pi@teslausb.local." +echo "It's recommended you have your Pi plugged into a PC USB port for power, and connected to the port labeled USB on the Pi." +echo "That way, when setup is complete, you should see your CAM and/or MUSIC drives appear as confirmation." echo "" diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless index 2a5fc3d..bd49a23 100644 --- a/headless-scripts/setup-teslausb-headless +++ b/headless-scripts/setup-teslausb-headless @@ -5,6 +5,7 @@ BRANCH=master user_enabled_pushover=false LOGFILE=/boot/teslausb-headless-setup.log setup_complete=false +stage_in_progress=false # if ! [ $(id -u) = 0 ] # then @@ -42,7 +43,8 @@ function check_variable () { if [ -z "${!var_name+x}" ] then echo "STOP: Define the variable $var_name like this: export $var_name=value" - setup_log "SETUP FAILED: Define the variable $var_name as export $var_name=value in /boot/teslausb_setup_variables" + setup_log "SETUP FAILED: Define the variable $var_name as export $var_name=value in /boot/teslausb_setup_variables.conf" + /tmp/stage_flash 10 &>/dev/null exit 1 fi } @@ -50,73 +52,60 @@ function check_variable () { function check_pushover_enabled () { if [ ! -z "${pushover_enabled+x}" ] then - if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] - then - setup_log "ERROR: " - echo "STOP: You're trying to setup Pushover but didn't provide your User and/or App key." - echo "Define the variables like this:" - echo "export pushover_user_key=put_your_userkey_here" - echo "export pushover_app_key=put_your_appkey_here" - exit 1 - elif [ "${pushover_user_key}" = "put_your_userkey_here" ] || [ "${pushover_app_key}" = "put_your_appkey_here" ] - then - echo "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." - exit 1 - else - user_enabled_pushover=true + setup_log "Adding Pushover variables into /root/.teslaCamPushoverCredentials" echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials fi - fi } function check_archive_server_reachable () { - echo "Verifying that the archive server $archiveserver is reachable..." + setup_log "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 + setup_log "WARNING: The archive server $archiveserver is unreachable. Try specifying its IP address instead." + setup_log "Continuing setup, but you may need to edit /etc/fstab to verify your archive mount entry is correct" fi - echo "The archive server is reachable." + # echo "The archive server is reachable." } function check_available_space () { - echo "Verifying that there is sufficient space available on the MicroSD card..." + setup_log "Verifying that there is sufficient space available on the MicroSD card..." local available_space="$( parted -m /dev/mmcblk0 u b print free | tail -1 | cut -d ":" -f 4 | sed 's/B//g' )" if [ "$available_space" -lt 4294967296 ] then - echo "STOP: The MicroSD card is too small." + setup_log "ERROR: The MicroSD card is too small. Stopping setup." + /tmp/stage_flash 10 &>/dev/null exit 1 fi - echo "There is sufficient space available." + setup_log "There is sufficient space available." } -function get_ancillary_setup_scripts () { - pushd /tmp - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh - chmod +x ./create-backingfiles-partition.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh - chmod +x ./create-backingfiles.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh - chmod +x ./make-root-fs-readonly.sh - popd -} +# function get_ancillary_setup_scripts () { +# pushd /tmp +# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh +# chmod +x ./create-backingfiles-partition.sh +# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh +# chmod +x ./create-backingfiles.sh +# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh +# chmod +x ./make-root-fs-readonly.sh +# popd +# } function fix_cmdline_txt_modules_load () { - echo "Fixing the modules-load parameter in /boot/cmdline.txt..." + setup_log "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 rm ~/cmdline.txt - echo "Fixed cmdline.txt." + setup_log "Fixed cmdline.txt." } BACKINGFILES_MOUNTPOINT=/backingfiles @@ -125,61 +114,61 @@ function create_usb_drive_backing_files () { mkdir "$BACKINGFILES_MOUNTPOINT" /tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" - echo "Mounting the partition for the backing files..." + setup_log "Mounting the partition for the backing files..." mount /backingfiles - echo "Mounted the partition for the backing files." + setup_log "Mounted the partition for the backing files." /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" } function configure_archive () { - echo "Configuring the archive..." + setup_log "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 echo "username=$shareuser" > /root/.teslaCamArchiveCredentials echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials - echo "Configured the archive." + setup_log "Configured the archive." } -function configure_archive_scripts () { - echo "Configuring the archive scripts..." - mkdir /root/bin +# 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 ~ +# 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/archive-teslacam-clips - chmod +x archive-teslacam-clips - popd - echo "Configured the archive scripts." +# pushd /root/bin +# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips +# chmod +x archive-teslacam-clips +# popd +# echo "Configured the archive scripts." - pushd /root - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw - chmod +x remountfs_rw - popd - echo "Downloaded script to remount filesystems read/write if needed (/root/remountfs_rw)." -} +# pushd /root +# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw +# chmod +x remountfs_rw +# popd +# echo "Downloaded script to remount filesystems read/write if needed (/root/remountfs_rw)." +# } -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_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 () { - echo "Configuring /etc/rc.local to run the archive scripts at startup..." + setup_log "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 cat << 'EOF' >> ~/rc.local @@ -198,11 +187,11 @@ EOF cat ~/rc.local > /etc/rc.local rm ~/rc.local - echo "Configured rc.local." + setup_log "Configured rc.local." } function configure_hostname () { - echo "Configuring the hostname..." + setup_log "Configuring the hostname..." local new_host_name="teslausb" cp /etc/hosts ~ @@ -210,22 +199,35 @@ function configure_hostname () { cp /etc/hostname ~ sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname - echo "Configured the hostname." + setup_log "Configured the hostname." } function make_root_fs_readonly () { /tmp/make-root-fs-readonly.sh } +# TURN OFF LED so we can start watching progress +echo 1 | sudo tee /sys/class/leds/led0/brightness + +sleep 5 + +# SETUP STAGE 1 - Check variables file + +/tmp/stage_flash 1 &>/dev/null +setup_log "SETUP STAGE 1: Check variables file." if [ ! -e /boot/teslausb_setup_variables.conf ] then setup_log "ERROR: teslausb_setup_variables.conf file not found. Can't continue setup." + /tmp/stage_flash 10 &>/dev/null exit 1 fi source /boot/teslausb_setup_variables.conf -echo "Verifying environment variables..." +# SETUP STAGE 2 - Validate variables. This should never fail but just in case. +/tmp/stage_flash 2 &>/dev/null + +setup_log "SETUP STAGE 2: Verifying environment variables..." check_variable "archiveserver" check_variable "sharename" @@ -237,20 +239,28 @@ check_pushover_enabled check_archive_server_reachable +# SETUP STAGE 3 + +setup_log "SETUP STAGE 3: Check available space." +/tmp/stage_flash 3 &>/dev/null check_available_space -get_ancillary_setup_scripts +# get_ancillary_setup_scripts -pushd ~ +# pushd ~ -configure_archive_scripts +# configure_archive_scripts -configure_pushover_scripts +# configure_pushover_scripts fix_cmdline_txt_modules_load echo "" >> /etc/fstab +# SETUP STAGE 4 +setup_log "SETUP STAGE 4: Create backing files and final config changes." +/tmp/stage_flash 4 &>/dev/null + create_usb_drive_backing_files configure_archive @@ -259,6 +269,10 @@ configure_rc_local configure_hostname +# SETUP STAGE 5 and reboot +# If you see 5 flashes we are probably good! + +/tmp/stage_flash 5 &>/dev/null mark_setup_success make_root_fs_readonly diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index c6be29a..c18eace 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -5,8 +5,7 @@ CAM_MOUNT=/mnt/cam ARCHIVE_MOUNT=/mnt/archive function log () { - echo "$( date )" >> "$LOG_FILE" - echo "$1" >> "$LOG_FILE" + echo "$( date ) : $1" >> "$LOG_FILE" } function retry () { diff --git a/windows_archive/archiveloop b/windows_archive/archiveloop index 09f276d..ec196d1 100644 --- a/windows_archive/archiveloop +++ b/windows_archive/archiveloop @@ -5,8 +5,7 @@ ARCHIVE_HOST_NAME=archiveserver LOGFILE=/tmp/archiveloop.log function log () { - echo "$( date )" >> "$LOGFILE" - echo "$1" >> "$LOGFILE" + echo "$( date ) : $1" >> "$LOG_FILE" } function archive_is_reachable () { diff --git a/windows_archive/send-pushover b/windows_archive/send-pushover index 6948c06..90697f9 100644 --- a/windows_archive/send-pushover +++ b/windows_archive/send-pushover @@ -1,14 +1,18 @@ #!/bin/bash -eu +LOGFILE=/tmp/archiveloop.log + function log () { - echo "$( date )" >> "$LOG_FILE" - echo "$1" >> "$LOG_FILE" + echo "$( date ) : $1" >> "$LOG_FILE" } source /root/.teslaCamPushoverCredentials -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 +if ping -c 1 api.pushover.net &> /dev/null +then + 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 +fi From 1335be2a1ce26fc1e3c7f5e7824e40d6bcf8cf9d Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 11:05:35 -0500 Subject: [PATCH 05/67] Change branch for testing Also in prev commit always download pushover script as it doesn't hurt (user can set it up later) and removes some conditional logic. --- headless-scripts/setup-teslausb-headless | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless index bd49a23..687d276 100644 --- a/headless-scripts/setup-teslausb-headless +++ b/headless-scripts/setup-teslausb-headless @@ -1,11 +1,10 @@ #!/bin/bash -eu -REPO=cimryan -BRANCH=master +REPO=rtgoodwin +BRANCH="headless-patch" user_enabled_pushover=false LOGFILE=/boot/teslausb-headless-setup.log setup_complete=false -stage_in_progress=false # if ! [ $(id -u) = 0 ] # then From 307afe4792841e5db083e0b8418b07d6963866f7 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 11:08:49 -0500 Subject: [PATCH 06/67] Update headless-script path --- headless-scripts/setup-piForHeadlessBuild.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh index 30e2ec1..3f119ad 100755 --- a/headless-scripts/setup-piForHeadlessBuild.sh +++ b/headless-scripts/setup-piForHeadlessBuild.sh @@ -134,7 +134,7 @@ function download_scripts () { else pushd "${BOOT_DIR}/teslausb_script_scripts" - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/headless-patch/setup-teslausb-headless -O setup-teslausb-headless + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/headless-scripts/setup-teslausb-headless -O setup-teslausb-headless verify_setup_file_exists "setup-teslausb-headless" "${BOOT_DIR}/teslausb_script_scripts" chmod +x setup-teslausb-headless good_message "Downloaded main setup script." From 055c0e8d36462f312eedccb586a1b1b3d07c1d91 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 11:39:24 -0500 Subject: [PATCH 07/67] Path error in setup script --- headless-scripts/Readme.md | 16 ++++++++++++---- headless-scripts/setup-piForHeadlessBuild.sh | 5 +++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 5c1effa..27b9d5b 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -2,14 +2,22 @@ # This is a WORK IN PROGRESS, NOT CURRENTLY WORKING. -For now the image creation work is at [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). +For now the image creation work is at: +* Modified pi-gen [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). +* `headless-patch` branch of [https://github.com/rtgoodwin/teslausb](https://github.com/rtgoodwin/teslausb) + +## Notes + * Assumes your Pi comes up on Wifi, with internet access. (But so does most of this guide.) USB networking still enabled for troubleshooting. -* At this point, I'm designing it to pull the setup scripts dynamically, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! +* I moved all script downloads and variable creation to the initial setup. At this point, I'm designing it to pull the setup scripts dynamically, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! +* The archive server might not be reachable during the first boot during setup, ex. if building the card somewhere away from the archive server location. So I no longer fail on it not being reachable. +## Building the Pi +WORK IN PROGRESS BUT MOSTLY RIGHT -1. Flash the image -1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, wifi, and push notifications if desired.) +1. Flash the image from: XXXXXXXX +1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) See the main README for these instructions for now. 1. Run the `setup-piForHeadlessBuild.sh` (note: **not** `setup-piForHeadlessSetup.sh`): `curl https://raw.githubusercontent.com/rtgoodwin/teslausb/headless-patch/headless-scripts/setup-piForHeadlessBuild.sh -o setup-piForHeadlessBuild.sh` `chmod +x setup-piForHeadlessBuild.sh` diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh index 3f119ad..9104c29 100755 --- a/headless-scripts/setup-piForHeadlessBuild.sh +++ b/headless-scripts/setup-piForHeadlessBuild.sh @@ -127,10 +127,11 @@ function verify_pushover_variables () { } function download_scripts () { - mkdir "${BOOT_DIR}/teslausb_script_scripts" + if [ ! -d "${BOOT_DIR}/teslausb_script_scripts" ] then - stop_message "ERROR: Failed to make teslausb_setup_scripts and download setup scripts. Ensure you have internet access and run this script again." + mkdir "${BOOT_DIR}/teslausb_script_scripts" + # stop_message "ERROR: Failed to make teslausb_setup_scripts and download setup scripts. Ensure you have internet access and run this script again." else pushd "${BOOT_DIR}/teslausb_script_scripts" From cbcfa38d0f2106cd657dbe130a1785e2f4863903 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 11:41:42 -0500 Subject: [PATCH 08/67] Another path error in setup script --- headless-scripts/setup-piForHeadlessBuild.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh index 9104c29..fc666d5 100755 --- a/headless-scripts/setup-piForHeadlessBuild.sh +++ b/headless-scripts/setup-piForHeadlessBuild.sh @@ -128,9 +128,9 @@ function verify_pushover_variables () { function download_scripts () { - if [ ! -d "${BOOT_DIR}/teslausb_script_scripts" ] + if [ ! -d "${BOOT_DIR}/teslausb_setup_scripts" ] then - mkdir "${BOOT_DIR}/teslausb_script_scripts" + mkdir "${BOOT_DIR}/teslausb_setup_scripts" # stop_message "ERROR: Failed to make teslausb_setup_scripts and download setup scripts. Ensure you have internet access and run this script again." else pushd "${BOOT_DIR}/teslausb_script_scripts" From c0bf2dce81c9433a48de0db12ea6871a70bab66b Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 11:42:56 -0500 Subject: [PATCH 09/67] All path errors all day. --- headless-scripts/setup-piForHeadlessBuild.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh index fc666d5..a8832d5 100755 --- a/headless-scripts/setup-piForHeadlessBuild.sh +++ b/headless-scripts/setup-piForHeadlessBuild.sh @@ -133,46 +133,46 @@ function download_scripts () { mkdir "${BOOT_DIR}/teslausb_setup_scripts" # stop_message "ERROR: Failed to make teslausb_setup_scripts and download setup scripts. Ensure you have internet access and run this script again." else - pushd "${BOOT_DIR}/teslausb_script_scripts" + pushd "${BOOT_DIR}/teslausb_setup_scripts" wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/headless-scripts/setup-teslausb-headless -O setup-teslausb-headless - verify_setup_file_exists "setup-teslausb-headless" "${BOOT_DIR}/teslausb_script_scripts" + verify_setup_file_exists "setup-teslausb-headless" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x setup-teslausb-headless good_message "Downloaded main setup script." wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop -O archiveloop # sed s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/ ~/archiveloop > /root/bin/archiveloop sed -i'.bak' -e "s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/" archiveloop - verify_setup_file_exists "archiveloop" "${BOOT_DIR}/teslausb_script_scripts" + verify_setup_file_exists "archiveloop" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x archiveloop wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips -O archive-teslacam-clips - verify_setup_file_exists "archive-teslacam-clips" "${BOOT_DIR}/teslausb_script_scripts" + verify_setup_file_exists "archive-teslacam-clips" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x archive-teslacam-clips good_message "Configured the archive scripts." wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw -O remountfs_rw - verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_script_scripts" + verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x remountfs_rw good_message "Downloaded script to remount filesystems read/write if needed (/root/bin/remountfs_rw)." if [ ${user_enabled_pushover} = "true" ] then wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover - verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_script_scripts" + verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x send-pushover good_message "Downloaded Pushover notification script." fi good_message "Downloading ancillary setup scripts." wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh -O create-backingfiles-partition.sh - verify_setup_file_exists "create-backingfiles-partition.sh" "${BOOT_DIR}/teslausb_script_scripts" + verify_setup_file_exists "create-backingfiles-partition.sh" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x create-backingfiles-partition.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh -O create-backingfiles.sh - verify_setup_file_exists "create-backingfiles.sh" "${BOOT_DIR}/teslausb_script_scripts" + verify_setup_file_exists "create-backingfiles.sh" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x create-backingfiles.sh wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh -O make-root-fs-readonly.sh - verify_setup_file_exists "make-root-fs-readonly.sh" "${BOOT_DIR}/teslausb_script_scripts" + verify_setup_file_exists "make-root-fs-readonly.sh" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x make-root-fs-readonly.sh popd good_message "All scripts downloaded and configured." @@ -239,7 +239,7 @@ network={ EOF good_message "Downloading setup scripts. They will be downloaded to ${BOOT_DIR}/teslausb_setup_scripts," -good_message "and moved to /root/teslausb_script_scripts during first boot and install." +good_message "and moved to /root/teslausb_setup_scripts during first boot and install." download_scripts From 0aa03a1ca8bdabca255891126dbf9093af97aace Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 12:57:21 -0500 Subject: [PATCH 10/67] Don't exit rc.local prematurely Also silent downloads of scripts. --- headless-scripts/Readme.md | 1 + headless-scripts/setup-piForHeadlessBuild.sh | 33 ++++++++++---------- headless-scripts/setup-teslausb-headless | 19 +++++------ 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 27b9d5b..c93c0b8 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -50,5 +50,6 @@ Built image on a Raspi running Stretch, for maximum Pi-ception. ### Image creation TODOs 1. TODO: Patch the hostname to teslausb 1. TODO: I still see some errors during pi-gen about locale, may need to be fixed? stage0/01-locale/debconf en_US.UTF-8 +1. TODO: Cache the remount packages? Might mess with first boot like `rsyslog` 1. Aspirational TODO: Remove more packages etc to make the boot process faster? OR start from `stage1` if we don't need all of `stage2` diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh index a8832d5..3dcc0df 100755 --- a/headless-scripts/setup-piForHeadlessBuild.sh +++ b/headless-scripts/setup-piForHeadlessBuild.sh @@ -61,12 +61,13 @@ function verify_file_exists () { function verify_setup_file_exists () { local file_name="$1" - local expected_path="$2" - if [ ! -e "$expected_path/$file_name" ] + if [ -e "$file_name" ] then - stop_message "STOP: Didn't find setup script $file_name at $expected_path. Try running the setup script again." - exit 1 + good_message "Downloaded $file_name." + else + stop_message "STOP: Didn't find downloaded script $file_name. Try running the setup script again." + exit 1 fi } @@ -132,51 +133,49 @@ function download_scripts () { then mkdir "${BOOT_DIR}/teslausb_setup_scripts" # stop_message "ERROR: Failed to make teslausb_setup_scripts and download setup scripts. Ensure you have internet access and run this script again." - else - pushd "${BOOT_DIR}/teslausb_setup_scripts" - - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/headless-scripts/setup-teslausb-headless -O setup-teslausb-headless + fi + cd "${BOOT_DIR}/teslausb_setup_scripts" + curl -s -o setup-teslausb-headless https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/headless-scripts/setup-teslausb-headless verify_setup_file_exists "setup-teslausb-headless" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x setup-teslausb-headless good_message "Downloaded main setup script." - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop -O archiveloop + curl -s -o archiveloop https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop # sed s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/ ~/archiveloop > /root/bin/archiveloop sed -i'.bak' -e "s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/" archiveloop verify_setup_file_exists "archiveloop" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x archiveloop - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips -O archive-teslacam-clips + curl -s -o archive-teslacam-clips https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips verify_setup_file_exists "archive-teslacam-clips" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x archive-teslacam-clips good_message "Configured the archive scripts." - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw -O remountfs_rw + curl -s -o remountfs_rw https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x remountfs_rw good_message "Downloaded script to remount filesystems read/write if needed (/root/bin/remountfs_rw)." if [ ${user_enabled_pushover} = "true" ] then - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover + curl -s -o send-pushover https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x send-pushover good_message "Downloaded Pushover notification script." fi good_message "Downloading ancillary setup scripts." - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh -O create-backingfiles-partition.sh + curl -s -o create-backingfiles-partition.sh https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh verify_setup_file_exists "create-backingfiles-partition.sh" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x create-backingfiles-partition.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh -O create-backingfiles.sh + curl -s -o create-backingfiles.sh https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh verify_setup_file_exists "create-backingfiles.sh" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x create-backingfiles.sh - wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh -O make-root-fs-readonly.sh + curl -s -o make-root-fs-readonly.sh https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh verify_setup_file_exists "make-root-fs-readonly.sh" "${BOOT_DIR}/teslausb_setup_scripts" chmod +x make-root-fs-readonly.sh - popd + cd - good_message "All scripts downloaded and configured." - fi } diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless index 687d276..816f20f 100644 --- a/headless-scripts/setup-teslausb-headless +++ b/headless-scripts/setup-teslausb-headless @@ -43,7 +43,7 @@ function check_variable () { then echo "STOP: Define the variable $var_name like this: export $var_name=value" setup_log "SETUP FAILED: Define the variable $var_name as export $var_name=value in /boot/teslausb_setup_variables.conf" - /tmp/stage_flash 10 &>/dev/null + /etc/stage_flash 10 exit 1 fi } @@ -80,7 +80,7 @@ function check_available_space () { if [ "$available_space" -lt 4294967296 ] then setup_log "ERROR: The MicroSD card is too small. Stopping setup." - /tmp/stage_flash 10 &>/dev/null + /etc/stage_flash 10 exit 1 fi @@ -212,19 +212,20 @@ sleep 5 # SETUP STAGE 1 - Check variables file -/tmp/stage_flash 1 &>/dev/null +/etc/stage_flash 1 + setup_log "SETUP STAGE 1: Check variables file." if [ ! -e /boot/teslausb_setup_variables.conf ] then setup_log "ERROR: teslausb_setup_variables.conf file not found. Can't continue setup." - /tmp/stage_flash 10 &>/dev/null + /etc/stage_flash 10 exit 1 fi source /boot/teslausb_setup_variables.conf # SETUP STAGE 2 - Validate variables. This should never fail but just in case. -/tmp/stage_flash 2 &>/dev/null +/etc/stage_flash 2 setup_log "SETUP STAGE 2: Verifying environment variables..." @@ -241,7 +242,7 @@ check_archive_server_reachable # SETUP STAGE 3 setup_log "SETUP STAGE 3: Check available space." -/tmp/stage_flash 3 &>/dev/null +/etc/stage_flash 3 check_available_space # get_ancillary_setup_scripts @@ -258,7 +259,7 @@ echo "" >> /etc/fstab # SETUP STAGE 4 setup_log "SETUP STAGE 4: Create backing files and final config changes." -/tmp/stage_flash 4 &>/dev/null +/etc/stage_flash 4 create_usb_drive_backing_files @@ -271,9 +272,9 @@ configure_hostname # SETUP STAGE 5 and reboot # If you see 5 flashes we are probably good! -/tmp/stage_flash 5 &>/dev/null +/etc/stage_flash 5 mark_setup_success - +echo 1 | sudo tee /sys/class/leds/led0/brightness make_root_fs_readonly setup_log "Filesystems made read-only. Rebooting." From a8ac613fd034a00f29740825de15f0015e58f4d4 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 13:10:50 -0500 Subject: [PATCH 11/67] More descriptive Also typos in LOGFILE var. --- headless-scripts/setup-teslausb-headless | 4 +++- windows_archive/archive-teslacam-clips | 2 +- windows_archive/archiveloop | 2 +- windows_archive/send-pushover | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless index 816f20f..aed8d66 100644 --- a/headless-scripts/setup-teslausb-headless +++ b/headless-scripts/setup-teslausb-headless @@ -272,9 +272,11 @@ configure_hostname # SETUP STAGE 5 and reboot # If you see 5 flashes we are probably good! +setup_log "SETUP STAGE 5: Marking successful and remounting filesystem readonly." /etc/stage_flash 5 mark_setup_success -echo 1 | sudo tee /sys/class/leds/led0/brightness + +echo 0 | sudo tee /sys/class/leds/led0/brightness make_root_fs_readonly setup_log "Filesystems made read-only. Rebooting." diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index c18eace..28bb689 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -5,7 +5,7 @@ CAM_MOUNT=/mnt/cam ARCHIVE_MOUNT=/mnt/archive function log () { - echo "$( date ) : $1" >> "$LOG_FILE" + echo "$( date ) : $1" >> "$LOGFILE" } function retry () { diff --git a/windows_archive/archiveloop b/windows_archive/archiveloop index ec196d1..2bb7797 100644 --- a/windows_archive/archiveloop +++ b/windows_archive/archiveloop @@ -5,7 +5,7 @@ ARCHIVE_HOST_NAME=archiveserver LOGFILE=/tmp/archiveloop.log function log () { - echo "$( date ) : $1" >> "$LOG_FILE" + echo "$( date ) : $1" >> "$LOGFILE" } function archive_is_reachable () { diff --git a/windows_archive/send-pushover b/windows_archive/send-pushover index 90697f9..f594667 100644 --- a/windows_archive/send-pushover +++ b/windows_archive/send-pushover @@ -3,7 +3,7 @@ LOGFILE=/tmp/archiveloop.log function log () { - echo "$( date ) : $1" >> "$LOG_FILE" + echo "$( date ) : $1" >> "$LOGFILE" } source /root/.teslaCamPushoverCredentials From 5b4dd4538f16cd04f0af3739fdf9ea3c7895f02e Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 13:37:29 -0500 Subject: [PATCH 12/67] Better testing of pushover And archive loop logging weirdness. --- windows_archive/archive-teslacam-clips | 8 ++++---- windows_archive/archiveloop | 4 ++-- windows_archive/send-pushover | 9 ++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index 28bb689..1ddd7c4 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -1,11 +1,11 @@ #!/bin/bash -eu -LOG_FILE=/tmp/archive-teslacam-clips.log +LOG_FILE=/tmp/archiveloop.log CAM_MOUNT=/mnt/cam ARCHIVE_MOUNT=/mnt/archive function log () { - echo "$( date ) : $1" >> "$LOGFILE" + echo "$( date ) : $1" >> "$LOG_FILE" } function retry () { @@ -70,7 +70,7 @@ function ensure_mountpoint_is_mounted_with_retry () { function move_clips_to_archive () { 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 log "Moving $file_name ..." @@ -80,7 +80,7 @@ function move_clips_to_archive () { done log "Moved $move_count file(s)." - if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $move_count > 0 ] + if [ -e "/root/.teslaCamPushoverCredentials" ] && [ ${move_count} -gt 0 ] then log "Sending Pushover message for copied files." /root/bin/send-pushover $move_count diff --git a/windows_archive/archiveloop b/windows_archive/archiveloop index 2bb7797..5336ff3 100644 --- a/windows_archive/archiveloop +++ b/windows_archive/archiveloop @@ -2,10 +2,10 @@ # Change the value on the right side of the equal sign to the name of the server hosting the archive. ARCHIVE_HOST_NAME=archiveserver -LOGFILE=/tmp/archiveloop.log +LOG_FILE=/tmp/archiveloop.log function log () { - echo "$( date ) : $1" >> "$LOGFILE" + echo "$( date ) : $1" >> "$LOG_FILE" } function archive_is_reachable () { diff --git a/windows_archive/send-pushover b/windows_archive/send-pushover index f594667..cd92f3e 100644 --- a/windows_archive/send-pushover +++ b/windows_archive/send-pushover @@ -1,18 +1,21 @@ #!/bin/bash -eu -LOGFILE=/tmp/archiveloop.log +files_copied=$1 + +LOG_FILE=/tmp/archiveloop.log function log () { - echo "$( date ) : $1" >> "$LOGFILE" + echo "$( date ) : $1" >> "$LOG_FILE" } source /root/.teslaCamPushoverCredentials if ping -c 1 api.pushover.net &> /dev/null then + if [ ${files_copied} -gt 0 ] curl -F "token=$pushover_app_key" \ -F "user=$pushover_user_key" \ -F "title=Dashcam Copy Complete" \ - -F "message=$1 file(s) were copied." \ + -F "message=${files_copied} file(s) were copied." \ https://api.pushover.net/1/messages fi From 5cfe22fb92ea06a703d176ab8c5c824572e00ed0 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 14:04:23 -0500 Subject: [PATCH 13/67] Check for teslacam folder And other tweaks. --- headless-scripts/Readme.md | 1 + headless-scripts/setup-teslausb-headless | 5 ++--- windows_archive/archive-teslacam-clips | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index c93c0b8..4535a2b 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -28,6 +28,7 @@ WORK IN PROGRESS BUT MOSTLY RIGHT * Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. May use a progress system so the script can pick back up if needed. (This is probably useful for the general/old way of setup too.) * The Pi LED will flash patterns as it gets to each stage (labeled in the setup-teslausb-headless script). * 10 flashes means setup failed! + * After the final stage and reboot the LED will go back to normal #### Modifications to pi-gen builder from master diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless index aed8d66..b713bf1 100644 --- a/headless-scripts/setup-teslausb-headless +++ b/headless-scripts/setup-teslausb-headless @@ -272,13 +272,12 @@ configure_hostname # SETUP STAGE 5 and reboot # If you see 5 flashes we are probably good! -setup_log "SETUP STAGE 5: Marking successful and remounting filesystem readonly." +setup_log "SETUP STAGE 5: Marking successful and making filesystem readonly." /etc/stage_flash 5 mark_setup_success -echo 0 | sudo tee /sys/class/leds/led0/brightness make_root_fs_readonly - +# echo 0 | sudo tee /sys/class/leds/led0/brightness setup_log "Filesystems made read-only. Rebooting." reboot diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index 1ddd7c4..5349666 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -41,6 +41,13 @@ function mount_mountpoint () { if [ "$mounted" = true ] then log "Mounted $mount_point." + if [ -d "/mnt/cam/TeslaCam" ] + then + log "TeslaCam folder exists" + true + return + else + mkdir /mnt/cam/TeslaCam true return else @@ -131,5 +138,5 @@ ensure_cam_drive_is_mounted move_clips_to_archive unmount_cam_drive - + connect_usb_drives_to_host \ No newline at end of file From fe764b00f7b56ce1b7c6ffce23db5f36b870824d Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 14:46:45 -0500 Subject: [PATCH 14/67] Silent pushover curl And fixed a missing fi --- windows_archive/archive-teslacam-clips | 17 +++++++++-------- windows_archive/send-pushover | 7 +++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index 5349666..a41985f 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -43,13 +43,14 @@ function mount_mountpoint () { log "Mounted $mount_point." if [ -d "/mnt/cam/TeslaCam" ] then - log "TeslaCam folder exists" - true - return - else - mkdir /mnt/cam/TeslaCam - true - return + log "TeslaCam folder exists" + true + return + else + mkdir /mnt/cam/TeslaCam + true + return + fi else log "Failed to mount $mount_point." false @@ -69,7 +70,7 @@ function ensure_mountpoint_is_mounted () { else mount_mountpoint "$mount_point" fi -} +} function ensure_mountpoint_is_mounted_with_retry () { retry ensure_mountpoint_is_mounted "$1" diff --git a/windows_archive/send-pushover b/windows_archive/send-pushover index cd92f3e..db2d4fe 100644 --- a/windows_archive/send-pushover +++ b/windows_archive/send-pushover @@ -12,10 +12,13 @@ source /root/.teslaCamPushoverCredentials if ping -c 1 api.pushover.net &> /dev/null then - if [ ${files_copied} -gt 0 ] - curl -F "token=$pushover_app_key" \ + if [ $files_copied -gt 0 ] + then + log "Sending notification that $files_copied were copied." + curl -s -F "token=$pushover_app_key" \ -F "user=$pushover_user_key" \ -F "title=Dashcam Copy Complete" \ -F "message=${files_copied} file(s) were copied." \ https://api.pushover.net/1/messages + fi fi From 4f9136cf9b03ba0b3fbba39eaaf560376e8c48f8 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 15:21:18 -0500 Subject: [PATCH 15/67] Update readme Ready for testing and feedback. --- headless-scripts/Readme.md | 42 +++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 4535a2b..065b85a 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -1,6 +1,6 @@ # Flashable image to get started more quick -# This is a WORK IN PROGRESS, NOT CURRENTLY WORKING. +# This is a WORK IN PROGRESS, SHOULD BE WORKING. For now the image creation work is at: * Modified pi-gen [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). @@ -10,25 +10,46 @@ For now the image creation work is at: * Assumes your Pi comes up on Wifi, with internet access. (But so does most of this guide.) USB networking still enabled for troubleshooting. * I moved all script downloads and variable creation to the initial setup. At this point, I'm designing it to pull the setup scripts dynamically, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! -* The archive server might not be reachable during the first boot during setup, ex. if building the card somewhere away from the archive server location. So I no longer fail on it not being reachable. + * At the very least we could bake in stable first stage headlessBuild scripts for Mac/Linux/Windows. + ## Building the Pi -WORK IN PROGRESS BUT MOSTLY RIGHT +WORK IN PROGRESS BUT MOSTLY RIGHT. And still shorter than the full process! -1. Flash the image from: XXXXXXXX -1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) See the main README for these instructions for now. +1. Flash the image from [here](https://www.dropbox.com/s/zfzjbmx4744q810/image_2018-10-21-teslausb_headless-lite.zip?dl=0) +1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) See the main README for all the variables. 1. Run the `setup-piForHeadlessBuild.sh` (note: **not** `setup-piForHeadlessSetup.sh`): `curl https://raw.githubusercontent.com/rtgoodwin/teslausb/headless-patch/headless-scripts/setup-piForHeadlessBuild.sh -o setup-piForHeadlessBuild.sh` `chmod +x setup-piForHeadlessBuild.sh` `./setup-piForHeadlessBuild.sh .` 1. If all goes well, put card into Pi and boot. +1. Wait for the the Pi to come up as a CAM USB drive, if you have it plugged into your computer. If not, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. +## What happens under the covers + +When the Pi boots the first time: * A `/boot/teslausb-headless-setup.log` file will be created and stages logged. This takes the place of the "STOP" commands * Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. May use a progress system so the script can pick back up if needed. (This is probably useful for the general/old way of setup too.) * The Pi LED will flash patterns as it gets to each stage (labeled in the setup-teslausb-headless script). * 10 flashes means setup failed! - * After the final stage and reboot the LED will go back to normal + * After the final stage and reboot the LED will go back to normal. Remember, the step to remount the filesystem takes a few minutes. + +At this point the next boot should start the Dashcam/music drives like normal. If you're watching the LED it will start flashing every 1 second, which is the archive loop running. + +> NOTE: Don't delete the `TESLAUSB_SETUP_FINISHED` file. This is how the system knows setup is complete. + + + + + +### Image creation TODOs +1. Patch the hostname to teslausb +1. Make it so if someone deletes the `TESLAUSB_SETUP_FINISHED` file it's handled gracefully. +1. I still see some errors during pi-gen about locale, may need to be fixed? stage0/01-locale/debconf en_US.UTF-8 +1. Cache the remount packages? Might mess with first boot like `rsyslog` +1. Any other steps to move into the base image? +1. Aspirational TODO: Remove more packages and set services to stopped to make the boot process faster? #### Modifications to pi-gen builder from master @@ -46,11 +67,4 @@ Built image on a Raspi running Stretch, for maximum Pi-ception. 1. (Yes at this point you could suggest that just putting the end state files in place instead of patching would be good, but why not be idiomatic? :) ) 1. Add a script to flash LEDs 1. Run `sudo ./build.sh` from the `pi-gen` directory. -1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in stage2-stage5 present) and rerun `sudo CLEAN=1 ./build.sh` - -### Image creation TODOs -1. TODO: Patch the hostname to teslausb -1. TODO: I still see some errors during pi-gen about locale, may need to be fixed? stage0/01-locale/debconf en_US.UTF-8 -1. TODO: Cache the remount packages? Might mess with first boot like `rsyslog` -1. Aspirational TODO: Remove more packages etc to make the boot process faster? OR start from `stage1` if we don't need all of `stage2` - +1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in stage2-stage5 present) and rerun `sudo CLEAN=1 ./build.sh` \ No newline at end of file From e94a1aadb8ba5a26da3c4137424479bbb41375b4 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 15:25:44 -0500 Subject: [PATCH 16/67] Slightly more clear readme --- headless-scripts/Readme.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 065b85a..c764c88 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -2,15 +2,10 @@ # This is a WORK IN PROGRESS, SHOULD BE WORKING. -For now the image creation work is at: -* Modified pi-gen [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). -* `headless-patch` branch of [https://github.com/rtgoodwin/teslausb](https://github.com/rtgoodwin/teslausb) ## Notes -* Assumes your Pi comes up on Wifi, with internet access. (But so does most of this guide.) USB networking still enabled for troubleshooting. -* I moved all script downloads and variable creation to the initial setup. At this point, I'm designing it to pull the setup scripts dynamically, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! - * At the very least we could bake in stable first stage headlessBuild scripts for Mac/Linux/Windows. +* Assumes your Pi has access to Wifi, with internet access (during setup). (But all setup methods do currently.) USB networking still enabled for troubleshooting. ## Building the Pi @@ -39,8 +34,11 @@ At this point the next boot should start the Dashcam/music drives like normal. I > NOTE: Don't delete the `TESLAUSB_SETUP_FINISHED` file. This is how the system knows setup is complete. +### Image builder source and patches - +For now the image creation work is at: +* Modified pi-gen [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). +* `headless-patch` branch of [https://github.com/rtgoodwin/teslausb](https://github.com/rtgoodwin/teslausb) ### Image creation TODOs @@ -50,6 +48,7 @@ At this point the next boot should start the Dashcam/music drives like normal. I 1. Cache the remount packages? Might mess with first boot like `rsyslog` 1. Any other steps to move into the base image? 1. Aspirational TODO: Remove more packages and set services to stopped to make the boot process faster? +1. NOTE: I moved all script downloads and variable creation to the initial setup. At this point, I'm designing it to pull the setup scripts dynamically, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! At the very least we could bake in stable first stage headlessBuild scripts for Mac/Linux/Windows. #### Modifications to pi-gen builder from master From 0a4e7da22684c5a42ab0541df51070948cfdc40c Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 15:35:30 -0500 Subject: [PATCH 17/67] Readme updates --- headless-scripts/Readme.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index c764c88..de96d1f 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -1,4 +1,4 @@ -# Flashable image to get started more quick +# Flashable image to get started more quickly # This is a WORK IN PROGRESS, SHOULD BE WORKING. @@ -8,12 +8,20 @@ * Assumes your Pi has access to Wifi, with internet access (during setup). (But all setup methods do currently.) USB networking still enabled for troubleshooting. -## Building the Pi +## Configure the SD card before first boot of the Pi -WORK IN PROGRESS BUT MOSTLY RIGHT. And still shorter than the full process! -1. Flash the image from [here](https://www.dropbox.com/s/zfzjbmx4744q810/image_2018-10-21-teslausb_headless-lite.zip?dl=0) -1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) See the main README for all the variables. +1. Flash the image from [here](https://www.dropbox.com/s/zfzjbmx4744q810/image_2018-10-21-teslausb_headless-lite.zip?dl=0) using Etcher or similar. +1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) See the main README for all the variables. I.e. file should contain at a minimum (replace with your own values): + ``` + export archiveserver=Nautilus + export sharename=SailfishCam + export shareuser=sailfish + export sharepassword=pa$$w0rd + export campercent=100 + export SSID=your_ssid + export WIFIPASS=your_wifi_password + ``` 1. Run the `setup-piForHeadlessBuild.sh` (note: **not** `setup-piForHeadlessSetup.sh`): `curl https://raw.githubusercontent.com/rtgoodwin/teslausb/headless-patch/headless-scripts/setup-piForHeadlessBuild.sh -o setup-piForHeadlessBuild.sh` `chmod +x setup-piForHeadlessBuild.sh` @@ -38,7 +46,7 @@ At this point the next boot should start the Dashcam/music drives like normal. I For now the image creation work is at: * Modified pi-gen [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). -* `headless-patch` branch of [https://github.com/rtgoodwin/teslausb](https://github.com/rtgoodwin/teslausb) +* `headless-patch` branch of rtgoodwin fork [https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts](https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts) ### Image creation TODOs From b80b14e533296c7687b9b03bad3d754a896774b1 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 15:38:55 -0500 Subject: [PATCH 18/67] More readme! --- headless-scripts/Readme.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index de96d1f..8de59da 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -23,9 +23,13 @@ export WIFIPASS=your_wifi_password ``` 1. Run the `setup-piForHeadlessBuild.sh` (note: **not** `setup-piForHeadlessSetup.sh`): -`curl https://raw.githubusercontent.com/rtgoodwin/teslausb/headless-patch/headless-scripts/setup-piForHeadlessBuild.sh -o setup-piForHeadlessBuild.sh` -`chmod +x setup-piForHeadlessBuild.sh` -`./setup-piForHeadlessBuild.sh .` +``` +curl https://raw.githubusercontent.com/rtgoodwin/teslausb/headless-patch/headless-scripts/setup-piForHeadlessBuild.sh -o setup-piForHeadlessBuild.sh + +chmod +x setup-piForHeadlessBuild.sh + +./setup-piForHeadlessBuild.sh +``` 1. If all goes well, put card into Pi and boot. 1. Wait for the the Pi to come up as a CAM USB drive, if you have it plugged into your computer. If not, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. From 09d465a1885101834386f31dc1d1b2db1e83c636 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 15:40:24 -0500 Subject: [PATCH 19/67] Neverending readme updates. --- headless-scripts/Readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 8de59da..30153a1 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -23,13 +23,13 @@ export WIFIPASS=your_wifi_password ``` 1. Run the `setup-piForHeadlessBuild.sh` (note: **not** `setup-piForHeadlessSetup.sh`): -``` -curl https://raw.githubusercontent.com/rtgoodwin/teslausb/headless-patch/headless-scripts/setup-piForHeadlessBuild.sh -o setup-piForHeadlessBuild.sh + ``` + curl https://raw.githubusercontent.com/rtgoodwin/teslausb/headless-patch/headless-scripts/setup-piForHeadlessBuild.sh -o setup-piForHeadlessBuild.sh -chmod +x setup-piForHeadlessBuild.sh + chmod +x setup-piForHeadlessBuild.sh -./setup-piForHeadlessBuild.sh -``` + ./setup-piForHeadlessBuild.sh + ``` 1. If all goes well, put card into Pi and boot. 1. Wait for the the Pi to come up as a CAM USB drive, if you have it plugged into your computer. If not, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. From a3737510332fe12c0cb42d3d43b52c53fc896098 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sun, 21 Oct 2018 15:42:22 -0500 Subject: [PATCH 20/67] So many readme updates --- headless-scripts/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 30153a1..52127ff 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -31,7 +31,7 @@ ./setup-piForHeadlessBuild.sh ``` 1. If all goes well, put card into Pi and boot. -1. Wait for the the Pi to come up as a CAM USB drive, if you have it plugged into your computer. If not, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. +1. Wait for the the Pi to come up as a CAM USB drive, if you have it plugged into your computer. If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. ## What happens under the covers From 1bcca1b8dd36ee333ed43bf0ed20d3a48d1a2476 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Wed, 24 Oct 2018 08:31:16 -0500 Subject: [PATCH 21/67] 10-24 image scripts Tested working for me. --- headless-scripts/Readme.md | 26 +++++------ headless-scripts/setup-teslausb-headless | 44 +++++++++---------- .../teslausb_setup_variables.conf.sample | 10 +++++ 3 files changed, 43 insertions(+), 37 deletions(-) create mode 100644 headless-scripts/teslausb_setup_variables.conf.sample diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 52127ff..5a3e6df 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -11,8 +11,8 @@ ## Configure the SD card before first boot of the Pi -1. Flash the image from [here](https://www.dropbox.com/s/zfzjbmx4744q810/image_2018-10-21-teslausb_headless-lite.zip?dl=0) using Etcher or similar. -1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) See the main README for all the variables. I.e. file should contain at a minimum (replace with your own values): +1. Flash the image from [here (10-24 dated image)](https://www.dropbox.com/s/6f8kxenvtz8pkj9/image_2018-10-24-teslausb_headless-lite.zip?dl=0) using Etcher or similar. +1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) A sample conf file is in this repo. I.e. file should contain at a minimum (replace with your own values): ``` export archiveserver=Nautilus export sharename=SailfishCam @@ -22,29 +22,25 @@ export SSID=your_ssid export WIFIPASS=your_wifi_password ``` -1. Run the `setup-piForHeadlessBuild.sh` (note: **not** `setup-piForHeadlessSetup.sh`): - ``` - curl https://raw.githubusercontent.com/rtgoodwin/teslausb/headless-patch/headless-scripts/setup-piForHeadlessBuild.sh -o setup-piForHeadlessBuild.sh - - chmod +x setup-piForHeadlessBuild.sh - - ./setup-piForHeadlessBuild.sh - ``` -1. If all goes well, put card into Pi and boot. -1. Wait for the the Pi to come up as a CAM USB drive, if you have it plugged into your computer. If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. +* Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5, maybe 6) and then a reboot and/or the CAM to become available on your PC/Mac. +* The Pi should be available at teslausb.local over Wifi (if it works) or USB networking (if it doesn't). Takes about 5 minutes for me. You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success too. +* Currently doesn't create the TeslaCam folder, so you'll need to do that before taking to your car. +* If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. ## What happens under the covers When the Pi boots the first time: * A `/boot/teslausb-headless-setup.log` file will be created and stages logged. This takes the place of the "STOP" commands -* Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. May use a progress system so the script can pick back up if needed. (This is probably useful for the general/old way of setup too.) -* The Pi LED will flash patterns as it gets to each stage (labeled in the setup-teslausb-headless script). +* Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. +* (Working on a progress system so the script can pick back up if needed. This is probably useful for the general/old way of setup too.) +* Wifi is detected by looking for `/boot/WIFI_ENABLED` and if not, creates the `wpa_supplicant.conf` file in place and reboots. +* The Pi LED will flash patterns (2, 3, 4, 5, maybe 6) as it gets to each stage (labeled in the setup-teslausb-headless script). * 10 flashes means setup failed! * After the final stage and reboot the LED will go back to normal. Remember, the step to remount the filesystem takes a few minutes. At this point the next boot should start the Dashcam/music drives like normal. If you're watching the LED it will start flashing every 1 second, which is the archive loop running. -> NOTE: Don't delete the `TESLAUSB_SETUP_FINISHED` file. This is how the system knows setup is complete. +> NOTE: Don't delete the `TESLAUSB_SETUP_FINISHED` or `WIFI_ENABLED` files. This is how the system knows setup is complete. ### Image builder source and patches diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless index b713bf1..f9396d2 100644 --- a/headless-scripts/setup-teslausb-headless +++ b/headless-scripts/setup-teslausb-headless @@ -88,7 +88,7 @@ function check_available_space () { } # function get_ancillary_setup_scripts () { -# pushd /tmp +# pushd # wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh # chmod +x ./create-backingfiles-partition.sh # wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh @@ -111,20 +111,20 @@ BACKINGFILES_MOUNTPOINT=/backingfiles function create_usb_drive_backing_files () { mkdir "$BACKINGFILES_MOUNTPOINT" - /tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" + /root/bin/tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" setup_log "Mounting the partition for the backing files..." mount /backingfiles setup_log "Mounted the partition for the backing files." - /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" + /root/bin/tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" } function configure_archive () { setup_log "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 + echo "//$archive_server_ip_address/$sharename /mnt/archive cifs credentials=/root/.teslaCamArchiveCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab echo "username=$shareuser" > /root/.teslaCamArchiveCredentials echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials @@ -189,20 +189,20 @@ EOF setup_log "Configured rc.local." } -function configure_hostname () { - setup_log "Configuring the hostname..." +# function configure_hostname () { +# setup_log "Configuring the hostname..." - local new_host_name="teslausb" - cp /etc/hosts ~ - sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts +# local new_host_name="teslausb" +# cp /etc/hosts ~ +# sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts - cp /etc/hostname ~ - sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname - setup_log "Configured the hostname." -} +# cp /etc/hostname ~ +# sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname +# setup_log "Configured the hostname." +# } function make_root_fs_readonly () { - /tmp/make-root-fs-readonly.sh + /root/bin/tmp/make-root-fs-readonly.sh } # TURN OFF LED so we can start watching progress @@ -214,13 +214,13 @@ sleep 5 /etc/stage_flash 1 -setup_log "SETUP STAGE 1: Check variables file." -if [ ! -e /boot/teslausb_setup_variables.conf ] -then - setup_log "ERROR: teslausb_setup_variables.conf file not found. Can't continue setup." - /etc/stage_flash 10 - exit 1 -fi +# setup_log "SETUP STAGE 1: Check variables file." +# if [ ! -e /boot/teslausb_setup_variables.conf ] +# then +# setup_log "ERROR: teslausb_setup_variables.conf file not found. Can't continue setup." +# /etc/stage_flash 10 +# exit 1 +# fi source /boot/teslausb_setup_variables.conf @@ -267,7 +267,7 @@ configure_archive configure_rc_local -configure_hostname +# configure_hostname # SETUP STAGE 5 and reboot # If you see 5 flashes we are probably good! diff --git a/headless-scripts/teslausb_setup_variables.conf.sample b/headless-scripts/teslausb_setup_variables.conf.sample new file mode 100644 index 0000000..aae9f34 --- /dev/null +++ b/headless-scripts/teslausb_setup_variables.conf.sample @@ -0,0 +1,10 @@ +export archiveserver=your_archive_name_or_ip +export sharename=your_archive_share_name +export shareuser=username +export sharepassword=password +export campercent=100 +export SSID=your_ssid +export WIFIPASS=your_pass +# export pushover_enabled=false +# export pushover_user_key=user_key +# export pushover_app_key=app_key \ No newline at end of file From 331fc9c4bd6c0694b52e370805bf656c5ebc656f Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Wed, 24 Oct 2018 08:32:13 -0500 Subject: [PATCH 22/67] Note about Pushover --- headless-scripts/Readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 5a3e6df..511dafd 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -21,7 +21,11 @@ export campercent=100 export SSID=your_ssid export WIFIPASS=your_wifi_password + # export pushover_enabled=false + # export pushover_user_key=user_key + # export pushover_app_key=app_key ``` + (Pushover should be working but commented out by default.) * Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5, maybe 6) and then a reboot and/or the CAM to become available on your PC/Mac. * The Pi should be available at teslausb.local over Wifi (if it works) or USB networking (if it doesn't). Takes about 5 minutes for me. You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success too. * Currently doesn't create the TeslaCam folder, so you'll need to do that before taking to your car. From a4ca3d8a6f5941342e6498ccbf23f615308a2c75 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Wed, 24 Oct 2018 08:42:50 -0500 Subject: [PATCH 23/67] Slight readme update --- headless-scripts/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 511dafd..fbbeb3e 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -27,7 +27,7 @@ ``` (Pushover should be working but commented out by default.) * Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5, maybe 6) and then a reboot and/or the CAM to become available on your PC/Mac. -* The Pi should be available at teslausb.local over Wifi (if it works) or USB networking (if it doesn't). Takes about 5 minutes for me. You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success too. +* The Pi should be available at `teslausb.local` over Wifi (if it works) or USB networking (if it doesn't). Takes about 5 minutes for me. You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success too. * Currently doesn't create the TeslaCam folder, so you'll need to do that before taking to your car. * If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. From bda9ef4c22fe3653e352cda0a99485144563c4bd Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Wed, 24 Oct 2018 08:51:08 -0500 Subject: [PATCH 24/67] Note experimental image in README Just to get more visibility/testing. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 6f3c49e..901a5d7 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,10 @@ There are three phases to setting up the Pi: 2. Use Etcher to write the zip file you downloaded to the SD card. Etcher works well and is multi-platform. > Note: you don't need to uncompress the zip file you downloaded. +#### (Experimental) + +There is an experimental image that requires only a configuration file. Needs testing and issues filed _on this specific image/process_ at [this repo](https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts). Issues about general functionality should still be filed on the main (cimryan) repo. + ### 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). From 2da60f4351768c3a0dc35543f910eb336985d517 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Wed, 24 Oct 2018 08:53:53 -0500 Subject: [PATCH 25/67] Dropbox instructions --- headless-scripts/Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 511dafd..94edace 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -11,7 +11,7 @@ ## Configure the SD card before first boot of the Pi -1. Flash the image from [here (10-24 dated image)](https://www.dropbox.com/s/6f8kxenvtz8pkj9/image_2018-10-24-teslausb_headless-lite.zip?dl=0) using Etcher or similar. +1. Flash the image from [here (10-24 dated image)](https://www.dropbox.com/s/6f8kxenvtz8pkj9/image_2018-10-24-teslausb_headless-lite.zip?dl=0) using Etcher or similar. (Be sure to click the `...` on Dropbox and download the `.zip` file.) 1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) A sample conf file is in this repo. I.e. file should contain at a minimum (replace with your own values): ``` export archiveserver=Nautilus @@ -78,4 +78,4 @@ Built image on a Raspi running Stretch, for maximum Pi-ception. 1. (Yes at this point you could suggest that just putting the end state files in place instead of patching would be good, but why not be idiomatic? :) ) 1. Add a script to flash LEDs 1. Run `sudo ./build.sh` from the `pi-gen` directory. -1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in stage2-stage5 present) and rerun `sudo CLEAN=1 ./build.sh` \ No newline at end of file +1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in stage2-stage5 present) and rerun `sudo CLEAN=1 ./build.sh` From 4deb1c35b8473f3086fa43e39fa175145d75d39b Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Thu, 25 Oct 2018 12:46:10 -0700 Subject: [PATCH 26/67] add rclone configuration option in main setup script --- setup/pi/setup-teslausb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 1b208ce..b4bf97e 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -119,6 +119,11 @@ function configure_archive_scripts () { get_script /root/bin archive-clips.sh run/rsync_archive get_script /root/bin connect-archive.sh run/rsync_archive get_script /root/bin disconnect-archive.sh run/rsync_archive + elif [ $RCLONE_ENABLE = true ] + then + get_script /root/bin archive-clips.sh run/rclone_archive + get_script /root/bin connect-archive.sh run/rclone_archive + get_script /root/bin disconnect-archive.sh run/rclone_archive else get_script /root/bin archive-clips.sh run/cifs_archive get_script /root/bin connect-archive.sh run/cifs_archive @@ -181,6 +186,7 @@ function make_root_fs_readonly () { echo "Verifying environment variables..." RSYNC_ENABLE="${RSYNC_ENABLE:-false}" +RCLONE_ENABLE="${RCLONE_ENABLE:-false}" if [ "$RSYNC_ENABLE" = true ] then @@ -188,6 +194,12 @@ then check_variable "RSYNC_SERVER" export archiveserver="$RSYNC_SERVER" check_variable "RSYNC_PATH" +elif [ "$RCLONE_ENABLE" = true ] +then + check_variable "RCLONE_DRIVE" + check_variable "RCLONE_PATH" + # since it's a cloud hosted drive we'll just set this to google dns + export archiveserver="8.8.8.8" else # Else for now, TODO allow both for more redundancy? check_variable "sharename" check_variable "shareuser" @@ -210,6 +222,10 @@ if [ "$RSYNC_ENABLE" = true ] then get_script /root/bin verify-archive-configuration.sh run/rsync_archive get_script /root/bin configure-archive.sh run/rsync_archive +elif [ "$RCLONE_ENABLE" = true ] +then + get_script /root/bin verify-archive-configuration.sh run/clone_archive + get_script /root/bin configure-archive.sh run/rclone_archive else get_script /root/bin verify-archive-configuration.sh run/cifs_archive get_script /root/bin configure-archive.sh run/cifs_archive From 9bb8f1e0463cf5886e17c921ee6d6644b4051a22 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Thu, 25 Oct 2018 15:18:06 -0700 Subject: [PATCH 27/67] adding support and documentation for using rclone --- README.md | 3 + doc/SetupRClone.md | 85 +++++++++++++++++++ run/rclone_archive/archive-clips.sh | 20 +++++ run/rclone_archive/configure-archive.sh | 10 +++ run/rclone_archive/connect-archive.sh | 2 + run/rclone_archive/disconnect-archive.sh | 2 + .../verify-archive-configuration.sh | 1 + 7 files changed, 123 insertions(+) create mode 100644 doc/SetupRClone.md create mode 100644 run/rclone_archive/archive-clips.sh create mode 100644 run/rclone_archive/configure-archive.sh create mode 100644 run/rclone_archive/connect-archive.sh create mode 100644 run/rclone_archive/disconnect-archive.sh create mode 100644 run/rclone_archive/verify-archive-configuration.sh diff --git a/README.md b/README.md index fa902c4..40f525f 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,9 @@ Get the IP address of the archive machine. You'll need this later, so write it d 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. +### Hosting via rclone (for Google Drive, S3, DropBox, etc) +**EXPERIMENTAL** - This hasn't been thoroughly tested yet but you can follow these [instructions](/doc/SetupRClone.md) and give it a spin. + ### ***TODO: Other hosting solutions*** ## Set up the Raspberry Pi diff --git a/doc/SetupRClone.md b/doc/SetupRClone.md new file mode 100644 index 0000000..e4aaa55 --- /dev/null +++ b/doc/SetupRClone.md @@ -0,0 +1,85 @@ +# Introduction + +This guide will show you how to install and configure [rclone4pi](https://github.com/pageauc/rclone4pi/wiki) (based off [rclone](https://rclone.org/)) to archive your saved TeslaCam footage on a number of different remote storage services including (Google Drive, S3 and Dropbox). + +This guide assumes you have **NOT** run the `setup-teslacam` script yet + +# Step 1: Install rclone4pi + +The first step is to get the [rclone4pi](https://github.com/pageauc/rclone4pi/wiki) binary installed on the raspberry pi. You can do this by executing the following command: + + +``` +curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash +``` + +You can also install the script manually by following these [instructions](https://github.com/pageauc/rclone4pi/wiki#manual-install). + + +Once installed, the script will install rclone-install.sh, rclone-sync.sh and create a subfolder rpi-sync in users home eg. /home/pi + +# Step 2: Configure rclone storage system + +Next, run this command as root to configure a storage system. + +``` +rclone config +``` + +**Important:** Run this as root since archiveloop runs as root and the rclone config is bound to the user running the config. + +This will launch an interactive setup with a series of questions. I highly recommend you look at the documents for your storage system by going to [rclone](https://rclone.org/) and selecting your storage system from the pull down menu at the stop. + +I've only personally tested this with Google Drive using these [instructions](https://rclone.org/drive/). One thing to note is the importance of setting the correct [scope](https://rclone.org/drive/#scopes) you are providing access to. Carefully read the documentation on [scopes on rclone](https://rclone.org/drive/#scopes) as well as [Google Drive](https://developers.google.com/drive/api/v3/about-auth). I recommend going with drive.file scope. + +**Important:** Take note of the name you used for this config. You will need it later. The rest of the document will use `gdrive` as the name since that's what I used. + +# Step 3: Verify and create storage directory + +Run the following command (again, as root) to see the name of the remote drive you just created. + +``` +rclone listremotes +``` + +If you don't see the name there, something went wrong and you'll likely have to go back through the config process. If all went well, use + + +``` +rclone lsd gdrive: +``` + +At this point, you should not see anything if you set your scope correctly. Now we need to create a folder to put all our archives in. You can do this by running this command. I used TeslaCam but you can name it whatever you want as long as you set it in the next step below. + +``` +rclone mkdir gdrive:TeslaCam +``` + +Run this one last command again + +``` +rclone lsd gdrive: +``` + +Once you confirm that the directoy you just created is there, we're all set to move on! + +# Step 4: Exports + +To be able to configure the teslausb pi to use rclone, you'll need to export a few things. On your teslausb pi, run: + +``` +export RCLONE_ENABLE=true +export RCLONE_DRIVE= +export RCLONE_PATH= +``` + +An example of my config is listed below: + +``` +export RCLONE_ENABLE=true +export RCLONE_DRIVE=gdrive +export RCLONE_PATH=TeslaCam +``` +**Note:** `RCLONE_ENABLE=true` is going to disable the default archive server. It also will **not** play nicely with `RSYNC_ENABLE=true` 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 diff --git a/run/rclone_archive/archive-clips.sh b/run/rclone_archive/archive-clips.sh new file mode 100644 index 0000000..6b761d5 --- /dev/null +++ b/run/rclone_archive/archive-clips.sh @@ -0,0 +1,20 @@ +#!/bin/bash -eu + +log "Moving clips to rclone archive..." + +source /root/.teslaCamRcloneConfig + +NUM_FILES_MOVED=0 + +for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do + [ -e "$file_name" ] || continue + log "Moving $file_name ..." + rclone move "$file_name" "$drive:$path" >> "$LOG_FILE" 2>&1 || echo "" + log "Moved $file_name." + NUM_FILES_MOVED=$((NUM_FILES_MOVED + 1)) +done +log "Moved $NUM_FILES_MOVED file(s)." + +/root/bin/send-pushover "$NUM_FILES_MOVED" + +log "Finished moving clips to rclone archive" \ No newline at end of file diff --git a/run/rclone_archive/configure-archive.sh b/run/rclone_archive/configure-archive.sh new file mode 100644 index 0000000..13e291b --- /dev/null +++ b/run/rclone_archive/configure-archive.sh @@ -0,0 +1,10 @@ +#!/bin/bash -eu + +function configure_archive () { + echo "Configuring the archive for Rclone..." + + echo "drive=$RCLONE_DRIVE" > /root/.teslaCamRcloneConfig + echo "path=$RCLONE_PATH" >> /root/.teslaCamRcloneConfig +} + +configure_archive \ No newline at end of file diff --git a/run/rclone_archive/connect-archive.sh b/run/rclone_archive/connect-archive.sh new file mode 100644 index 0000000..cfcbd8e --- /dev/null +++ b/run/rclone_archive/connect-archive.sh @@ -0,0 +1,2 @@ +#!/bin/bash -eu +# Nothing to do. \ No newline at end of file diff --git a/run/rclone_archive/disconnect-archive.sh b/run/rclone_archive/disconnect-archive.sh new file mode 100644 index 0000000..cfcbd8e --- /dev/null +++ b/run/rclone_archive/disconnect-archive.sh @@ -0,0 +1,2 @@ +#!/bin/bash -eu +# Nothing to do. \ No newline at end of file diff --git a/run/rclone_archive/verify-archive-configuration.sh b/run/rclone_archive/verify-archive-configuration.sh new file mode 100644 index 0000000..95dbbf8 --- /dev/null +++ b/run/rclone_archive/verify-archive-configuration.sh @@ -0,0 +1 @@ +#!/bin/bash -eu \ No newline at end of file From 00d77474b12f0b1135867083c1d1c8b1f1513e4a Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Thu, 25 Oct 2018 15:27:17 -0700 Subject: [PATCH 28/67] bug fix: script tries to create a filename 0 when files sent is 0 --- run/send-pushover | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/send-pushover b/run/send-pushover index 9d5ffa5..7fc5402 100644 --- a/run/send-pushover +++ b/run/send-pushover @@ -7,7 +7,7 @@ function log () { echo "$1" >> "$LOG_FILE" } -if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $NUM_FILES_MOVED > 0 ] +if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $NUM_FILES_MOVED -gt 0 ] then log "Sending Pushover message for moved files." From 78194641d44ea5822de8350b3b02d518b85e52c9 Mon Sep 17 00:00:00 2001 From: cimryan Date: Thu, 25 Oct 2018 19:00:41 -0700 Subject: [PATCH 29/67] making suggested change Co-Authored-By: rtanaka --- setup/pi/setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 65e25dd..f608edf 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -224,7 +224,7 @@ then get_script /root/bin configure-archive.sh run/rsync_archive elif [ "$RCLONE_ENABLE" = true ] then - get_script /root/bin verify-archive-configuration.sh run/clone_archive + get_script /root/bin verify-archive-configuration.sh run/rclone_archive get_script /root/bin configure-archive.sh run/rclone_archive else get_script /root/bin verify-archive-configuration.sh run/cifs_archive From 485cec4e413632d8527032ea529d927463f13a09 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Fri, 26 Oct 2018 01:41:15 -0700 Subject: [PATCH 30/67] explicitly adding config file path since it is throwing errors --- run/rclone_archive/archive-clips.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/rclone_archive/archive-clips.sh b/run/rclone_archive/archive-clips.sh index 6b761d5..9f95c01 100644 --- a/run/rclone_archive/archive-clips.sh +++ b/run/rclone_archive/archive-clips.sh @@ -9,7 +9,7 @@ NUM_FILES_MOVED=0 for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do [ -e "$file_name" ] || continue log "Moving $file_name ..." - rclone move "$file_name" "$drive:$path" >> "$LOG_FILE" 2>&1 || echo "" + rclone --config /root/.config/rclone/rclone.conf move "$file_name" "$drive:$path" >> "$LOG_FILE" 2>&1 || echo "" log "Moved $file_name." NUM_FILES_MOVED=$((NUM_FILES_MOVED + 1)) done From 3a03382075e2f72306fec01d9d67262fd1c297d6 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 07:27:26 -0500 Subject: [PATCH 31/67] Reworking main setup script Main setup script rework to support headless --- setup/pi/setup-teslausb | 102 +++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 32 deletions(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 6e64ee8..635a4ca 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -1,22 +1,56 @@ #!/bin/bash -eu USER_ENABLED_PUSHOVER=false - +SETUP_LOGFILE=/boot/teslausb-headless-setup.log REPO=${REPO:-cimryan} - BRANCH=${BRANCH:-master} +HEADLESS_SETUP=${HEADLESS_SETUP:-false} +REPO=rtgoodwin +BRANCH=headless-patch + if ! [ $(id -u) = 0 ] then - echo "STOP: Run sudo -i." + setup_progress "STOP: Run sudo -i." exit 1 fi +function setup_progress () { + if [ $HEADLESS_SETUP = "true" ] + echo "$( date ) : $1" >> "$SETUP_LOGFILE" + else + echo $1 + fi +} + + +function headless_mark_setup_failed () { + setup_log "ERROR: Setup Failed." + touch /boot/TESLAUSB_SETUP_FAILED +} + +function headless_mark_setup_success () { + if [ -e /boot/TESLAUSB_SETUP_FAILED ] + then + rm /boot/TESLAUSB_SETUP_FAILED + fi + rm /boot/TESLAUSB_SETUP_STARTED + touch /boot/TESLAUSB_SETUP_FINISHED + setup_log "Main setup completed. Remounting file systems read only." +} + +function headless_progress_flash () { + if [ $HEADLESS_SETUP = "true" ] + then + /etc/stage_flash $1 + fi +} + function check_variable () { local var_name="$1" if [ -z "${!var_name+x}" ] then - echo "STOP: Define the variable $var_name like this: export $var_name=value" + setup_progress "STOP: Define the variable $var_name like this: export $var_name=value" exit 1 fi } @@ -26,36 +60,36 @@ function check_pushover_enabled () { then if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] then - echo "STOP: You're trying to setup Pushover but didn't provide your User and/or App key." - echo "Define the variables like this:" - echo "export pushover_user_key=put_your_userkey_here" - echo "export pushover_app_key=put_your_appkey_here" + setup_progress "STOP: You're trying to setup Pushover but didn't provide your User and/or App key." + setup_progress "Define the variables like this:" + setup_progress "export pushover_user_key=put_your_userkey_here" + setup_progress "export pushover_app_key=put_your_appkey_here" exit 1 elif [ "${pushover_user_key}" = "put_your_userkey_here" ] || [ "${pushover_app_key}" = "put_your_appkey_here" ] then - echo "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." + setup_progress "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." exit 1 else USER_ENABLED_PUSHOVER=true - echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials - echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials - echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials + setup_progress "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials + setup_progress "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials + setup_progress "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials fi fi } function check_available_space () { - echo "Verifying that there is sufficient space available on the MicroSD card..." + setup_progress "Verifying that there is sufficient space available on the MicroSD card..." local available_space="$( parted -m /dev/mmcblk0 u b print free | tail -1 | cut -d ":" -f 4 | sed 's/B//g' )" if [ "$available_space" -lt 4294967296 ] then - echo "STOP: The MicroSD card is too small." + setup_progress "STOP: The MicroSD card is too small." exit 1 fi - echo "There is sufficient space available." + setup_progress "There is sufficient space available." } function get_script () { @@ -75,11 +109,11 @@ function get_ancillary_setup_scripts () { function fix_cmdline_txt_modules_load () { - echo "Fixing the modules-load parameter in /boot/cmdline.txt..." + setup_progress "Fixing the modules-load parameter in /boot/cmdline.txt..." cp /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." + setup_progress "Fixed cmdline.txt." } BACKINGFILES_MOUNTPOINT=/backingfiles @@ -97,9 +131,9 @@ function create_usb_drive_backing_files () { if ! findmnt --mountpoint $BACKINGFILES_MOUNTPOINT then - echo "Mounting the partition for the backing files..." + setup_progress "Mounting the partition for the backing files..." mount $BACKINGFILES_MOUNTPOINT - echo "Mounted the partition for the backing files." + setup_progress "Mounted the partition for the backing files." fi if [ ! -e $BACKINGFILES_MOUNTPOINT/*.bin ] @@ -109,7 +143,7 @@ function create_usb_drive_backing_files () { } function configure_archive_scripts () { - echo "Configuring the archive scripts..." + setup_progress "Configuring the archive scripts..." get_script /root/bin archiveloop run @@ -126,7 +160,7 @@ function configure_archive_scripts () { get_script /root/bin remountfs_rw run - echo "Configured the archive scripts." + setup_progress "Configured the archive scripts." } function configure_pushover_scripts() { @@ -139,7 +173,7 @@ function configure_rc_local () { return fi - echo "Configuring /etc/rc.local to run the archive scripts at startup..." + setup_progress "Configuring /etc/rc.local to run the archive scripts at startup..." echo "#!/bin/bash -eu" > ~/rc.local echo "archiveserver=\"${archiveserver}\"" >> ~/rc.local cat << 'EOF' >> ~/rc.local @@ -158,26 +192,30 @@ EOF cat ~/rc.local > /etc/rc.local rm ~/rc.local - echo "Configured rc.local." + setup_progress "Configured rc.local." } function configure_hostname () { - echo "Configuring the hostname..." + # Headless image already has hostname set + if [ ! $HEADLESS_SETUP = "true" ] + then + setup_progress "Configuring the hostname..." - local new_host_name="teslausb" - cp /etc/hosts ~ - sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts + local new_host_name="teslausb" + cp /etc/hosts ~ + sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts - cp /etc/hostname ~ - sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname - echo "Configured the hostname." + cp /etc/hostname ~ + sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname + setup_progress "Configured the hostname." + fi } function make_root_fs_readonly () { /tmp/make-root-fs-readonly.sh } -echo "Verifying environment variables..." +setup_progress "Verifying environment variables..." RSYNC_ENABLE="${RSYNC_ENABLE:-false}" @@ -240,7 +278,7 @@ create_usb_drive_backing_files configure_rc_local configure_hostname - +headless_mark_setup_success make_root_fs_readonly echo "All done." From 11b3f510a58af9e56ff13df0b49e2670180cd2b5 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 07:53:42 -0500 Subject: [PATCH 32/67] Variable checks in case populated in conf file --- setup/pi/setup-teslausb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 635a4ca..5eadefd 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -1,12 +1,10 @@ #!/bin/bash -eu -USER_ENABLED_PUSHOVER=false +USER_ENABLED_PUSHOVER=${USER_ENABLED_PUSHOVER:-false} SETUP_LOGFILE=/boot/teslausb-headless-setup.log REPO=${REPO:-cimryan} BRANCH=${BRANCH:-master} HEADLESS_SETUP=${HEADLESS_SETUP:-false} -REPO=rtgoodwin -BRANCH=headless-patch if ! [ $(id -u) = 0 ] @@ -17,12 +15,19 @@ fi function setup_progress () { if [ $HEADLESS_SETUP = "true" ] + then echo "$( date ) : $1" >> "$SETUP_LOGFILE" - else - echo $1 fi + echo $1 } +function headless_populate_variables () { + # Pull in the conf file variables to make avail to this script and subscripts + if [ -e /boot/teslausb_setup_variables.conf ] && [ $HEADLESS_SETUP = "true" ] + then + source /boot/teslausb_setup_variables.conf + fi +} function headless_mark_setup_failed () { setup_log "ERROR: Setup Failed." From 065ddfb24dcf69b8ab8398f846eb7d7701389533 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 07:59:12 -0500 Subject: [PATCH 33/67] Better naming of headless_setup functions --- setup/pi/setup-teslausb | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 5eadefd..e51addb 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -21,7 +21,7 @@ function setup_progress () { echo $1 } -function headless_populate_variables () { +function headless_setup_populate_variables () { # Pull in the conf file variables to make avail to this script and subscripts if [ -e /boot/teslausb_setup_variables.conf ] && [ $HEADLESS_SETUP = "true" ] then @@ -29,22 +29,30 @@ function headless_populate_variables () { fi } -function headless_mark_setup_failed () { - setup_log "ERROR: Setup Failed." - touch /boot/TESLAUSB_SETUP_FAILED -} - -function headless_mark_setup_success () { - if [ -e /boot/TESLAUSB_SETUP_FAILED ] +function headless_setup_mark_setup_failed () { + if [ $HEADLESS_SETUP = "true" ] then - rm /boot/TESLAUSB_SETUP_FAILED + setup_log "ERROR: Setup Failed." + touch /boot/TESLAUSB_SETUP_FAILED fi - rm /boot/TESLAUSB_SETUP_STARTED - touch /boot/TESLAUSB_SETUP_FINISHED - setup_log "Main setup completed. Remounting file systems read only." } -function headless_progress_flash () { +function headless_setup_mark_setup_success () { + if [ $HEADLESS_SETUP = "true" ] + then + + if [ -e /boot/TESLAUSB_SETUP_FAILED ] + then + rm /boot/TESLAUSB_SETUP_FAILED + fi + + rm /boot/TESLAUSB_SETUP_STARTED + touch /boot/TESLAUSB_SETUP_FINISHED + setup_log "Main setup completed. Remounting file systems read only." + fi +} + +function headless_setup_progress_flash () { if [ $HEADLESS_SETUP = "true" ] then /etc/stage_flash $1 @@ -220,6 +228,8 @@ function make_root_fs_readonly () { /tmp/make-root-fs-readonly.sh } +headless_setup_populate_variables + setup_progress "Verifying environment variables..." RSYNC_ENABLE="${RSYNC_ENABLE:-false}" @@ -283,7 +293,9 @@ create_usb_drive_backing_files configure_rc_local configure_hostname -headless_mark_setup_success + +headless_setup_mark_setup_success + make_root_fs_readonly echo "All done." From 1bf8e642bfe1e53470581f5d780ad4510270ca26 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 08:48:56 -0500 Subject: [PATCH 34/67] Typo in function name. --- headless-scripts/setup-teslausb-headless | 4 ++-- setup/pi/setup-teslausb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless index f9396d2..8c8112f 100644 --- a/headless-scripts/setup-teslausb-headless +++ b/headless-scripts/setup-teslausb-headless @@ -3,7 +3,7 @@ REPO=rtgoodwin BRANCH="headless-patch" user_enabled_pushover=false -LOGFILE=/boot/teslausb-headless-setup.log +SETUP_LOGFILE=/boot/teslausb-headless-setup.log setup_complete=false # if ! [ $(id -u) = 0 ] @@ -12,7 +12,7 @@ setup_complete=false # exit 1 # fi -function setup_log () { +function setup_progress () { echo "$( date ) : $1" >> "$LOGFILE" } diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index e51addb..8f09d69 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -32,7 +32,7 @@ function headless_setup_populate_variables () { function headless_setup_mark_setup_failed () { if [ $HEADLESS_SETUP = "true" ] then - setup_log "ERROR: Setup Failed." + setup_progress "ERROR: Setup Failed." touch /boot/TESLAUSB_SETUP_FAILED fi } @@ -48,7 +48,7 @@ function headless_setup_mark_setup_success () { rm /boot/TESLAUSB_SETUP_STARTED touch /boot/TESLAUSB_SETUP_FINISHED - setup_log "Main setup completed. Remounting file systems read only." + setup_progress "Main setup completed. Remounting file systems read only." fi } From e15506681d1233eab9a7e445622eaf124de54c0b Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 09:06:37 -0500 Subject: [PATCH 35/67] Extra checks for whether to send push --- run/cifs_archive/archive-clips.sh | 3 +++ run/send-pushover | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/run/cifs_archive/archive-clips.sh b/run/cifs_archive/archive-clips.sh index c7523a5..2816065 100644 --- a/run/cifs_archive/archive-clips.sh +++ b/run/cifs_archive/archive-clips.sh @@ -19,6 +19,9 @@ for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do done log "Moved $NUM_FILES_MOVED file(s)." +if [ $NUM_FILES_MOVED -gt 0 ] +then /root/bin/send-pushover "$NUM_FILES_MOVED" +fi log "Finished moving clips to archive." diff --git a/run/send-pushover b/run/send-pushover index 9d5ffa5..7fc5402 100644 --- a/run/send-pushover +++ b/run/send-pushover @@ -7,7 +7,7 @@ function log () { echo "$1" >> "$LOG_FILE" } -if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $NUM_FILES_MOVED > 0 ] +if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $NUM_FILES_MOVED -gt 0 ] then log "Sending Pushover message for moved files." From 31d19b7c0023ffeab0e87dea56d4274922b6c8c9 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 09:28:49 -0500 Subject: [PATCH 36/67] Removed unneeded scripts --- headless-scripts/setup-piForHeadlessBuild.sh | 252 ---------------- headless-scripts/setup-teslausb-headless | 284 ------------------ .../teslausb_setup_variables.conf.sample | 3 + 3 files changed, 3 insertions(+), 536 deletions(-) delete mode 100755 headless-scripts/setup-piForHeadlessBuild.sh delete mode 100644 headless-scripts/setup-teslausb-headless diff --git a/headless-scripts/setup-piForHeadlessBuild.sh b/headless-scripts/setup-piForHeadlessBuild.sh deleted file mode 100755 index 3dcc0df..0000000 --- a/headless-scripts/setup-piForHeadlessBuild.sh +++ /dev/null @@ -1,252 +0,0 @@ -#/bin/bash -eu - -# This script will modify the cmdline.txt file on a freshly flashed Raspbian Stretch/Lite -# It readies it for SSH, USB OTG, USB networking, and Wifi -# -# Pass it the path to the location at which the "boot" filesystem is mounted. -# E.g. on a Mac: -# ./setup-piForHeadlessConfig.sh /Volumes/boot -# or on Ubuntu: -# ./setup-piForHeadlessConfig.sh /media/$USER/boot -# cd /Volumes/boot (or wherever the boot folder is mounted) -# chmod +x setup-piForHeadlessConfig.sh -# ./setup-piForHeadlessConfig.sh -# -# Put the card in your Pi, and reboot! - -# Creates the ssh file if needed, since Raspbian now disables -# ssh by default if the file isn't present - -BOOT_DIR="$1" -RED='\033[0;31m' # Red for warning -NC='\033[0m' # No Color -GREEN='\033[0;32m' -scripts_downloaded=false -REPO=rtgoodwin -BRANCH=headless-patch - -function stop_message () { - echo -e "${RED}${1} ${NC}" -} - -function good_message () { - echo -e "${GREEN}${1} ${NC}" -} - -function show_setup_var_instructions () { - - stop_message 'STOP: You need to specify your setup variables first. Create the file "teslausb_setup_variables.conf" with: ' - echo "" - echo ' export archiveserver=Nautilus' - echo ' export sharename=SailfishCam' - echo ' export shareuser=sailfish' - echo ' export sharepassword=pa$$w0rd' - echo ' export campercent=100' - echo "" - echo "Be sure to replace the values with your relevant choices." - exit 1 - -} - -function verify_file_exists () { - local file_name="$1" - local expected_path="$2" - - if [ ! -e "$expected_path/$file_name" ] - then - stop_message "STOP: Didn't find $file_name at $expected_path." - exit 1 - fi -} - -function verify_setup_file_exists () { - local file_name="$1" - - if [ -e "$file_name" ] - then - good_message "Downloaded $file_name." - else - stop_message "STOP: Didn't find downloaded script $file_name. Try running the setup script again." - exit 1 - fi -} - -function verify_wifi_variables () { - if [ ! -n "${SSID+x}" ] || [ ! -n "${WIFIPASS+x}" ] - then - stop_message 'STOP: You need to specify your wifi name and password first. Run: ' - echo "" - echo ' export SSID=your_ssid' - echo ' export WIFIPASS=your_wifi_password' - echo "" - echo "Be sure to replace the values with your SSID (network name) and password." - exit 1 - fi -} - -function verify_setup_variables_file_exists () { - local file_name="$1" - local expected_path="$2" - - if [ ! -e "$expected_path/$file_name" ] - then - show_setup_var_instructions - exit 1 - fi -} - -function verify_setup_variables () { - if [ ! -n "${archiveserver+x}" ] - then - show_setup_var_instructions - fi -} - -function verify_pushover_variables () { - if [ ! -z "${pushover_enabled+x}" ] - then - if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] - then - stop_message "STOP: You're trying to setup Pushover but didn't provide your User and/or App key." - echo 'Define the variables in "teslausb_setup_variables.conf" like this:' - echo "" - echo " export pushover_user_key=put_your_userkey_here" - echo " export pushover_app_key=put_your_appkey_here" - exit 1 - elif [ "${pushover_user_key}" = "put_your_userkey_here" ] || [ "${pushover_app_key}" = "put_your_appkey_here" ] - then - stop_message "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." - echo 'Replace the default values in "teslausb_setup_variables.conf".' - exit 1 - else - user_enabled_pushover=true - echo "export pushover_enabled=true" > $BOOT_DIR/.teslaCamPushoverCredentials - echo "export pushover_user_key=$pushover_user_key" >> $BOOT_DIR/.teslaCamPushoverCredentials - echo "export pushover_app_key=$pushover_app_key" >> $BOOT_DIR/.teslaCamPushoverCredentials - fi - fi -} - -function download_scripts () { - - if [ ! -d "${BOOT_DIR}/teslausb_setup_scripts" ] - then - mkdir "${BOOT_DIR}/teslausb_setup_scripts" - # stop_message "ERROR: Failed to make teslausb_setup_scripts and download setup scripts. Ensure you have internet access and run this script again." - fi - cd "${BOOT_DIR}/teslausb_setup_scripts" - curl -s -o setup-teslausb-headless https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/headless-scripts/setup-teslausb-headless - verify_setup_file_exists "setup-teslausb-headless" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x setup-teslausb-headless - good_message "Downloaded main setup script." - - curl -s -o archiveloop https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archiveloop - # sed s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/ ~/archiveloop > /root/bin/archiveloop - sed -i'.bak' -e "s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/" archiveloop - verify_setup_file_exists "archiveloop" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x archiveloop - - curl -s -o archive-teslacam-clips https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips - verify_setup_file_exists "archive-teslacam-clips" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x archive-teslacam-clips - good_message "Configured the archive scripts." - - curl -s -o remountfs_rw https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw - verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x remountfs_rw - good_message "Downloaded script to remount filesystems read/write if needed (/root/bin/remountfs_rw)." - - if [ ${user_enabled_pushover} = "true" ] - then - curl -s -o send-pushover https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover - verify_setup_file_exists "remountfs_rw" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x send-pushover - good_message "Downloaded Pushover notification script." - fi - - good_message "Downloading ancillary setup scripts." - curl -s -o create-backingfiles-partition.sh https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh - verify_setup_file_exists "create-backingfiles-partition.sh" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x create-backingfiles-partition.sh - curl -s -o create-backingfiles.sh https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh - verify_setup_file_exists "create-backingfiles.sh" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x create-backingfiles.sh - curl -s -o make-root-fs-readonly.sh https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh - verify_setup_file_exists "make-root-fs-readonly.sh" "${BOOT_DIR}/teslausb_setup_scripts" - chmod +x make-root-fs-readonly.sh - cd - - good_message "All scripts downloaded and configured." - -} - -verify_file_exists "cmdline.txt" "$BOOT_DIR" -verify_file_exists "config.txt" "$BOOT_DIR" -verify_setup_variables_file_exists "teslausb_setup_variables.conf" "$BOOT_DIR" - -source "$BOOT_DIR"/teslausb_setup_variables.conf - -verify_wifi_variables -verify_setup_variables -verify_pushover_variables - -CMDLINE_TXT_PATH="$BOOT_DIR/cmdline.txt" -CONFIG_TXT_PATH="$BOOT_DIR/config.txt" - -if ! grep -q "dtoverlay=dwc2" $CONFIG_TXT_PATH -then - good_message "Updating $CONFIG_TXT_PATH ..." - echo "" >> "$CONFIG_TXT_PATH" - echo "dtoverlay=dwc2" >> "$CONFIG_TXT_PATH" -else - good_message "config.txt already contains the required dwc2 module" -fi - -if ! grep -q "dwc2,g_ether" $CMDLINE_TXT_PATH -then - echo "Updating $CMDLINE_TXT_PATH ..." - sed -i'.bak' -e "s/rootwait/rootwait modules-load=dwc2,g_ether/" -e "s@ init=/usr/lib/raspi-config/init_resize.sh@@" "$CMDLINE_TXT_PATH" -else - good_message "cmdline.txt already updated with modules and removed initial resize script." -fi - -if [ ! -e "$BOOT_DIR/ssh" ] -then - good_message "Ensuring SSH is setup..." - touch "$BOOT_DIR/ssh" -fi - -# Sets up wifi credentials so wifi will be -# auto configured on first boot - -WPA_SUPPLICANT_CONF_PATH="$BOOT_DIR/wpa_supplicant.conf" - -good_message "Adding Wifi setup file (wpa_supplicant.conf)." -if [ -r "$WPA_SUPPLICANT_CONF_PATH" ] -then - rm "$WPA_SUPPLICANT_CONF_PATH" -fi - -cat << EOF >> "$WPA_SUPPLICANT_CONF_PATH" -ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev -update_config=1 - -network={ - ssid="$SSID" - psk="$WIFIPASS" - key_mgmt=WPA-PSK -} -EOF - -good_message "Downloading setup scripts. They will be downloaded to ${BOOT_DIR}/teslausb_setup_scripts," -good_message "and moved to /root/teslausb_setup_scripts during first boot and install." - -download_scripts - -echo "" -good_message '-- Files updated and ready for headless setup --' -echo '' -echo 'You can now insert your SD card into the Pi for headless setup. Plug in power to the Pi and it will boot and run.' -echo "When done (this may take a vew minutes), the Pi should be available over SSH as pi@teslausb.local." -echo "It's recommended you have your Pi plugged into a PC USB port for power, and connected to the port labeled USB on the Pi." -echo "That way, when setup is complete, you should see your CAM and/or MUSIC drives appear as confirmation." -echo "" diff --git a/headless-scripts/setup-teslausb-headless b/headless-scripts/setup-teslausb-headless deleted file mode 100644 index 8c8112f..0000000 --- a/headless-scripts/setup-teslausb-headless +++ /dev/null @@ -1,284 +0,0 @@ -#!/bin/bash -eu - -REPO=rtgoodwin -BRANCH="headless-patch" -user_enabled_pushover=false -SETUP_LOGFILE=/boot/teslausb-headless-setup.log -setup_complete=false - -# if ! [ $(id -u) = 0 ] -# then -# echo "STOP: Run sudo -i." -# exit 1 -# fi - -function setup_progress () { - echo "$( date ) : $1" >> "$LOGFILE" -} - -if [ ! -e /boot/TESLAUSB_SETUP_FINISHED ] -then - setup_log "Setting up teslausb functionality" - touch /boot/TESLAUSB_SETUP_STARTED -fi - -function mark_setup_failed () { - setup_log "ERROR: Setup Failed." - touch /boot/TESLAUSB_SETUP_FAILED -} - -function mark_setup_success () { - if [ -e /boot/TESLAUSB_SETUP_FAILED ] - then - rm /boot/TESLAUSB_SETUP_FAILED - fi - rm /boot/TESLAUSB_SETUP_STARTED - touch /boot/TESLAUSB_SETUP_FINISHED - setup_log "Main setup completed. Remounting file systems read only." -} - -function check_variable () { - local var_name="$1" - if [ -z "${!var_name+x}" ] - then - echo "STOP: Define the variable $var_name like this: export $var_name=value" - setup_log "SETUP FAILED: Define the variable $var_name as export $var_name=value in /boot/teslausb_setup_variables.conf" - /etc/stage_flash 10 - exit 1 - fi -} - -function check_pushover_enabled () { - if [ ! -z "${pushover_enabled+x}" ] - then - setup_log "Adding Pushover variables into /root/.teslaCamPushoverCredentials" - echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials - echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials - echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials - fi -} - -function check_archive_server_reachable () { - setup_log "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 - setup_log "WARNING: The archive server $archiveserver is unreachable. Try specifying its IP address instead." - setup_log "Continuing setup, but you may need to edit /etc/fstab to verify your archive mount entry is correct" - fi - - # echo "The archive server is reachable." -} - -function check_available_space () { - setup_log "Verifying that there is sufficient space available on the MicroSD card..." - - local available_space="$( parted -m /dev/mmcblk0 u b print free | tail -1 | cut -d ":" -f 4 | sed 's/B//g' )" - - if [ "$available_space" -lt 4294967296 ] - then - setup_log "ERROR: The MicroSD card is too small. Stopping setup." - /etc/stage_flash 10 - exit 1 - fi - - setup_log "There is sufficient space available." -} - -# function get_ancillary_setup_scripts () { -# pushd -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh -# chmod +x ./create-backingfiles-partition.sh -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh -# chmod +x ./create-backingfiles.sh -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.sh -# chmod +x ./make-root-fs-readonly.sh -# popd -# } - -function fix_cmdline_txt_modules_load () -{ - setup_log "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 - rm ~/cmdline.txt - setup_log "Fixed cmdline.txt." -} - -BACKINGFILES_MOUNTPOINT=/backingfiles - -function create_usb_drive_backing_files () { - mkdir "$BACKINGFILES_MOUNTPOINT" - /root/bin/tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" - - setup_log "Mounting the partition for the backing files..." - mount /backingfiles - setup_log "Mounted the partition for the backing files." - - /root/bin/tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" -} - -function configure_archive () { - setup_log "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 credentials=/root/.teslaCamArchiveCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab - - echo "username=$shareuser" > /root/.teslaCamArchiveCredentials - echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials - setup_log "Configured the archive." -} - -# 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/archive-teslacam-clips -# chmod +x archive-teslacam-clips -# popd -# echo "Configured the archive scripts." - -# pushd /root -# wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw -# chmod +x remountfs_rw -# popd -# echo "Downloaded script to remount filesystems read/write if needed (/root/remountfs_rw)." -# } - - -# 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 () { - setup_log "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 -cat << 'EOF' >> ~/rc.local -LOGFILE=/tmp/rc.local.log - -function log () { - echo "$( date )" >> "$LOGFILE" - echo "$1" >> "$LOGFILE" -} - -log "Launching archival script..." -/root/bin/archiveloop & -log "All done" -exit 0 -EOF - - cat ~/rc.local > /etc/rc.local - rm ~/rc.local - setup_log "Configured rc.local." -} - -# function configure_hostname () { -# setup_log "Configuring the hostname..." - -# local new_host_name="teslausb" -# cp /etc/hosts ~ -# sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts - -# cp /etc/hostname ~ -# sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname -# setup_log "Configured the hostname." -# } - -function make_root_fs_readonly () { - /root/bin/tmp/make-root-fs-readonly.sh -} - -# TURN OFF LED so we can start watching progress -echo 1 | sudo tee /sys/class/leds/led0/brightness - -sleep 5 - -# SETUP STAGE 1 - Check variables file - -/etc/stage_flash 1 - -# setup_log "SETUP STAGE 1: Check variables file." -# if [ ! -e /boot/teslausb_setup_variables.conf ] -# then -# setup_log "ERROR: teslausb_setup_variables.conf file not found. Can't continue setup." -# /etc/stage_flash 10 -# exit 1 -# fi - -source /boot/teslausb_setup_variables.conf - -# SETUP STAGE 2 - Validate variables. This should never fail but just in case. -/etc/stage_flash 2 - -setup_log "SETUP STAGE 2: Verifying environment variables..." - -check_variable "archiveserver" -check_variable "sharename" -check_variable "shareuser" -check_variable "sharepassword" -check_variable "campercent" - -check_pushover_enabled - -check_archive_server_reachable - -# SETUP STAGE 3 - -setup_log "SETUP STAGE 3: Check available space." -/etc/stage_flash 3 -check_available_space - -# get_ancillary_setup_scripts - -# pushd ~ - -# configure_archive_scripts - -# configure_pushover_scripts - -fix_cmdline_txt_modules_load - -echo "" >> /etc/fstab - -# SETUP STAGE 4 -setup_log "SETUP STAGE 4: Create backing files and final config changes." -/etc/stage_flash 4 - -create_usb_drive_backing_files - -configure_archive - -configure_rc_local - -# configure_hostname - -# SETUP STAGE 5 and reboot -# If you see 5 flashes we are probably good! - -setup_log "SETUP STAGE 5: Marking successful and making filesystem readonly." -/etc/stage_flash 5 -mark_setup_success - -make_root_fs_readonly -# echo 0 | sudo tee /sys/class/leds/led0/brightness -setup_log "Filesystems made read-only. Rebooting." - -reboot - diff --git a/headless-scripts/teslausb_setup_variables.conf.sample b/headless-scripts/teslausb_setup_variables.conf.sample index aae9f34..5340683 100644 --- a/headless-scripts/teslausb_setup_variables.conf.sample +++ b/headless-scripts/teslausb_setup_variables.conf.sample @@ -5,6 +5,9 @@ export sharepassword=password export campercent=100 export SSID=your_ssid export WIFIPASS=your_pass +export HEADLESS_SETUP=true +# export REPO=cimryan +# export BRANCH=master # export pushover_enabled=false # export pushover_user_key=user_key # export pushover_app_key=app_key \ No newline at end of file From 95d641cd2b35b58fbd8a8535f104a760e1d7ffa2 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 10:07:26 -0500 Subject: [PATCH 37/67] Update the baseimage rc.local if needed --- setup/pi/setup-teslausb | 1 + 1 file changed, 1 insertion(+) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 8f09d69..9cd22a5 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -48,6 +48,7 @@ function headless_setup_mark_setup_success () { rm /boot/TESLAUSB_SETUP_STARTED touch /boot/TESLAUSB_SETUP_FINISHED + sed -i'.bak' -e "s/TEMPARCHIVESERVER/$archiveserver/g" /etc/rc.local setup_progress "Main setup completed. Remounting file systems read only." fi } From 697ded0c549ea1476a2e21a964cc0581b1837698 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 10:22:47 -0500 Subject: [PATCH 38/67] Add a check to ensure archiveserver is set In headless mode, the image rc.local is used. It should get replaced outside of setup, but replacing it just in case. Only takes action in headless mode. --- setup/pi/setup-teslausb | 1 + 1 file changed, 1 insertion(+) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 9cd22a5..4563c72 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -48,6 +48,7 @@ function headless_setup_mark_setup_success () { rm /boot/TESLAUSB_SETUP_STARTED touch /boot/TESLAUSB_SETUP_FINISHED + # This sed shouldn't be needed, but double checking just to be sure. sed -i'.bak' -e "s/TEMPARCHIVESERVER/$archiveserver/g" /etc/rc.local setup_progress "Main setup completed. Remounting file systems read only." fi From f8fd5acbed66f9afeb34cf38e24a74599050ed10 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 10:40:08 -0500 Subject: [PATCH 39/67] Optionally use LED for setup progress in either setup mode --- setup/pi/setup-teslausb | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 4563c72..9b800f1 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -5,6 +5,8 @@ SETUP_LOGFILE=/boot/teslausb-headless-setup.log REPO=${REPO:-cimryan} BRANCH=${BRANCH:-master} HEADLESS_SETUP=${HEADLESS_SETUP:-false} +USE_LED_FOR_SETUP_PROGRESS=true + if ! [ $(id -u) = 0 ] @@ -29,6 +31,7 @@ function headless_setup_populate_variables () { fi } + function headless_setup_mark_setup_failed () { if [ $HEADLESS_SETUP = "true" ] then @@ -61,6 +64,22 @@ function headless_setup_progress_flash () { fi } +function setup_led_off () { + + if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] + then + echo 1 | sudo tee /sys/class/leds/led1/brightness + fi +} + +function setup_led_on () { + + if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] + then + echo 0 | sudo tee /sys/class/leds/led1/brightness + fi +} + function check_variable () { local var_name="$1" if [ -z "${!var_name+x}" ] @@ -232,6 +251,12 @@ function make_root_fs_readonly () { headless_setup_populate_variables +# If USE_LED_FOR_SETUP_PROGRESS = true. +setup_led_off + +# Flash for stage 2 headless (verify variables) +headless_setup_progress_flash 2 + setup_progress "Verifying environment variables..." RSYNC_ENABLE="${RSYNC_ENABLE:-false}" @@ -255,6 +280,9 @@ check_variable "campercent" check_pushover_enabled +# Flash for Stage 3 headless (grab scripts) +headless_setup_progress_flash 3 + if [ ! -e /root/bin ] then mkdir /root/bin @@ -280,6 +308,7 @@ get_ancillary_setup_scripts pushd ~ + configure_archive_scripts configure_pushover_scripts @@ -288,6 +317,9 @@ fix_cmdline_txt_modules_load echo "" >> /etc/fstab +# Flash for stage 4 headless (Create backing files) +headless_setup_progress_flash 4 + create_usb_drive_backing_files /root/bin/configure-archive.sh @@ -296,8 +328,14 @@ configure_rc_local configure_hostname +# Flash for stage 5 headless (Mark success, FS readonly) +headless_setup_progress_flash 5 + headless_setup_mark_setup_success make_root_fs_readonly -echo "All done." +# If USE_LED_FOR_SETUP_PROGRESS = true. +setup_led_on + +setup_progress "All done." From 410f5868b54e7641a7ae45c6ee29d854a96d57da Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 11:36:31 -0500 Subject: [PATCH 40/67] Wrong LED resource (typo) --- setup/pi/setup-teslausb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 9b800f1..2a831e0 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -68,7 +68,8 @@ function setup_led_off () { if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] then - echo 1 | sudo tee /sys/class/leds/led1/brightness + echo "none" | sudo tee /sys/class/leds/led0/trigger > /dev/null + echo 1 | sudo tee /sys/class/leds/led0/brightness > /dev/null fi } @@ -76,7 +77,7 @@ function setup_led_on () { if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] then - echo 0 | sudo tee /sys/class/leds/led1/brightness + echo 0 | sudo tee /sys/class/leds/led1/brightness > /dev/null fi } From 718487c5b4d6fb7e872f847566177f1e43e56e61 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 11:40:13 -0500 Subject: [PATCH 41/67] Added rtgoodwin repo/branch for testing at the moment --- headless-scripts/teslausb_setup_variables.conf.sample | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/headless-scripts/teslausb_setup_variables.conf.sample b/headless-scripts/teslausb_setup_variables.conf.sample index 5340683..422a001 100644 --- a/headless-scripts/teslausb_setup_variables.conf.sample +++ b/headless-scripts/teslausb_setup_variables.conf.sample @@ -6,8 +6,8 @@ export campercent=100 export SSID=your_ssid export WIFIPASS=your_pass export HEADLESS_SETUP=true -# export REPO=cimryan -# export BRANCH=master +export REPO=rtgoodwin +export BRANCH=headless-patch # export pushover_enabled=false # export pushover_user_key=user_key # export pushover_app_key=app_key \ No newline at end of file From 1b5dc5343a2e75f756591526c31de71562624411 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 11:57:39 -0500 Subject: [PATCH 42/67] Extra log and correct blink pattern --- setup/pi/setup-teslausb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 2a831e0..73d4fc8 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -106,9 +106,9 @@ function check_pushover_enabled () { exit 1 else USER_ENABLED_PUSHOVER=true - setup_progress "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials - setup_progress "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials - setup_progress "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials + echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials + echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials + echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials fi fi } @@ -173,6 +173,7 @@ function create_usb_drive_backing_files () { if [ ! -e $BACKINGFILES_MOUNTPOINT/*.bin ] then + setup_progress "Creating backing disk files." /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" fi } @@ -256,7 +257,7 @@ headless_setup_populate_variables setup_led_off # Flash for stage 2 headless (verify variables) -headless_setup_progress_flash 2 +headless_setup_progress_flash 1 setup_progress "Verifying environment variables..." @@ -282,7 +283,7 @@ check_variable "campercent" check_pushover_enabled # Flash for Stage 3 headless (grab scripts) -headless_setup_progress_flash 3 +headless_setup_progress_flash 2 if [ ! -e /root/bin ] then @@ -319,7 +320,7 @@ fix_cmdline_txt_modules_load echo "" >> /etc/fstab # Flash for stage 4 headless (Create backing files) -headless_setup_progress_flash 4 +headless_setup_progress_flash 3 create_usb_drive_backing_files @@ -330,7 +331,7 @@ configure_rc_local configure_hostname # Flash for stage 5 headless (Mark success, FS readonly) -headless_setup_progress_flash 5 +headless_setup_progress_flash 4 headless_setup_mark_setup_success From 9fee370a2d23409a499ce9622f8294e4d8538fc8 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 12:00:32 -0500 Subject: [PATCH 43/67] How many times can I miss the led0 entry --- setup/pi/setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 73d4fc8..0af4178 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -77,7 +77,7 @@ function setup_led_on () { if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] then - echo 0 | sudo tee /sys/class/leds/led1/brightness > /dev/null + echo 0 | sudo tee /sys/class/leds/led0/brightness > /dev/null fi } From 6ced0c2c0499d99f0bc4d39d4944042fe218e6c9 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 12:14:29 -0500 Subject: [PATCH 44/67] Only use LED for headless setup for now --- setup/pi/setup-teslausb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 0af4178..6e87db6 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -66,7 +66,7 @@ function headless_setup_progress_flash () { function setup_led_off () { - if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] + if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] && [ $HEADLESS_SETUP = "true" ] then echo "none" | sudo tee /sys/class/leds/led0/trigger > /dev/null echo 1 | sudo tee /sys/class/leds/led0/brightness > /dev/null @@ -75,7 +75,7 @@ function setup_led_off () { function setup_led_on () { - if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] + if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] && [ $HEADLESS_SETUP = "true" ] then echo 0 | sudo tee /sys/class/leds/led0/brightness > /dev/null fi From 29466505f788417e125c10276ec6b97f5c47d78f Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 12:15:29 -0500 Subject: [PATCH 45/67] Now it really is only using LED for setup --- setup/pi/setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 6e87db6..5c9ca79 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -58,7 +58,7 @@ function headless_setup_mark_setup_success () { } function headless_setup_progress_flash () { - if [ $HEADLESS_SETUP = "true" ] + if [ $USE_LED_FOR_SETUP_PROGRESS = "true" ] && [ $HEADLESS_SETUP = "true" ] then /etc/stage_flash $1 fi From 965b3533a41a1c1aa27b5266315e09bc8dd84189 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 26 Oct 2018 12:50:01 -0500 Subject: [PATCH 46/67] More logging in getting scripts --- setup/pi/setup-teslausb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 5c9ca79..cf2690a 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -132,8 +132,10 @@ function get_script () { local name="$2" local remote_path="${3:-}" - wget -O "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" + curl -o "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" + # wget -O "$local_path/$name" https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/"$remote_path"/"$name" chmod +x "$local_path/$name" + setup_progress "Downloaded $local_path/$name ..." } function get_ancillary_setup_scripts () { @@ -285,6 +287,8 @@ check_pushover_enabled # Flash for Stage 3 headless (grab scripts) headless_setup_progress_flash 2 +setup_progress "Downloading additional setup scripts." + if [ ! -e /root/bin ] then mkdir /root/bin From b2111722a74e52919b9d7b89eb7581a76493ec3f Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 27 Oct 2018 08:54:39 -0700 Subject: [PATCH 47/67] Create a 100MB "mutable" partition after the backingfiles partition. --- setup/pi/create-backingfiles-partition.sh | 25 +++++++++++++++++------ setup/pi/setup-teslausb | 8 +++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/setup/pi/create-backingfiles-partition.sh b/setup/pi/create-backingfiles-partition.sh index e8b7013..120130e 100644 --- a/setup/pi/create-backingfiles-partition.sh +++ b/setup/pi/create-backingfiles-partition.sh @@ -1,16 +1,27 @@ #!/bin/bash -eu BACKINGFILES_MOUNTPOINT="$1" - -PARTITION_TABLE=$(parted -m /dev/mmcblk0 unit s print) -ROOT_PARTITION_LINE=$(echo "$PARTITION_TABLE" | grep -e "^2:") -LAST_ROOT_PARTITION_SECTOR=$(echo "$ROOT_PARTITION_LINE" | sed 's/s//g' | cut -d ":" -f 3) +MUTABLE_MOUNTPOINT="$2" -FIRST_BACKINGFILES_PARTITION_SECTOR=$(( $LAST_ROOT_PARTITION_SECTOR + 1 )) +PARTITION_TABLE=$(parted -m /dev/mmcblk0 unit B print) +DISK_LINE=$(echo "$PARTITION_TABLE" | grep -e "^/dev/mmcblk0:") +DISK_SIZE=$(echo "$DISK_LINE" | cut -d ":" -f 2 | sed 's/B//' ) + +ROOT_PARTITION_LINE=$(echo "$PARTITION_TABLE" | grep -e "^2:") +LAST_ROOT_PARTITION_BYTE=$(echo "$ROOT_PARTITION_LINE" | sed 's/B//g' | cut -d ":" -f 3) + +FIRST_BACKINGFILES_PARTITION_BYTE="$(( $LAST_ROOT_PARTITION_BYTE + 1 ))" +LAST_BACKINGFILES_PARTITION_DESIRED_BYTE="$(( $DISK_SIZE - (100 * (2 ** 20)) - 1))" ORIGINAL_DISK_IDENTIFIER=$( fdisk -l /dev/mmcblk0 | grep -e "^Disk identifier" | sed "s/Disk identifier: 0x//" ) -parted -m /dev/mmcblk0 u s mkpart primary ext4 "$FIRST_BACKINGFILES_PARTITION_SECTOR" 100% +BACKINGFILES_PARTITION_END_SPEC="$(( $LAST_BACKINGFILES_PARTITION_DESIRED_BYTE / 1000000 ))M" +parted -a optimal -m /dev/mmcblk0 unit B mkpart primary ext4 "$FIRST_BACKINGFILES_PARTITION_BYTE" "$BACKINGFILES_PARTITION_END_SPEC" + +LAST_BACKINGFILES_PARTITION_BYTE=$(parted -m /dev/mmcblk0 unit B print | grep -e "^3:" | cut -d ":" -f 3 | sed 's/B//g' ) + +MUTABLE_PARTITION_START_SPEC="$(( $LAST_BACKINGFILES_PARTITION_BYTE / 1000000 ))M" +parted -a optimal -m /dev/mmcblk0 unit B mkpart primary ext4 "$MUTABLE_PARTITION_START_SPEC" 100% NEW_DISK_IDENTIFIER=$( fdisk -l /dev/mmcblk0 | grep -e "^Disk identifier" | sed "s/Disk identifier: 0x//" ) @@ -18,5 +29,7 @@ sed -i "s/${ORIGINAL_DISK_IDENTIFIER}/${NEW_DISK_IDENTIFIER}/g" /etc/fstab sed -i "s/${ORIGINAL_DISK_IDENTIFIER}/${NEW_DISK_IDENTIFIER}/" /boot/cmdline.txt mkfs.ext4 -F /dev/mmcblk0p3 +mkfs.ext4 -F /dev/mmcblk0p4 echo "/dev/mmcblk0p3 $BACKINGFILES_MOUNTPOINT ext4 auto,rw,noatime 0 2" >> /etc/fstab +echo "/dev/mmcblk0p4 $MUTABLE_MOUNTPOINT ext4 auto,rw 0 2" >> /etc/fstab diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 6e64ee8..cc4e8c3 100644 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -83,6 +83,7 @@ function fix_cmdline_txt_modules_load () } BACKINGFILES_MOUNTPOINT=/backingfiles +MUTABLE_MOUNTPOINT=/mutable function create_usb_drive_backing_files () { if [ ! -e "$BACKINGFILES_MOUNTPOINT" ] @@ -90,9 +91,14 @@ function create_usb_drive_backing_files () { mkdir "$BACKINGFILES_MOUNTPOINT" fi + if [ ! -e "$MUTABLE_MOUNTPOINT" ] + then + mkdir "$MUTABLE_MOUNTPOINT" + fi + if [ ! -e /dev/mmcblk0p3 ] then - /tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" + /tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" "$MUTABLE_MOUNTPOINT" fi if ! findmnt --mountpoint $BACKINGFILES_MOUNTPOINT From fd6cedb5f9a44c5f12146bc25dbc16ac62dbd87f Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 12:34:20 -0500 Subject: [PATCH 48/67] Updated readme Points to newer image. Need to come up with a way to point to latest. Notes that image is now usable for both kinds of setup. Troubleshooting examples. --- headless-scripts/Readme.md | 41 ++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index de894d4..ad63a54 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -1,18 +1,25 @@ # Flashable image to get started more quickly -# This is a WORK IN PROGRESS, SHOULD BE WORKING. +# This is a WORK IN PROGRESS, SHOULD CURRENTLY BE WORKING. ## Notes -* Assumes your Pi has access to Wifi, with internet access (during setup). (But all setup methods do currently.) USB networking still enabled for troubleshooting. +* Assumes your Pi has access to Wifi, with internet access (during setup). (But all setup methods do currently.) USB networking is still enabled for troubleshooting or manual setup +* This image will work for either headless or automatic setup. + ## Configure the SD card before first boot of the Pi -1. Flash the image from [here (10-24 dated image)](https://www.dropbox.com/s/6f8kxenvtz8pkj9/image_2018-10-24-teslausb_headless-lite.zip?dl=0) using Etcher or similar. (Be sure to click the `...` on Dropbox and download the `.zip` file.) -1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) A sample conf file is in this repo. I.e. file should contain at a minimum (replace with your own values): +1. Flash the image from [Image dated 2018-10-27](https://www.dropbox.com/s/pr9gampu6upmmaf/image_2018-10-27-teslausb_headless-lite.zip?dl=0) using Etcher or similar. Be sure to download the `.zip` file, although the `.img` file should work also. + +### For headless (automatic) setup + +1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) A sample conf file is located in the `boot` folder on the SD card. + + The file should contain at a minimum (replace with your own values): ``` export archiveserver=Nautilus export sharename=SailfishCam @@ -21,22 +28,40 @@ export campercent=100 export SSID=your_ssid export WIFIPASS=your_wifi_password + export HEADLESS_SETUP=true + export REPO=rtgoodwin + export BRANCH=headless-patch + # Currently set to track this repo/branch while under development. # export pushover_enabled=false # export pushover_user_key=user_key # export pushover_app_key=app_key ``` (Pushover should be working but commented out by default.) * Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5, maybe 6) and then a reboot and/or the CAM to become available on your PC/Mac. -* The Pi should be available at `teslausb.local` over Wifi (if it works) or USB networking (if it doesn't). Takes about 5 minutes for me. You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success too. -* Currently doesn't create the TeslaCam folder, so you'll need to do that before taking to your car. +* The Pi should be available at `teslausb.local` over Wifi (if it works) or USB networking (if it doesn't). Takes about 5 minutes, or more depending on network speed, etc. You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success too. * If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. +### For manual setup + +After flashing the image, boot it in your Pi and connect via USB networking. (The Pi must be connected to your PC and plugged into the port labeled USB on the Pi.) + +Follow the steps starting at [Set up the USB storage functionality](https://github.com/cimryan/teslausb#set-up-the-usb-storage-functionality) in the main guide. + +### Troubleshooting + +* `ssh` to `pi@teslausb.local` (assuming Wifi came up, or your Pi is connected to your computer via USB) and look at the `/boot/teslausb-headless-setup.log`. +* Try `sudo -i` and then run `/etc/rc.local`. The scripts are now fairly resilient to restarting and not completing previous steps. +* If Wifi didn't come up, doublecheck the SSID and WIFIPASS variables in `teslausb_setup_variables.conf`. + * Remove `/boot/WIFI_ENABLED` and re-run `/etc/rc.local`. + * If all else fails, copy `/boot/wpa_supplicant.conf.sample` to `/boot/wpa_supplicant.conf` and edit out the `TEMP` variables to your desired settings. + * You may have to `sudo` and run `/root/bin/remountfs_rw` if the filesystems have already been remounted as read-only. + + ## What happens under the covers When the Pi boots the first time: * A `/boot/teslausb-headless-setup.log` file will be created and stages logged. This takes the place of the "STOP" commands * Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. -* (Working on a progress system so the script can pick back up if needed. This is probably useful for the general/old way of setup too.) * Wifi is detected by looking for `/boot/WIFI_ENABLED` and if not, creates the `wpa_supplicant.conf` file in place and reboots. * The Pi LED will flash patterns (2, 3, 4, 5, maybe 6) as it gets to each stage (labeled in the setup-teslausb-headless script). * 10 flashes means setup failed! @@ -78,4 +103,4 @@ Built image on a Raspi running Stretch, for maximum Pi-ception. 1. (Yes at this point you could suggest that just putting the end state files in place instead of patching would be good, but why not be idiomatic? :) ) 1. Add a script to flash LEDs 1. Run `sudo ./build.sh` from the `pi-gen` directory. -1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in stage2-stage5 present) and rerun `sudo CLEAN=1 ./build.sh` +1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in stage2-stage5 present) and rerun `sudo CLEAN=1 ./build.sh` \ No newline at end of file From 7a377117bdb755f272e88c908d8f84fbb6b689e4 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 20:01:11 -0500 Subject: [PATCH 49/67] Point to images on releases page --- headless-scripts/Readme.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index ad63a54..23f7fdc 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -8,18 +8,15 @@ * Assumes your Pi has access to Wifi, with internet access (during setup). (But all setup methods do currently.) USB networking is still enabled for troubleshooting or manual setup * This image will work for either headless or automatic setup. - - ## Configure the SD card before first boot of the Pi - -1. Flash the image from [Image dated 2018-10-27](https://www.dropbox.com/s/pr9gampu6upmmaf/image_2018-10-27-teslausb_headless-lite.zip?dl=0) using Etcher or similar. Be sure to download the `.zip` file, although the `.img` file should work also. +1. Flash the [latest image release] using Etcher or similar. ### For headless (automatic) setup 1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) A sample conf file is located in the `boot` folder on the SD card. - The file should contain at a minimum (replace with your own values): + The file should contain at a minimum, but (**replace with your own values**): ``` export archiveserver=Nautilus export sharename=SailfishCam From 81272313a94bd18b371b2ae80d957ddb9913bc87 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 20:39:15 -0500 Subject: [PATCH 50/67] More general readme updates --- headless-scripts/Readme.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 23f7fdc..7243fb9 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -6,17 +6,19 @@ ## Notes * Assumes your Pi has access to Wifi, with internet access (during setup). (But all setup methods do currently.) USB networking is still enabled for troubleshooting or manual setup -* This image will work for either headless or automatic setup. +* This image will work for either _headless_ (tested) or _manual_ (tested less) setup. +* Currently not tested with the RSYNC/SFTP method when using headless setup. ## Configure the SD card before first boot of the Pi -1. Flash the [latest image release] using Etcher or similar. +1. Flash the [latest image release](https://github.com/rtgoodwin/teslausb/releases) using Etcher or similar. ### For headless (automatic) setup -1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for setup (including archive, Wifi, and push notifications (if desired).) A sample conf file is located in the `boot` folder on the SD card. +1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for manual setup (including archive info, Wifi, and push notifications (if desired).) A sample conf file is located in the `boot` folder on the SD card. - The file should contain at a minimum, but (**replace with your own values**): + + The file should contain the entries below at a minimum, but **replace with your own values**: ``` export archiveserver=Nautilus export sharename=SailfishCam @@ -29,14 +31,17 @@ export REPO=rtgoodwin export BRANCH=headless-patch # Currently set to track this repo/branch while under development. + # export pushover_enabled=false # export pushover_user_key=user_key # export pushover_app_key=app_key ``` - (Pushover should be working but commented out by default.) -* Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5, maybe 6) and then a reboot and/or the CAM to become available on your PC/Mac. -* The Pi should be available at `teslausb.local` over Wifi (if it works) or USB networking (if it doesn't). Takes about 5 minutes, or more depending on network speed, etc. You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success too. + (For now, please leave the REPO and BRANCH set to the settings above.) + +* Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5) and then a reboot and/or the CAM to become available on your PC/Mac. +* The Pi should be available for `ssh` at `pi@teslausb.local`, over Wifi (if automatic setup works) or USB networking (if it doesn't). It takes about 5 minutes, or more depending on network speed, etc. * If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. +* You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success as well. ### For manual setup From 0ca6936d9792e4945095d6ee12cd0842383a7076 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 21:08:01 -0500 Subject: [PATCH 51/67] More general updates --- headless-scripts/Readme.md | 83 +++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index 7243fb9..d55ad9a 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -38,34 +38,53 @@ ``` (For now, please leave the REPO and BRANCH set to the settings above.) -* Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5) and then a reboot and/or the CAM to become available on your PC/Mac. +* Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5) and then a reboot and/or the CAM to become available on your PC/Mac. The LED flash stages are: + +| Stage (number of flashes) | Activity | +|---|---| +| 2 | Verify setup variables | +| 3 | Grab scripts to start/continue setup | +| 4 | Create partition and files to store camera clips/music) | +| 5 | Setup completed; remounting filesystems as read-only and rebooting | + + + * The Pi should be available for `ssh` at `pi@teslausb.local`, over Wifi (if automatic setup works) or USB networking (if it doesn't). It takes about 5 minutes, or more depending on network speed, etc. * If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. * You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success as well. ### For manual setup -After flashing the image, boot it in your Pi and connect via USB networking. (The Pi must be connected to your PC and plugged into the port labeled USB on the Pi.) +1. After flashing the image, boot it in your Pi and: + * connect via USB networking at `ssh pi@teslausb.local`. (The Pi must be connected to your PC and plugged into the port labeled USB on the Pi. Or... + * You can also automate only the Wifi portion of setup by creating the `boot/teslausb_setup_variables.conf` file and populating it with the `SSID` and `WIFIPASS` variables: + ``` + export SSID=your_ssid + export WIFIPASS=your_wifi_pass + ``` -Follow the steps starting at [Set up the USB storage functionality](https://github.com/cimryan/teslausb#set-up-the-usb-storage-functionality) in the main guide. +1. Once you have an `ssh` session, follow the steps starting at [Set up the USB storage functionality](https://github.com/cimryan/teslausb#set-up-the-usb-storage-functionality) in the main guide. ### Troubleshooting +#### Headless (full or Wifi) setup * `ssh` to `pi@teslausb.local` (assuming Wifi came up, or your Pi is connected to your computer via USB) and look at the `/boot/teslausb-headless-setup.log`. -* Try `sudo -i` and then run `/etc/rc.local`. The scripts are now fairly resilient to restarting and not completing previous steps. -* If Wifi didn't come up, doublecheck the SSID and WIFIPASS variables in `teslausb_setup_variables.conf`. - * Remove `/boot/WIFI_ENABLED` and re-run `/etc/rc.local`. +* Try `sudo -i` and then run `/etc/rc.local`. The scripts are fairly resilient to restarting and not re-running previous steps, and will tell you about progress/failure. +* If Wifi didn't come up: + * Double-check the SSID and WIFIPASS variables in `teslausb_setup_variables.conf`, and remove `/boot/WIFI_ENABLED`, then booting the SD in your Pi to retry automatic Wifi setup. + * If still no go, re-run `/etc/rc.local` * If all else fails, copy `/boot/wpa_supplicant.conf.sample` to `/boot/wpa_supplicant.conf` and edit out the `TEMP` variables to your desired settings. - * You may have to `sudo` and run `/root/bin/remountfs_rw` if the filesystems have already been remounted as read-only. + * (Note: if you get an error about `read-only filesystem`, you may have to `sudo -i` and run `/root/bin/remountfs_rw`. +# Background information ## What happens under the covers When the Pi boots the first time: -* A `/boot/teslausb-headless-setup.log` file will be created and stages logged. This takes the place of the "STOP" commands +* A `/boot/teslausb-headless-setup.log` file will be created and stages logged. * Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. -* Wifi is detected by looking for `/boot/WIFI_ENABLED` and if not, creates the `wpa_supplicant.conf` file in place and reboots. -* The Pi LED will flash patterns (2, 3, 4, 5, maybe 6) as it gets to each stage (labeled in the setup-teslausb-headless script). +* Wifi is detected by looking for `/boot/WIFI_ENABLED` and if not, creates the `wpa_supplicant.conf` file in place, using `SSID` and `WIFIPASS` from `teslausb_setup_varibles.conf` and reboots. +* The Pi LED will flash patterns (2, 3, 4, 5) as it gets to each stage (labeled in the setup-teslausb-headless script). * 10 flashes means setup failed! * After the final stage and reboot the LED will go back to normal. Remember, the step to remount the filesystem takes a few minutes. @@ -80,29 +99,39 @@ For now the image creation work is at: * `headless-patch` branch of rtgoodwin fork [https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts](https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts) -### Image creation TODOs -1. Patch the hostname to teslausb -1. Make it so if someone deletes the `TESLAUSB_SETUP_FINISHED` file it's handled gracefully. -1. I still see some errors during pi-gen about locale, may need to be fixed? stage0/01-locale/debconf en_US.UTF-8 +### Image refinement TODOs +1. ~Patch the hostname to teslausb~ +1. Make it so if someone deletes the `TESLAUSB_SETUP_FINISHED` file it's handled gracefully. (Right now it will try to re-run setup which should be fine.) 1. Cache the remount packages? Might mess with first boot like `rsyslog` -1. Any other steps to move into the base image? 1. Aspirational TODO: Remove more packages and set services to stopped to make the boot process faster? -1. NOTE: I moved all script downloads and variable creation to the initial setup. At this point, I'm designing it to pull the setup scripts dynamically, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! At the very least we could bake in stable first stage headlessBuild scripts for Mac/Linux/Windows. +1. At this point, it's designed to pull the setup scripts _dynamically_, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is essentially ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! #### Modifications to pi-gen builder from master -Built image on a Raspi running Stretch, for maximum Pi-ception. +The image is built on a Raspberry Pi 3B running Stretch, for maximum Pi-ception. -1. Add SKIP and SKIP_IMAGES files to stage3, 4, and 5 (if present). -1. Add a stage6. (There are stages0-5, but may be a stage5 in some cases. This will help keep a clean merge later.) -1. Copy the prerun.sh from `stage2`. Be SURE to mark `chmod +x` it. +This is the basic configuration, but it's helpful to just [look at the code itself](https://github.com/rtgoodwin/pi-gen/tree/teslausb-headless-image) and the Readme for Pi-gen which explains this all in much greater detail: + +1. Added SKIP and SKIP_IMAGES files to stage3, 4, and 5 (if present). We want to build the default image up to stage2, then add our own stage for tweaks we want. +1. Added a `stage6` (or 7, just something beyond stage5). (There are stages 0-4 in the main repo by default, but may be a stage5 in some cases. This will help keep a clean merge later.) +1. Copy the prerun.sh from `stage2`. Be SURE to `chmod +x` it. 1. Remove or rename the EXPORT_NOOBS files in all stages. We don't need a NOOBS image built. -1. In `stage6`, create a `00-tweaks` folder, with a `00-patches` folder and patch inside to patch `cmdline.txt` to remove the resize and add the needed modules. The build process uses `quilt` for patching. Note: the path for any patching you do at this stage is `stage6/rootfs/FILEPATH` where `rootfs` represents the Pi's `/`. So, `cmdline.txt` is `stage6/rootfs/boot/cmdline.txt`. -1. Add a patch for the `config.txt` file. -1. Add a file called `series` in the patches directory with the name of each `.diff` file in the order you want them applied. -1. Add a `files` folder in stage6 with modified `rc.local`. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time. (Still working on build logic here.) Files are moved into final locations in a `00-run.sh` script and the `install` command. See the script for details. -1. (Yes at this point you could suggest that just putting the end state files in place instead of patching would be good, but why not be idiomatic? :) ) -1. Add a script to flash LEDs +1. In `stage6`, create a `00-tweaks` folder, with a `00-patches` folder and patches inside. Currently patched: + + | File | Change | + |---|---| + | `cmdline.txt`| Add the dwc2,g_ether modules | + | `config.txt`| Add the dwc2 module | + | `hosts` | Change hostname to `teslausb` | + | `hostname` | Change hostname to `teslausb` | + + * The build process uses `quilt` for patching + * The path for any patching you do at this stage is `stage6/rootfs/FILEPATH` where `rootfs` represents the Pi's `/`. So, `cmdline.txt` is `stage6/rootfs/boot/cmdline.txt`. + +1. Added a file called `series` in the patches directory with the name of each `.diff` file in the order you want them applied. +1. Added a `files` folder in stage6 with modified `rc.local`, and whatever else you want copied into the image. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time. +1. Added a script to flash the Pi LED +1. Files are moved into final locations using the `00-run.sh` script using the `install` command. See the script for details. I also `touch /boot/ssh` here so SSH is ready out of the box. 1. Run `sudo ./build.sh` from the `pi-gen` directory. -1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in stage2-stage5 present) and rerun `sudo CLEAN=1 ./build.sh` \ No newline at end of file +1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in all successful stages and rerun `sudo CLEAN=1 ./build.sh` \ No newline at end of file From 7dfb98ce5e2bb88872d863dd5d87150626cf64ff Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 21:43:32 -0500 Subject: [PATCH 52/67] A good readme is never done. --- headless-scripts/Readme.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/headless-scripts/Readme.md b/headless-scripts/Readme.md index d55ad9a..9fa7d88 100644 --- a/headless-scripts/Readme.md +++ b/headless-scripts/Readme.md @@ -15,7 +15,8 @@ ### For headless (automatic) setup -1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for manual setup (including archive info, Wifi, and push notifications (if desired).) A sample conf file is located in the `boot` folder on the SD card. +1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for manual setup (including archive info, Wifi, and push notifications (if desired). +A sample conf file is located in the `boot` folder on the SD card. The file should contain the entries below at a minimum, but **replace with your own values**: @@ -38,7 +39,7 @@ ``` (For now, please leave the REPO and BRANCH set to the settings above.) -* Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5) and then a reboot and/or the CAM to become available on your PC/Mac. The LED flash stages are: +* Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5) and then a reboot and/or the CAM/music drives to become available on your PC/Mac. The LED flash stages are: | Stage (number of flashes) | Activity | |---|---| @@ -51,13 +52,13 @@ * The Pi should be available for `ssh` at `pi@teslausb.local`, over Wifi (if automatic setup works) or USB networking (if it doesn't). It takes about 5 minutes, or more depending on network speed, etc. * If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. -* You should see in `/boot` the TESLAUSB_SETUP_FINISHED and WIFI_ENABLED files as markers of success as well. +* You should see in `/boot` the `TESLAUSB_SETUP_FINISHED` and `WIFI_ENABLED` files as markers of headless setup success as well. ### For manual setup 1. After flashing the image, boot it in your Pi and: * connect via USB networking at `ssh pi@teslausb.local`. (The Pi must be connected to your PC and plugged into the port labeled USB on the Pi. Or... - * You can also automate only the Wifi portion of setup by creating the `boot/teslausb_setup_variables.conf` file and populating it with the `SSID` and `WIFIPASS` variables: + * You can also just automate the Wifi portion of setup by creating the `boot/teslausb_setup_variables.conf` file and populating it with the `SSID` and `WIFIPASS` variables: ``` export SSID=your_ssid export WIFIPASS=your_wifi_pass @@ -74,7 +75,7 @@ * Double-check the SSID and WIFIPASS variables in `teslausb_setup_variables.conf`, and remove `/boot/WIFI_ENABLED`, then booting the SD in your Pi to retry automatic Wifi setup. * If still no go, re-run `/etc/rc.local` * If all else fails, copy `/boot/wpa_supplicant.conf.sample` to `/boot/wpa_supplicant.conf` and edit out the `TEMP` variables to your desired settings. - * (Note: if you get an error about `read-only filesystem`, you may have to `sudo -i` and run `/root/bin/remountfs_rw`. +* (Note: if you get an error about `read-only filesystem`, you may have to `sudo -i` and run `/root/bin/remountfs_rw`. # Background information @@ -85,8 +86,8 @@ When the Pi boots the first time: * Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. * Wifi is detected by looking for `/boot/WIFI_ENABLED` and if not, creates the `wpa_supplicant.conf` file in place, using `SSID` and `WIFIPASS` from `teslausb_setup_varibles.conf` and reboots. * The Pi LED will flash patterns (2, 3, 4, 5) as it gets to each stage (labeled in the setup-teslausb-headless script). - * 10 flashes means setup failed! - * After the final stage and reboot the LED will go back to normal. Remember, the step to remount the filesystem takes a few minutes. + * ~~10 flashes means setup failed!~~ (not currently working) +* After the final stage and reboot the LED will go back to normal. Remember, the step to remount the filesystem takes a few minutes. At this point the next boot should start the Dashcam/music drives like normal. If you're watching the LED it will start flashing every 1 second, which is the archive loop running. @@ -100,7 +101,7 @@ For now the image creation work is at: ### Image refinement TODOs -1. ~Patch the hostname to teslausb~ +1. ~~Patch the hostname to teslausb~~ 1. Make it so if someone deletes the `TESLAUSB_SETUP_FINISHED` file it's handled gracefully. (Right now it will try to re-run setup which should be fine.) 1. Cache the remount packages? Might mess with first boot like `rsyslog` 1. Aspirational TODO: Remove more packages and set services to stopped to make the boot process faster? @@ -114,7 +115,7 @@ The image is built on a Raspberry Pi 3B running Stretch, for maximum Pi-ception. This is the basic configuration, but it's helpful to just [look at the code itself](https://github.com/rtgoodwin/pi-gen/tree/teslausb-headless-image) and the Readme for Pi-gen which explains this all in much greater detail: 1. Added SKIP and SKIP_IMAGES files to stage3, 4, and 5 (if present). We want to build the default image up to stage2, then add our own stage for tweaks we want. -1. Added a `stage6` (or 7, just something beyond stage5). (There are stages 0-4 in the main repo by default, but may be a stage5 in some cases. This will help keep a clean merge later.) +1. Added a `stage6` (or 7, just something beyond stage5). (There are stages 0-4 in the main Raspbian pi-gen repo by default, but may be a stage5 in some cases. This will help keep a clean merge later.) 1. Copy the prerun.sh from `stage2`. Be SURE to `chmod +x` it. 1. Remove or rename the EXPORT_NOOBS files in all stages. We don't need a NOOBS image built. 1. In `stage6`, create a `00-tweaks` folder, with a `00-patches` folder and patches inside. Currently patched: @@ -130,7 +131,7 @@ This is the basic configuration, but it's helpful to just [look at the code itse * The path for any patching you do at this stage is `stage6/rootfs/FILEPATH` where `rootfs` represents the Pi's `/`. So, `cmdline.txt` is `stage6/rootfs/boot/cmdline.txt`. 1. Added a file called `series` in the patches directory with the name of each `.diff` file in the order you want them applied. -1. Added a `files` folder in stage6 with modified `rc.local`, and whatever else you want copied into the image. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time. +1. Added a `files` folder in stage6 with modified `rc.local`, and whatever else you want copied into the image. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time and doing Wifi setup. 1. Added a script to flash the Pi LED 1. Files are moved into final locations using the `00-run.sh` script using the `install` command. See the script for details. I also `touch /boot/ssh` here so SSH is ready out of the box. 1. Run `sudo ./build.sh` from the `pi-gen` directory. From 0c1cf449d88e0c44c555ad3b5983cab445441383 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 21:44:52 -0500 Subject: [PATCH 53/67] A good readme is never done... --- README.md | 250 ++++++++++++++++++++++++++---------------------------- 1 file changed, 118 insertions(+), 132 deletions(-) diff --git a/README.md b/README.md index fa902c4..34ef63b 100644 --- a/README.md +++ b/README.md @@ -1,152 +1,138 @@ -# teslausb +# Flashable image to get started more quickly -## Meta -This repo contains steps and scripts originally from [this thread on Reddit]( https://www.reddit.com/r/teslamotors/comments/9m9gyk/build_a_smart_usb_drive_for_your_tesla_dash_cam/) +# This is a WORK IN PROGRESS, SHOULD CURRENTLY BE WORKING. -Many people in that thread suggested that the scripts be hosted on Github but the author didn't seem interested in making that happen. I've hosted the scripts here with his/her permission. -The original post on Reddit assumed that the archive would be hosted on Windows and that the Pi would be set up using a Windows machine but this Git repo welcomes the contribution of instructions for other platforms. +## Notes -## Intro +* Assumes your Pi has access to Wifi, with internet access (during setup). (But all setup methods do currently.) USB networking is still enabled for troubleshooting or manual setup +* This image will work for either _headless_ (tested) or _manual_ (tested less) setup. +* Currently not tested with the RSYNC/SFTP method when using headless setup. -You can configure a Raspberry Pi Zero W so that your Tesla thinks it's a USB drive and will write dashcam footage to it. Since it's a computer, you can run scripts on the Pi to automatically copy the clips to an archive server when you get home. The Pi is going to continually: -1. Wait until it can connect to the archive server -1. Archive the clips -1. Wait until it can't connect to the archive server -1. GOTO 1. +## Configure the SD card before first boot of the Pi -The scripts in this repo will also allow you to use the Pi to store music that the Tesla can read through the USB interface. +1. Flash the [latest image release](https://github.com/rtgoodwin/teslausb/releases) using Etcher or similar. -Archiving the clips can take from seconds to hours depending on how many clips you've saved and how strong the WiFi signal is in your Tesla. If you find that the clips aren't getting completely transferred before the car powers down after you park or before you leave you can use the Tesla app to turn on the Climate control. This will send power to the Raspberry Pi, allowing it to complete the archival operation. +### For headless (automatic) setup -## Prerequisites +1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for manual setup (including archive info, Wifi, and push notifications (if desired). +A sample conf file is located in the `boot` folder on the SD card. -### Assumptions -* You park in range of your wireless network. -* Your wireless network is configured with WPA2 PSK access. -* You'll be archiving your dashcam clips to a Windows machine, and the Windows machine has a stable IP address on your home network. -* You'll be setting up the Raspberry Pi using a Windows machine. -### Hardware - -Required: -* [Raspberry Pi Zero W](https://www.raspberrypi.org/products/raspberry-pi-zero-w/): [Adafruit](https://www.adafruit.com/product/3400) or [Amazon](https://www.amazon.com/Raspberry-Pi-Zero-Wireless-model/dp/B06XFZC3BX/) - > Note: Of the many varieties of Raspberry Pi only the Raspberry Pi Zero and Raspberry Pi Zero W can be used as simulated USB drives. It may be possible to use a Pi Zero with a USB Wifi adapter to achieve the same result as the Pi Zero W, but this hasn't been confirmed. - -* A Micro SD card, at least 8 GB in size, and an adapter (if necessary) to connect the card to your computer. -* A mechanism to connect the Pi to the Tesla. Either: - * A USB A/Micro B cable: [Adafruit](https://www.adafruit.com/product/898) or [Amazon](https://www.amazon.com/gp/product/B013G4EAEI/), or - * A USB A Add-on Board if you want to plug your Pi into your Tesla like a USB drive instead of using a cable. [Amazon](https://www.amazon.com/gp/product/B07BK2BR6C/) - -Optional: -* A case. Don't want unprotected circuits hanging about! Official case at [Adafruit](https://www.adafruit.com/product/2885) or [Amazon](https://www.amazon.com/gp/product/B06Y593MHV). There are many others to choose from. Note that the official case won't work with the USB A Add on board. -* USB Splitter if you don't want to lose a front USB port. [The Onvian Splitter](https://www.amazon.com/gp/product/B01KX4TKH6) has been reported working by multiple people on reddit. - -### Software -Download [Raspbian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/) -* Note: Bittorrent is dramatically faster than direct download. - -Download and install: -* [Etcher](http://etcher.io) - -## Create your archive -### 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. -* 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 -**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*** - -## Set up the Raspberry 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. - -### Get the OS onto the micro SD card - -[These instructions](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) tell you how to get Raspbian onto your MicroSD card. Basically: -1. Connect your SD card to your computer. -2. Use Etcher to write the zip file you downloaded to the SD card. Etcher works well and is multi-platform. - > 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](doc/GetShellWithoutMonitorOnWindows.md). - -If you used a Mac or a Linux computer, follow these [Instructions](doc/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. Try to ping your archive server from the Pi. In this example the server is named `nautilus`. - ``` - ping -c 3 nautilus - ``` -1. If the server can't be reached, ping its IP address: - ``` - 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: - ``` - 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](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: + The file should contain the entries below at a minimum, but **replace with your own values**: ``` export archiveserver=Nautilus export sharename=SailfishCam 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](doc/ConfigureNotificationsForArchive.md). -1. Run these commands: - ``` - wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/pi/setup-teslausb - chmod +x setup-teslausb - ./setup-teslausb - ``` -1. Run this command: - ``` - halt - ``` -1. Disconnect the Pi from the computer. + export campercent=100 + export SSID=your_ssid + export WIFIPASS=your_wifi_password + export HEADLESS_SETUP=true + export REPO=rtgoodwin + export BRANCH=headless-patch + # Currently set to track this repo/branch while under development. -On the next boot, the Pi hostname will become `teslausb`, so future `ssh` sessions will be `ssh pi@teslausb.local`. + # export pushover_enabled=false + # export pushover_user_key=user_key + # export pushover_app_key=app_key + ``` + (For now, please leave the REPO and BRANCH set to the settings above.) -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. +* Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5) and then a reboot and/or the CAM/music drives to become available on your PC/Mac. The LED flash stages are: -## (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. +| Stage (number of flashes) | Activity | +|---|---| +| 2 | Verify setup variables | +| 3 | Grab scripts to start/continue setup | +| 4 | Create partition and files to store camera clips/music) | +| 5 | Setup completed; remounting filesystems as read-only and rebooting | -## 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. -To make changes to the system partitions: -``` -ssh pi@teslausb. -sudo -i -/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. + +* The Pi should be available for `ssh` at `pi@teslausb.local`, over Wifi (if automatic setup works) or USB networking (if it doesn't). It takes about 5 minutes, or more depending on network speed, etc. +* If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. +* You should see in `/boot` the `TESLAUSB_SETUP_FINISHED` and `WIFI_ENABLED` files as markers of headless setup success as well. + +### For manual setup + +1. After flashing the image, boot it in your Pi and: + * connect via USB networking at `ssh pi@teslausb.local`. (The Pi must be connected to your PC and plugged into the port labeled USB on the Pi. Or... + * You can also just automate the Wifi portion of setup by creating the `boot/teslausb_setup_variables.conf` file and populating it with the `SSID` and `WIFIPASS` variables: + ``` + export SSID=your_ssid + export WIFIPASS=your_wifi_pass + ``` + +1. Once you have an `ssh` session, follow the steps starting at [Set up the USB storage functionality](https://github.com/cimryan/teslausb#set-up-the-usb-storage-functionality) in the main guide. + +### Troubleshooting + +#### Headless (full or Wifi) setup +* `ssh` to `pi@teslausb.local` (assuming Wifi came up, or your Pi is connected to your computer via USB) and look at the `/boot/teslausb-headless-setup.log`. +* Try `sudo -i` and then run `/etc/rc.local`. The scripts are fairly resilient to restarting and not re-running previous steps, and will tell you about progress/failure. +* If Wifi didn't come up: + * Double-check the SSID and WIFIPASS variables in `teslausb_setup_variables.conf`, and remove `/boot/WIFI_ENABLED`, then booting the SD in your Pi to retry automatic Wifi setup. + * If still no go, re-run `/etc/rc.local` + * If all else fails, copy `/boot/wpa_supplicant.conf.sample` to `/boot/wpa_supplicant.conf` and edit out the `TEMP` variables to your desired settings. +* (Note: if you get an error about `read-only filesystem`, you may have to `sudo -i` and run `/root/bin/remountfs_rw`. + + +# Background information +## What happens under the covers + +When the Pi boots the first time: +* A `/boot/teslausb-headless-setup.log` file will be created and stages logged. +* Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. +* Wifi is detected by looking for `/boot/WIFI_ENABLED` and if not, creates the `wpa_supplicant.conf` file in place, using `SSID` and `WIFIPASS` from `teslausb_setup_varibles.conf` and reboots. +* The Pi LED will flash patterns (2, 3, 4, 5) as it gets to each stage (labeled in the setup-teslausb-headless script). + * ~~10 flashes means setup failed!~~ (not currently working) +* After the final stage and reboot the LED will go back to normal. Remember, the step to remount the filesystem takes a few minutes. + +At this point the next boot should start the Dashcam/music drives like normal. If you're watching the LED it will start flashing every 1 second, which is the archive loop running. + +> NOTE: Don't delete the `TESLAUSB_SETUP_FINISHED` or `WIFI_ENABLED` files. This is how the system knows setup is complete. + +### Image builder source and patches + +For now the image creation work is at: +* Modified pi-gen [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). +* `headless-patch` branch of rtgoodwin fork [https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts](https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts) + + +### Image refinement TODOs +1. ~~Patch the hostname to teslausb~~ +1. Make it so if someone deletes the `TESLAUSB_SETUP_FINISHED` file it's handled gracefully. (Right now it will try to re-run setup which should be fine.) +1. Cache the remount packages? Might mess with first boot like `rsyslog` +1. Aspirational TODO: Remove more packages and set services to stopped to make the boot process faster? +1. At this point, it's designed to pull the setup scripts _dynamically_, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is essentially ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! + + +#### Modifications to pi-gen builder from master + +The image is built on a Raspberry Pi 3B running Stretch, for maximum Pi-ception. + +This is the basic configuration, but it's helpful to just [look at the code itself](https://github.com/rtgoodwin/pi-gen/tree/teslausb-headless-image) and the Readme for Pi-gen which explains this all in much greater detail: + +1. Added SKIP and SKIP_IMAGES files to stage3, 4, and 5 (if present). We want to build the default image up to stage2, then add our own stage for tweaks we want. +1. Added a `stage6` (or 7, just something beyond stage5). (There are stages 0-4 in the main Raspbian pi-gen repo by default, but may be a stage5 in some cases. This will help keep a clean merge later.) +1. Copy the prerun.sh from `stage2`. Be SURE to `chmod +x` it. +1. Remove or rename the EXPORT_NOOBS files in all stages. We don't need a NOOBS image built. +1. In `stage6`, create a `00-tweaks` folder, with a `00-patches` folder and patches inside. Currently patched: + + | File | Change | + |---|---| + | `cmdline.txt`| Add the dwc2,g_ether modules | + | `config.txt`| Add the dwc2 module | + | `hosts` | Change hostname to `teslausb` | + | `hostname` | Change hostname to `teslausb` | + + * The build process uses `quilt` for patching + * The path for any patching you do at this stage is `stage6/rootfs/FILEPATH` where `rootfs` represents the Pi's `/`. So, `cmdline.txt` is `stage6/rootfs/boot/cmdline.txt`. + +1. Added a file called `series` in the patches directory with the name of each `.diff` file in the order you want them applied. +1. Added a `files` folder in stage6 with modified `rc.local`, and whatever else you want copied into the image. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time and doing Wifi setup. +1. Added a script to flash the Pi LED +1. Files are moved into final locations using the `00-run.sh` script using the `install` command. See the script for details. I also `touch /boot/ssh` here so SSH is ready out of the box. +1. Run `sudo ./build.sh` from the `pi-gen` directory. +1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in all successful stages and rerun `sudo CLEAN=1 ./build.sh` From 8e2b69ebbcfa735792c64cc0e568ccfa7fbb494d Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 22:27:04 -0500 Subject: [PATCH 54/67] Prepping for merge to main repo --- {headless-scripts => setup/headless_setup}/Readme.md | 0 .../headless_setup}/teslausb_setup_variables.conf.sample | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {headless-scripts => setup/headless_setup}/Readme.md (100%) rename {headless-scripts => setup/headless_setup}/teslausb_setup_variables.conf.sample (100%) diff --git a/headless-scripts/Readme.md b/setup/headless_setup/Readme.md similarity index 100% rename from headless-scripts/Readme.md rename to setup/headless_setup/Readme.md diff --git a/headless-scripts/teslausb_setup_variables.conf.sample b/setup/headless_setup/teslausb_setup_variables.conf.sample similarity index 100% rename from headless-scripts/teslausb_setup_variables.conf.sample rename to setup/headless_setup/teslausb_setup_variables.conf.sample From a3457448adb97a0bc5adf277c9b7c6dfe3cb7b1c Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 22:36:00 -0500 Subject: [PATCH 55/67] More prep for merge --- README.md | 244 +++++++++++++++++---------------- setup/headless_setup/Readme.md | 2 +- 2 files changed, 130 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index 34ef63b..14775f5 100644 --- a/README.md +++ b/README.md @@ -1,138 +1,152 @@ -# Flashable image to get started more quickly +# teslausb -# This is a WORK IN PROGRESS, SHOULD CURRENTLY BE WORKING. +## Meta +This repo contains steps and scripts originally from [this thread on Reddit]( https://www.reddit.com/r/teslamotors/comments/9m9gyk/build_a_smart_usb_drive_for_your_tesla_dash_cam/) +Many people in that thread suggested that the scripts be hosted on Github but the author didn't seem interested in making that happen. I've hosted the scripts here with his/her permission. -## Notes +The original post on Reddit assumed that the archive would be hosted on Windows and that the Pi would be set up using a Windows machine (or a Mac using File Sharing, or Linux using Samba) but this Git repo welcomes the contribution of instructions for other platforms. -* Assumes your Pi has access to Wifi, with internet access (during setup). (But all setup methods do currently.) USB networking is still enabled for troubleshooting or manual setup -* This image will work for either _headless_ (tested) or _manual_ (tested less) setup. -* Currently not tested with the RSYNC/SFTP method when using headless setup. +## Intro -## Configure the SD card before first boot of the Pi +You can configure a Raspberry Pi Zero W so that your Tesla thinks it's a USB drive and will write dashcam footage to it. Since it's a computer, you can run scripts on the Pi to automatically copy the clips to an archive server when you get home. The Pi is going to continually: +1. Wait until it can connect to the archive server +1. Archive the clips +1. Wait until it can't connect to the archive server +1. GOTO 1. -1. Flash the [latest image release](https://github.com/rtgoodwin/teslausb/releases) using Etcher or similar. +The scripts in this repo will also allow you to use the Pi to store music that the Tesla can read through the USB interface. -### For headless (automatic) setup +Archiving the clips can take from seconds to hours depending on how many clips you've saved and how strong the WiFi signal is in your Tesla. If you find that the clips aren't getting completely transferred before the car powers down after you park or before you leave you can use the Tesla app to turn on the Climate control. This will send power to the Raspberry Pi, allowing it to complete the archival operation. -1. Mount the card again, and in the `boot` directory create a `teslausb_setup_variables.conf` file to export the same environment varibles normally needed for manual setup (including archive info, Wifi, and push notifications (if desired). -A sample conf file is located in the `boot` folder on the SD card. +## Prerequisites +### Assumptions +* You park in range of your wireless network. +* Your wireless network is configured with WPA2 PSK access. +* You'll be archiving your dashcam clips to a Windows machine (or a Mac using File Sharing, or Linux using Samba), and the Windows machine has a stable IP address on your home network. +* You'll be setting up the Raspberry Pi using a Windows machine, or Mac/Linux (a script is provided in the setup/macos_linux dir), or [the experimental flashable base image](https://github.com/cimryan/teslausb/tree/master/setup/headless_setup). - The file should contain the entries below at a minimum, but **replace with your own values**: +### Hardware + +Required: +* [Raspberry Pi Zero W](https://www.raspberrypi.org/products/raspberry-pi-zero-w/): [Adafruit](https://www.adafruit.com/product/3400) or [Amazon](https://www.amazon.com/Raspberry-Pi-Zero-Wireless-model/dp/B06XFZC3BX/) + > Note: Of the many varieties of Raspberry Pi, only the Raspberry Pi Zero and Raspberry Pi Zero W can be used as simulated USB drives. It may be possible to use a Pi Zero with a USB Wifi adapter to achieve the same result as the Pi Zero W, but this hasn't been confirmed. + +* A Micro SD card, at least 8 GB in size, and an adapter (if necessary) to connect the card to your computer. +* A mechanism to connect the Pi to the Tesla. Either: + * A USB A/Micro B cable: [Adafruit](https://www.adafruit.com/product/898) or [Amazon](https://www.amazon.com/gp/product/B013G4EAEI/), or + * A USB A Add-on Board if you want to plug your Pi into your Tesla like a USB drive instead of using a cable. [Amazon](https://www.amazon.com/gp/product/B07BK2BR6C/) + +Optional: +* A case. Don't want unprotected circuits hanging about! Official case at [Adafruit](https://www.adafruit.com/product/2885) or [Amazon](https://www.amazon.com/gp/product/B06Y593MHV). There are many others to choose from. Note that the official case won't work with the USB A Add on board. +* USB Splitter if you don't want to lose a front USB port. [The Onvian Splitter](https://www.amazon.com/gp/product/B01KX4TKH6) has been reported working by multiple people on reddit. + +### Software +Download [Raspbian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/) +* Note: Bittorrent is dramatically faster than direct download. + +Download and install: +* [Etcher](http://etcher.io) + +## Create your archive +### 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. +* 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 +**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*** + +## Set up the Raspberry 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. + +### Get the OS onto the micro SD card + +[These instructions](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) tell you how to get Raspbian onto your MicroSD card. Basically: +1. Connect your SD card to your computer. +2. Use Etcher to write the zip file you downloaded to the SD card. Etcher works well and is multi-platform. + > 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](doc/GetShellWithoutMonitorOnWindows.md). + +If you used a Mac or a Linux computer, follow these [Instructions](doc/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. Try to ping your archive server from the Pi. In this example the server is named `nautilus`. + ``` + ping -c 3 nautilus + ``` +1. If the server can't be reached, ping its IP address: + ``` + 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: + ``` + 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](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 export sharename=SailfishCam export shareuser=sailfish export sharepassword=pa$$w0rd - export campercent=100 - export SSID=your_ssid - export WIFIPASS=your_wifi_password - export HEADLESS_SETUP=true - export REPO=rtgoodwin - export BRANCH=headless-patch - # Currently set to track this repo/branch while under development. - - # export pushover_enabled=false - # export pushover_user_key=user_key - # export pushover_app_key=app_key ``` - (For now, please leave the REPO and BRANCH set to the settings above.) - -* Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5) and then a reboot and/or the CAM/music drives to become available on your PC/Mac. The LED flash stages are: - -| Stage (number of flashes) | Activity | -|---|---| -| 2 | Verify setup variables | -| 3 | Grab scripts to start/continue setup | -| 4 | Create partition and files to store camera clips/music) | -| 5 | Setup completed; remounting filesystems as read-only and rebooting | - - - -* The Pi should be available for `ssh` at `pi@teslausb.local`, over Wifi (if automatic setup works) or USB networking (if it doesn't). It takes about 5 minutes, or more depending on network speed, etc. -* If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go. -* You should see in `/boot` the `TESLAUSB_SETUP_FINISHED` and `WIFI_ENABLED` files as markers of headless setup success as well. - -### For manual setup - -1. After flashing the image, boot it in your Pi and: - * connect via USB networking at `ssh pi@teslausb.local`. (The Pi must be connected to your PC and plugged into the port labeled USB on the Pi. Or... - * You can also just automate the Wifi portion of setup by creating the `boot/teslausb_setup_variables.conf` file and populating it with the `SSID` and `WIFIPASS` variables: +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: ``` - export SSID=your_ssid - export WIFIPASS=your_wifi_pass + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/pi/setup-teslausb + chmod +x setup-teslausb + ./setup-teslausb ``` +1. Run this command: + ``` + halt + ``` +1. Disconnect the Pi from the computer. -1. Once you have an `ssh` session, follow the steps starting at [Set up the USB storage functionality](https://github.com/cimryan/teslausb#set-up-the-usb-storage-functionality) in the main guide. +On the next boot, the Pi hostname will become `teslausb`, so future `ssh` sessions will be `ssh pi@teslausb.local`. -### Troubleshooting +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. -#### Headless (full or Wifi) setup -* `ssh` to `pi@teslausb.local` (assuming Wifi came up, or your Pi is connected to your computer via USB) and look at the `/boot/teslausb-headless-setup.log`. -* Try `sudo -i` and then run `/etc/rc.local`. The scripts are fairly resilient to restarting and not re-running previous steps, and will tell you about progress/failure. -* If Wifi didn't come up: - * Double-check the SSID and WIFIPASS variables in `teslausb_setup_variables.conf`, and remove `/boot/WIFI_ENABLED`, then booting the SD in your Pi to retry automatic Wifi setup. - * If still no go, re-run `/etc/rc.local` - * If all else fails, copy `/boot/wpa_supplicant.conf.sample` to `/boot/wpa_supplicant.conf` and edit out the `TEMP` variables to your desired settings. -* (Note: if you get an error about `read-only filesystem`, you may have to `sudo -i` and run `/root/bin/remountfs_rw`. +## (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. -# Background information -## What happens under the covers - -When the Pi boots the first time: -* A `/boot/teslausb-headless-setup.log` file will be created and stages logged. -* Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress. -* Wifi is detected by looking for `/boot/WIFI_ENABLED` and if not, creates the `wpa_supplicant.conf` file in place, using `SSID` and `WIFIPASS` from `teslausb_setup_varibles.conf` and reboots. -* The Pi LED will flash patterns (2, 3, 4, 5) as it gets to each stage (labeled in the setup-teslausb-headless script). - * ~~10 flashes means setup failed!~~ (not currently working) -* After the final stage and reboot the LED will go back to normal. Remember, the step to remount the filesystem takes a few minutes. - -At this point the next boot should start the Dashcam/music drives like normal. If you're watching the LED it will start flashing every 1 second, which is the archive loop running. - -> NOTE: Don't delete the `TESLAUSB_SETUP_FINISHED` or `WIFI_ENABLED` files. This is how the system knows setup is complete. - -### Image builder source and patches - -For now the image creation work is at: -* Modified pi-gen [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). -* `headless-patch` branch of rtgoodwin fork [https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts](https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts) - - -### Image refinement TODOs -1. ~~Patch the hostname to teslausb~~ -1. Make it so if someone deletes the `TESLAUSB_SETUP_FINISHED` file it's handled gracefully. (Right now it will try to re-run setup which should be fine.) -1. Cache the remount packages? Might mess with first boot like `rsyslog` -1. Aspirational TODO: Remove more packages and set services to stopped to make the boot process faster? -1. At this point, it's designed to pull the setup scripts _dynamically_, since development is still ongoing. If/when we reach a good frozen state, we can generate an image that is essentially ready to run. I think it'll also be pretty tricky to do some of the remounting and creating the backing files etc. on the image creation side. Open to suggestions/contributions there though! - - -#### Modifications to pi-gen builder from master - -The image is built on a Raspberry Pi 3B running Stretch, for maximum Pi-ception. - -This is the basic configuration, but it's helpful to just [look at the code itself](https://github.com/rtgoodwin/pi-gen/tree/teslausb-headless-image) and the Readme for Pi-gen which explains this all in much greater detail: - -1. Added SKIP and SKIP_IMAGES files to stage3, 4, and 5 (if present). We want to build the default image up to stage2, then add our own stage for tweaks we want. -1. Added a `stage6` (or 7, just something beyond stage5). (There are stages 0-4 in the main Raspbian pi-gen repo by default, but may be a stage5 in some cases. This will help keep a clean merge later.) -1. Copy the prerun.sh from `stage2`. Be SURE to `chmod +x` it. -1. Remove or rename the EXPORT_NOOBS files in all stages. We don't need a NOOBS image built. -1. In `stage6`, create a `00-tweaks` folder, with a `00-patches` folder and patches inside. Currently patched: - - | File | Change | - |---|---| - | `cmdline.txt`| Add the dwc2,g_ether modules | - | `config.txt`| Add the dwc2 module | - | `hosts` | Change hostname to `teslausb` | - | `hostname` | Change hostname to `teslausb` | - - * The build process uses `quilt` for patching - * The path for any patching you do at this stage is `stage6/rootfs/FILEPATH` where `rootfs` represents the Pi's `/`. So, `cmdline.txt` is `stage6/rootfs/boot/cmdline.txt`. - -1. Added a file called `series` in the patches directory with the name of each `.diff` file in the order you want them applied. -1. Added a `files` folder in stage6 with modified `rc.local`, and whatever else you want copied into the image. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time and doing Wifi setup. -1. Added a script to flash the Pi LED -1. Files are moved into final locations using the `00-run.sh` script using the `install` command. See the script for details. I also `touch /boot/ssh` here so SSH is ready out of the box. -1. Run `sudo ./build.sh` from the `pi-gen` directory. -1. If you get a failure, it's almost certainly after stage2, so you can add SKIP files in all successful stages and rerun `sudo CLEAN=1 ./build.sh` +To make changes to the system partitions: +``` +ssh pi@teslausb. +sudo -i +/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. diff --git a/setup/headless_setup/Readme.md b/setup/headless_setup/Readme.md index 9fa7d88..80aa037 100644 --- a/setup/headless_setup/Readme.md +++ b/setup/headless_setup/Readme.md @@ -131,7 +131,7 @@ This is the basic configuration, but it's helpful to just [look at the code itse * The path for any patching you do at this stage is `stage6/rootfs/FILEPATH` where `rootfs` represents the Pi's `/`. So, `cmdline.txt` is `stage6/rootfs/boot/cmdline.txt`. 1. Added a file called `series` in the patches directory with the name of each `.diff` file in the order you want them applied. -1. Added a `files` folder in stage6 with modified `rc.local`, and whatever else you want copied into the image. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time and doing Wifi setup. +1. Added a `files` folder in stage6 with modified `rc.local`, and whatever else you want copied into the image. The modified `rc.local` will handle pulling down the `setup-teslausb-headless` file the first time and doing Wifi setup. 1. Added a script to flash the Pi LED 1. Files are moved into final locations using the `00-run.sh` script using the `install` command. See the script for details. I also `touch /boot/ssh` here so SSH is ready out of the box. 1. Run `sudo ./build.sh` from the `pi-gen` directory. From 98fab1774c056cb4610368ad02833eee0554f73d Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 22:46:07 -0500 Subject: [PATCH 56/67] Updated sample conf file --- .../teslausb_setup_variables.conf.sample | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/setup/headless_setup/teslausb_setup_variables.conf.sample b/setup/headless_setup/teslausb_setup_variables.conf.sample index 422a001..140e355 100644 --- a/setup/headless_setup/teslausb_setup_variables.conf.sample +++ b/setup/headless_setup/teslausb_setup_variables.conf.sample @@ -1,13 +1,43 @@ +##################################################################### +# SAMPLE CONFIGURATION FILE FOR TESLAUSB Pi Setup +# +# Example config file for teslausb_setup. Lines with "#" are comments/ignored. +# Remove the "#" before "export" to activate a line. Be sure to rename this file +# to "teslausb_setup_variables.conf" and place it in the "boot" folder of your +# SD card. +# +###################################################################### + +# Default variables for CIFS (Windows/Mac file sharing) setup export archiveserver=your_archive_name_or_ip export sharename=your_archive_share_name export shareuser=username export sharepassword=password export campercent=100 + +# Wifi setup information export SSID=your_ssid export WIFIPASS=your_pass + +# If doing a headless (i.e. automatic) setup export HEADLESS_SETUP=true -export REPO=rtgoodwin -export BRANCH=headless-patch + +# Uncomment if setting up Pushover push notifications # export pushover_enabled=false # export pushover_user_key=user_key -# export pushover_app_key=app_key \ No newline at end of file +# export pushover_app_key=app_key + +# Uncomment and change if you want setup scripts to be pulled +# from a different repo than the "main" github.com/cimryan/teslausb +# export REPO=cimryan + +# Uncomment and change if you want a different branch than master +# export BRANCH=master + +# Uncomment if you're using rsync/ssh for the archive. +# Note: RSYNC is not usable for headless setup since it currently requires a manual step. +# Note: RSYNC_ENABLE=true is going to disable the default archive server. +# export RSYNC_ENABLE=true +# export RSYNC_USER= +# export RSYNC_SERVER= +# export RSYNC_PATH= \ No newline at end of file From b3ab7788cf3bbbe7afb71295f0568dc38d991ffe Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Sat, 27 Oct 2018 22:52:07 -0500 Subject: [PATCH 57/67] Updated readme to not use my fork (if this gets merged) --- setup/headless_setup/Readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup/headless_setup/Readme.md b/setup/headless_setup/Readme.md index 80aa037..097981b 100644 --- a/setup/headless_setup/Readme.md +++ b/setup/headless_setup/Readme.md @@ -29,15 +29,15 @@ A sample conf file is located in the `boot` folder on the SD card. export SSID=your_ssid export WIFIPASS=your_wifi_password export HEADLESS_SETUP=true - export REPO=rtgoodwin - export BRANCH=headless-patch - # Currently set to track this repo/branch while under development. + # export REPO=rtgoodwin + # export BRANCH=headless-patch + # By default will use the main repo, but if you've been asked to test the image, + # these variables should be uncommunted and updated to point to the right repo/branch # export pushover_enabled=false # export pushover_user_key=user_key # export pushover_app_key=app_key ``` - (For now, please leave the REPO and BRANCH set to the settings above.) * Boot it in your Pi, give it a bit, watching for a series of flashes (2, 3, 4, 5) and then a reboot and/or the CAM/music drives to become available on your PC/Mac. The LED flash stages are: From b43e4d709d46fcd05c79486d453f10a89d135e28 Mon Sep 17 00:00:00 2001 From: Ray Tanaka Date: Sun, 28 Oct 2018 10:15:54 -0700 Subject: [PATCH 58/67] making change to leverage the new /mutable directory updating docs for clarification --- README.md | 4 ++-- doc/SetupRClone.md | 4 ++-- setup/pi/make-root-fs-readonly.sh | 33 ++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 40f525f..06914af 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Get the IP address of the archive machine. You'll need this later, so write it d 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. ### Hosting via rclone (for Google Drive, S3, DropBox, etc) -**EXPERIMENTAL** - This hasn't been thoroughly tested yet but you can follow these [instructions](/doc/SetupRClone.md) and give it a spin. +**EXPERIMENTAL** - This hasn't been thoroughly tested yet but you can follow these [instructions](/doc/SetupRClone.md) to setup up and configure rclone to work with teslausb. ### ***TODO: Other hosting solutions*** @@ -107,7 +107,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](doc/SetupRSync.md) and skip step 7. Otherwise, skip this step. +1. **Only for SFTP/rsync or rclone archives**: If you are trying to archive on an SFTP/rsync server, then follow these [instructions](doc/SetupRSync.md) and skip step 7. If you set up rclone you can also skip step 7 and go to step 8. 1. If you are trying to archive on a shared drive, run these commands, subsituting your values for your shared drive: ``` export archiveserver=Nautilus diff --git a/doc/SetupRClone.md b/doc/SetupRClone.md index e4aaa55..72ce8b4 100644 --- a/doc/SetupRClone.md +++ b/doc/SetupRClone.md @@ -16,7 +16,7 @@ curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash You can also install the script manually by following these [instructions](https://github.com/pageauc/rclone4pi/wiki#manual-install). -Once installed, the script will install rclone-install.sh, rclone-sync.sh and create a subfolder rpi-sync in users home eg. /home/pi +Once installed, the script will install rclone-install.sh, rclone-sync.sh and create a subfolder rpi-sync in users home eg. /root # Step 2: Configure rclone storage system @@ -26,7 +26,7 @@ Next, run this command as root to configure a storage system. rclone config ``` -**Important:** Run this as root since archiveloop runs as root and the rclone config is bound to the user running the config. +**Important:** Make sure to run this as root since archiveloop runs as root and the rclone config is bound to the user running the config. The config file is also moved with the assumption that the root user ran config. This will launch an interactive setup with a series of questions. I highly recommend you look at the documents for your storage system by going to [rclone](https://rclone.org/) and selecting your storage system from the pull down menu at the stop. diff --git a/setup/pi/make-root-fs-readonly.sh b/setup/pi/make-root-fs-readonly.sh index 1d7882c..fdf2ba6 100644 --- a/setup/pi/make-root-fs-readonly.sh +++ b/setup/pi/make-root-fs-readonly.sh @@ -10,7 +10,7 @@ function append_cmdline_txt_param() { echo "Updating package index files..." apt-get update echo "Removing unwanted packages..." -apt-get remove -y --force-yes --purge triggerhappy logrotate dphys-swapfile fake-hwclock +apt-get remove -y --force-yes --purge triggerhappy logrotate dphys-swapfile apt-get -y --force-yes autoremove --purge # Replace log management with busybox (use logread if needed) echo "Installing ntp and busybox-syslogd..." @@ -22,6 +22,37 @@ append_cmdline_txt_param fastboot append_cmdline_txt_param noswap append_cmdline_txt_param ro +# Move fake-hwclock.data to /mutable directory so it can be updated +if ! findmnt --mountpoint /mutable +then + echo "Mounting the multable partition..." + mount /mutable + echo "Mounted." +fi +if [ ! -e "/mutable/etc" ] +then + mkdir -p /mutable/etc +fi +if [ -e "/etc/fake-hwclock.data" ] +then + echo "Moving fake-hwclock data" + cp /etc/fake-hwclock.data /mutable/etc/fake-hwclock.data + rm /etc/fake-hwclock.data + ln -s /mutable/etc/fake-hwclock.data /etc/fake-hwclock.data +fi + +# Move rclone configs if it exists so we can write to it +if [ ! -e "/mutable/configs" ] +then + mkdir -p /mutable/configs +fi +if [ -e "/root/.config/rclone/rclone.conf" ] +then + echo "Moving rclone configs" + mv /root/.config/rclone /mutable/configs + ln -s /mutable/configs/rclone /root/.config/rclone +fi + # Move /var/spool to /tmp rm -rf /var/spool ln -s /tmp /var/spool From 2fe2e4c475d81a1da66940d96640266fd282bd5c Mon Sep 17 00:00:00 2001 From: cimryan Date: Sun, 28 Oct 2018 22:28:51 -0700 Subject: [PATCH 59/67] Consolidate and standardize documentation. --- README.md | 87 +++++++-------------------- doc/SetupRClone.md | 142 ++++++++++++++++++++++++--------------------- doc/SetupRSync.md | 38 +++++++----- doc/SetupShare.md | 32 ++++++++++ 4 files changed, 152 insertions(+), 147 deletions(-) create mode 100644 doc/SetupShare.md diff --git a/README.md b/README.md index 06914af..c68bd7e 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,12 @@ This repo contains steps and scripts originally from [this thread on Reddit]( ht Many people in that thread suggested that the scripts be hosted on Github but the author didn't seem interested in making that happen. I've hosted the scripts here with his/her permission. -The original post on Reddit assumed that the archive would be hosted on Windows and that the Pi would be set up using a Windows machine but this Git repo welcomes the contribution of instructions for other platforms. - ## Intro -You can configure a Raspberry Pi Zero W so that your Tesla thinks it's a USB drive and will write dashcam footage to it. Since it's a computer, you can run scripts on the Pi to automatically copy the clips to an archive server when you get home. The Pi is going to continually: -1. Wait until it can connect to the archive server -1. Archive the clips -1. Wait until it can't connect to the archive server -1. GOTO 1. - -The scripts in this repo will also allow you to use the Pi to store music that the Tesla can read through the USB interface. +You can configure a Raspberry Pi Zero W so that your Tesla thinks it's a USB drive and will write dashcam footage to it. Since it's a computer: +* Scripts running on the Pi can automatically copy the clips to an archive server when you get home. +* The Pi can hold both dashcam clips and music files. +* The Pi can automatically repair filesystem corruption produced by the Tesla's current failure to properly dismount the USB drives before cutting power to the USB ports. Archiving the clips can take from seconds to hours depending on how many clips you've saved and how strong the WiFi signal is in your Tesla. If you find that the clips aren't getting completely transferred before the car powers down after you park or before you leave you can use the Tesla app to turn on the Climate control. This will send power to the Raspberry Pi, allowing it to complete the archival operation. @@ -24,14 +19,12 @@ Archiving the clips can take from seconds to hours depending on how many clips y ### Assumptions * You park in range of your wireless network. * Your wireless network is configured with WPA2 PSK access. -* You'll be archiving your dashcam clips to a Windows machine, and the Windows machine has a stable IP address on your home network. -* You'll be setting up the Raspberry Pi using a Windows machine. ### Hardware Required: * [Raspberry Pi Zero W](https://www.raspberrypi.org/products/raspberry-pi-zero-w/): [Adafruit](https://www.adafruit.com/product/3400) or [Amazon](https://www.amazon.com/Raspberry-Pi-Zero-Wireless-model/dp/B06XFZC3BX/) - > Note: Of the many varieties of Raspberry Pi only the Raspberry Pi Zero and Raspberry Pi Zero W can be used as simulated USB drives. It may be possible to use a Pi Zero with a USB Wifi adapter to achieve the same result as the Pi Zero W, but this hasn't been confirmed. + > Note: Of the many varieties of Raspberry Pi avaiable only the Raspberry Pi Zero and Raspberry Pi Zero W can be used as simulated USB drives. It may be possible to use a Pi Zero with a USB Wifi adapter to achieve the same result as the Pi Zero W but this hasn't been confirmed. * A Micro SD card, at least 8 GB in size, and an adapter (if necessary) to connect the card to your computer. * A mechanism to connect the Pi to the Tesla. Either: @@ -44,77 +37,41 @@ Optional: ### Software Download [Raspbian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/) -* Note: Bittorrent is dramatically faster than direct download. - Download and install: * [Etcher](http://etcher.io) -## Create your archive -### 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. -* 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 -**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. - -### Hosting via rclone (for Google Drive, S3, DropBox, etc) -**EXPERIMENTAL** - This hasn't been thoroughly tested yet but you can follow these [instructions](/doc/SetupRClone.md) to setup up and configure rclone to work with teslausb. - -### ***TODO: Other hosting solutions*** - ## Set up the Raspberry Pi -There are three phases to setting up the Pi: +There are four 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 archive for dashcam clips. 1. Set up the USB storage functionality. -### Get the OS onto the micro SD card - +### Get the OS onto the MicroSD card [These instructions](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) tell you how to get Raspbian onto your MicroSD card. Basically: 1. Connect your SD card to your computer. -2. Use Etcher to write the zip file you downloaded to the SD card. Etcher works well and is multi-platform. +2. Use Etcher to write the zip file you downloaded to the SD card. > 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](doc/GetShellWithoutMonitorOnWindows.md). +Follow the instructions corresponding to the OS you used to flash the OS onto the MicroSD card: +* Windows: [Instructions](doc/GetShellWithoutMonitorOnWindows.md). +* MacOS or Linux: [Instructions](doc/GetShellWithoutMonitorOnLinux.md). -If you used a Mac or a Linux computer, follow these [Instructions](doc/GetShellWithoutMonitorOnLinux.md). +Whichever instructions you followed above will leave you in a command shell on the Pi. Use this shell for the rest of the steps in these instructions. + +### Set up the archive for dashcam clips +Follow the instructions corresponding to the technology you'd like to use to host the archive for your dashcam clips. You must choose just one of these technoloies; don't follow more than one of these sets of instructions: +* Windows file share, MacOS Sharing, or Samba on Linux: [Instructions](doc/SetupShare.md). +* SFTP/rsync: [Instructions](doc/SetupRsync.md) +* **Experimental:** Google Drive, Amazon S3, DropBox, Microsoft OneDrive: [Instructions](doc/SetupRClone.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. Try to ping your archive server from the Pi. In this example the server is named `nautilus`. - ``` - ping -c 3 nautilus - ``` -1. If the server can't be reached, ping its IP address: - ``` - 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. Indicate how much, as a percentage, of the drive you want to allocate to recording dashcam footage by running this command: ``` 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. **Only for SFTP/rsync or rclone archives**: If you are trying to archive on an SFTP/rsync server, then follow these [instructions](doc/SetupRSync.md) and skip step 7. If you set up rclone you can also skip step 7 and go to step 8. -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 - export shareuser=sailfish - export sharepassword=pa$$w0rd - ``` + 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 allocate half of the space for a dashcam footage drive and allocates the other half to for a music storage drive. 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: ``` @@ -137,7 +94,7 @@ Connect the Pi to a computer. If you're using a cable be sure to use the port la 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. Unplug the Pi from the computer. 1. Plug the Pi into your Tesla. ## Making changes to the system after setup diff --git a/doc/SetupRClone.md b/doc/SetupRClone.md index 72ce8b4..02d14ee 100644 --- a/doc/SetupRClone.md +++ b/doc/SetupRClone.md @@ -1,85 +1,93 @@ # Introduction -This guide will show you how to install and configure [rclone4pi](https://github.com/pageauc/rclone4pi/wiki) (based off [rclone](https://rclone.org/)) to archive your saved TeslaCam footage on a number of different remote storage services including (Google Drive, S3 and Dropbox). +This guide will show you how to install and configure [rclone4pi](https://github.com/pageauc/rclone4pi/wiki) (based off [rclone](https://rclone.org/)) to archive your saved TeslaCam footage on one of a number of different remote storage services including Google Drive, S3 and Dropbox. -This guide assumes you have **NOT** run the `setup-teslacam` script yet +You must perform these steps **after** getting a shell on the Pi and **before** running the `setup-teslacam` script on the Pi. -# Step 1: Install rclone4pi +**Make sure to run all commands in these instructions in a single command shell as root. When you return to the [Main Instructions](/README.md) continue running the commands there in this same shell.** This is necessary because: +* The `archiveloop` script runs as root and the rclone config is bound to the user running the config. +* These commands define environment variables that the main setup scripts need. -The first step is to get the [rclone4pi](https://github.com/pageauc/rclone4pi/wiki) binary installed on the raspberry pi. You can do this by executing the following command: +# Quick guide +These instructions will speed you through the process with good defaults. If you encounter an error, or you want to use a different config name than `gdrive` or a different folder name than `TeslaCam`, follow the detailed instuctions, below. +1. Run these commands. Specify the config name `gdrive` when prompted for the config name. + ``` + sudo -i + curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash + rclone config + ``` +1. Run these commands: + ``` + export RCLONE_ENABLE=true + export RCLONE_DRIVE=gdrive + export RCLONE_PATH=TeslaCam + + rclone mkdir "$RCLONE_DRIVE:$RCLONE_PATH" + rclone lsd "$RCLONE_DRIVE": + ``` +1. If you didn't encounter any error messages and you see the `TeslaCam` directory listed return to the [Main Instructions](../README.md). -``` -curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash -``` +# Detailed instructions +## Step 1: Install rclone4pi +1. Run this command to enter a command shell for the root user. + ``` + sudo -i + ``` +2. Run the following command to install rclone4pi: + ``` + curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash + ``` + Alternatively, you can install rclone4pi manually by following these [instructions] (https://github.com/pageauc/rclone4pi/wiki#manual-install). -You can also install the script manually by following these [instructions](https://github.com/pageauc/rclone4pi/wiki#manual-install). - - -Once installed, the script will install rclone-install.sh, rclone-sync.sh and create a subfolder rpi-sync in users home eg. /root - -# Step 2: Configure rclone storage system - -Next, run this command as root to configure a storage system. - -``` -rclone config -``` - -**Important:** Make sure to run this as root since archiveloop runs as root and the rclone config is bound to the user running the config. The config file is also moved with the assumption that the root user ran config. - -This will launch an interactive setup with a series of questions. I highly recommend you look at the documents for your storage system by going to [rclone](https://rclone.org/) and selecting your storage system from the pull down menu at the stop. - -I've only personally tested this with Google Drive using these [instructions](https://rclone.org/drive/). One thing to note is the importance of setting the correct [scope](https://rclone.org/drive/#scopes) you are providing access to. Carefully read the documentation on [scopes on rclone](https://rclone.org/drive/#scopes) as well as [Google Drive](https://developers.google.com/drive/api/v3/about-auth). I recommend going with drive.file scope. - -**Important:** Take note of the name you used for this config. You will need it later. The rest of the document will use `gdrive` as the name since that's what I used. +# Step 2: Configure the archive +1. Run this command to configure an archive: + ``` + rclone config + ``` + This will launch an interactive setup with a series of questions. It is recommended that you look at the documentation for your storage system by going to [rclone](https://rclone.org/) and selecting your storage system from the pull down menu at the stop. + + It has been confirmed that this process works with Google Drive using these [instructions](https://rclone.org/drive/). If you are using another storage system, please feel encouraged to create an "Issue" describing your challenges and/or your success. + + If you are using Google Drive it is important to set the correct [scope](https://rclone.org/drive/#scopes). Carefully read the documentation on [scopes on rclone](https://rclone.org/drive/#scopes) as well as [Google Drive](https://developers.google.com/drive/api/v3/about-auth). The `drive.file` scope is recommended. + + **Important:** During the `rclone config` process you will sepcify a name for the configuration. The rest of the document will assume the use of the name `gdrive`; replace this with your chosen configuration name. +1. Run this command: + ``` + export RCLONE_DRIVE="gdrive" + ``` # Step 3: Verify and create storage directory -Run the following command (again, as root) to see the name of the remote drive you just created. - -``` -rclone listremotes -``` - -If you don't see the name there, something went wrong and you'll likely have to go back through the config process. If all went well, use - - -``` -rclone lsd gdrive: -``` - -At this point, you should not see anything if you set your scope correctly. Now we need to create a folder to put all our archives in. You can do this by running this command. I used TeslaCam but you can name it whatever you want as long as you set it in the next step below. - -``` -rclone mkdir gdrive:TeslaCam -``` - -Run this one last command again - -``` -rclone lsd gdrive: -``` - -Once you confirm that the directoy you just created is there, we're all set to move on! +1. Run the following command to see the name of the remote drive you just created. + ``` + rclone listremotes + ``` + If you don't see the name there, something went wrong. Go back through the `rclone config` process. +1. Run this command: + ``` + rclone lsd "$RCLONE_DRIVE": + ``` + You should not see any files listed. If you do then you did not set your scope correctly during the `rclone config` process. +1. Choose the name of a folder to hold the archived clips. These instructions will assume you chose the name `TeslaCam`. Substitute the name you chose for this name. Run this command: + ``` + export RCLONE_PATH="TeslaCam" + ``` +1. Run the following command to create a folder which will hold the archived clips. + ``` + rclone mkdir "$RCLONE_DRIVE:TeslaCam" + ``` +1. Run this command again: + ``` + rclone lsd "RCLONE_DRIVE": + ``` +Confirm that the directory `TeslaCam` is present. If not, start over. # Step 4: Exports - -To be able to configure the teslausb pi to use rclone, you'll need to export a few things. On your teslausb pi, run: - +Run this command to cause the setup processes which you'll resume in the main instructions to use rclone4pi: ``` export RCLONE_ENABLE=true -export RCLONE_DRIVE= -export RCLONE_PATH= -``` - -An example of my config is listed below: - -``` -export RCLONE_ENABLE=true -export RCLONE_DRIVE=gdrive -export RCLONE_PATH=TeslaCam ``` **Note:** `RCLONE_ENABLE=true` is going to disable the default archive server. It also will **not** play nicely with `RSYNC_ENABLE=true` 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 +Now return to the section "Set up the USB storage functionality" in the [main instructions](../README.md). diff --git a/doc/SetupRSync.md b/doc/SetupRSync.md index 7106a7a..0d586ac 100644 --- a/doc/SetupRSync.md +++ b/doc/SetupRSync.md @@ -1,21 +1,33 @@ # 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 will show you how to use [rsync](https://rsync.samba.org/) to archive your saved TeslaCam footage on a remote storage server. + +Since sftp/rsync accesses a computer through SSH the only requirement for hosting an SFTP/rsync server is to have a box running SSH. For example, you could use 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. 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 +* 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. +* The ftp/rsync server has rsync installed (raspbian automatically does) + # 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. +Similar to sftp, rsync by default uses ssh to connect to a remote server and transfer files. This guide will use a generated ssh keypair, hence the first assumption above. -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. Run these commands to to generate an ssh key for the `root` user: + ``` + sudo -i + ssh-keygen + ``` -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. 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. You can do this by connectin via ssh to the archive server from the computer you're using to set up the Pi, editing the `~/.ssh/authorized_keys` in nano, and pasting in the content of the `/root/.ssh/id_rsa.pub` file from the teslausb Pi. -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. +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 **when you are asked if you wish to continue connecting type `yes`** + ``` + ssh user@archiveserver + ``` + If you do not do this then 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: +Run this command to cause the setup processes which you'll resume in the main instructions to use rsync: ``` export RSYNC_ENABLE=true @@ -23,21 +35,17 @@ 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: - +An example config is 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.*** - -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 +Now return to the section "Set up the USB storage functionality" in the [main instructions](../README.md). \ No newline at end of file diff --git a/doc/SetupShare.md b/doc/SetupShare.md new file mode 100644 index 0000000..cee21aa --- /dev/null +++ b/doc/SetupShare.md @@ -0,0 +1,32 @@ +# Hosting the archive on Windows File Shares, MacOS Sharing, or Samba on Linux +Set up a share to host the archive on a computer on your home network. 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". + +Now, on the Pi: +1. Try to ping your archive server from the Pi. In this example the server is named `nautilus`. + ``` + ping -c 3 nautilus + ``` +1. If the server can't be reached, ping its IP address (These instructions will assume that the IP address of the archive server is `192.168.0.41`.): + ``` + ping 192.168.0.41 + ``` + To get the IP address of the archive machine: + * On Windows: Open a PowerShell session and type `ipconfig`. Get the IP address from the line labeled "IPv4 Address". + * On MacOS or Linux open a terminal and type ifconfig. + + If you can't ping the archive server by IP address from the Pi, go do whatever you need to on your network to fix that. + + If you can't reach the archive server by name but you can by IP address then use its IP address, below, for the `archiveserver` variable. + +1. Run these commands, subsituting your values: + ``` + sudo -i + export archiveserver="Nautilus" + export sharename="SailfishCam" + export shareuser="sailfish" + export sharepassword="pa$$w0rd" + ``` + +Now return to the section "Set up the USB storage functionality" in the [main instructions](/README.md). \ No newline at end of file From c3554cac89f96c31db0f4a122541a9ab80a85611 Mon Sep 17 00:00:00 2001 From: Gocnak Date: Mon, 29 Oct 2018 00:23:15 -0400 Subject: [PATCH 60/67] Use compression (-z) with rsync This was dropped during the great merge of '18 --- run/rsync_archive/archive-clips.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/rsync_archive/archive-clips.sh b/run/rsync_archive/archive-clips.sh index 29f5a55..4bd8e4b 100644 --- a/run/rsync_archive/archive-clips.sh +++ b/run/rsync_archive/archive-clips.sh @@ -4,7 +4,7 @@ log "Archiving through rsync..." source /root/.teslaCamRsyncConfig -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}') +num_files_moved=$(rsync -auzvh --stats --log-file=/tmp/archive-rsync-cmd.log /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') /root/bin/send-pushover "$num_files_moved" From f15d59702586417a5677440f61779af46cff80ed Mon Sep 17 00:00:00 2001 From: Gocnak Date: Mon, 29 Oct 2018 00:54:19 -0400 Subject: [PATCH 61/67] 10-try retry the disconnect check Also lost in the great merge of '18 --- run/archiveloop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/archiveloop b/run/archiveloop index 9b8674f..81b313a 100644 --- a/run/archiveloop +++ b/run/archiveloop @@ -159,7 +159,7 @@ function wait_for_archive_to_be_unreachable () { log "Waiting for archive to be unreachable..." while [ true ] do - if ! archive_is_reachable + if ! retry archive_is_reachable then log "Archive is unreachable." break From 636b1a1819a618f671e80a3195d7d99d74fd3214 Mon Sep 17 00:00:00 2001 From: Gocnak Date: Mon, 29 Oct 2018 01:32:17 -0400 Subject: [PATCH 62/67] Disregard copying perms to catch another edge case Pesky, was caught up trying to copy permissions over and didn't really need to --- run/rsync_archive/archive-clips.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/rsync_archive/archive-clips.sh b/run/rsync_archive/archive-clips.sh index 4bd8e4b..a87369f 100644 --- a/run/rsync_archive/archive-clips.sh +++ b/run/rsync_archive/archive-clips.sh @@ -4,7 +4,7 @@ log "Archiving through rsync..." source /root/.teslaCamRsyncConfig -num_files_moved=$(rsync -auzvh --stats --log-file=/tmp/archive-rsync-cmd.log /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') +num_files_moved=$(rsync -auzvh --no-perms --stats --log-file=/tmp/archive-rsync-cmd.log /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}') /root/bin/send-pushover "$num_files_moved" From a9bcb5c1adf3eb5189ef5359ff023421e006d6d7 Mon Sep 17 00:00:00 2001 From: Gocnak Date: Mon, 29 Oct 2018 01:33:31 -0400 Subject: [PATCH 63/67] Remove experimental warning from README Works on my end, and has worked before the great '18 merge as well --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c68bd7e..fe17fbd 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Whichever instructions you followed above will leave you in a command shell on t ### Set up the archive for dashcam clips Follow the instructions corresponding to the technology you'd like to use to host the archive for your dashcam clips. You must choose just one of these technoloies; don't follow more than one of these sets of instructions: * Windows file share, MacOS Sharing, or Samba on Linux: [Instructions](doc/SetupShare.md). -* SFTP/rsync: [Instructions](doc/SetupRsync.md) +* SFTP/rsync: [Instructions](doc/pi/SetupRSync.md) * **Experimental:** Google Drive, Amazon S3, DropBox, Microsoft OneDrive: [Instructions](doc/SetupRClone.md) ### Set up the USB storage functionality From 7d9b838420733c8b756d2e8b6fb6f4de45bbe50f Mon Sep 17 00:00:00 2001 From: Gocnak Date: Mon, 29 Oct 2018 01:43:58 -0400 Subject: [PATCH 64/67] Fixed path to instructions for rsync --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fe17fbd..ae8c449 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Whichever instructions you followed above will leave you in a command shell on t ### Set up the archive for dashcam clips Follow the instructions corresponding to the technology you'd like to use to host the archive for your dashcam clips. You must choose just one of these technoloies; don't follow more than one of these sets of instructions: * Windows file share, MacOS Sharing, or Samba on Linux: [Instructions](doc/SetupShare.md). -* SFTP/rsync: [Instructions](doc/pi/SetupRSync.md) +* SFTP/rsync: [Instructions](doc/SetupRSync.md) * **Experimental:** Google Drive, Amazon S3, DropBox, Microsoft OneDrive: [Instructions](doc/SetupRClone.md) ### Set up the USB storage functionality From 810bfa256ad01054b74dffcc3fa575ea4b3719a1 Mon Sep 17 00:00:00 2001 From: cimryan Date: Mon, 29 Oct 2018 06:33:21 -0700 Subject: [PATCH 65/67] Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae8c449..ccc69cd 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Follow the instructions corresponding to the OS you used to flash the OS onto th Whichever instructions you followed above will leave you in a command shell on the Pi. Use this shell for the rest of the steps in these instructions. ### Set up the archive for dashcam clips -Follow the instructions corresponding to the technology you'd like to use to host the archive for your dashcam clips. You must choose just one of these technoloies; don't follow more than one of these sets of instructions: +Follow the instructions corresponding to the technology you'd like to use to host the archive for your dashcam clips. You must choose just one of these technologies; don't follow more than one of these sets of instructions: * Windows file share, MacOS Sharing, or Samba on Linux: [Instructions](doc/SetupShare.md). * SFTP/rsync: [Instructions](doc/SetupRSync.md) * **Experimental:** Google Drive, Amazon S3, DropBox, Microsoft OneDrive: [Instructions](doc/SetupRClone.md) From b34f362ef4bab9be13a3f455c0758766cc3efe8d Mon Sep 17 00:00:00 2001 From: cimryan Date: Mon, 29 Oct 2018 18:53:47 -0700 Subject: [PATCH 66/67] OneStepSetup --- README.md | 12 ++++++++---- .../headless_setup/Readme.md => doc/OneStepSetup.md | 7 ++----- .../teslausb_setup_variables.conf.sample | 0 3 files changed, 10 insertions(+), 9 deletions(-) rename setup/headless_setup/Readme.md => doc/OneStepSetup.md (96%) rename {setup/headless_setup => doc}/teslausb_setup_variables.conf.sample (100%) diff --git a/README.md b/README.md index ccc69cd..e95413c 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,13 @@ Required: * A USB A Add-on Board if you want to plug your Pi into your Tesla like a USB drive instead of using a cable. [Amazon](https://www.amazon.com/gp/product/B07BK2BR6C/) Optional: -* A case. Don't want unprotected circuits hanging about! Official case at [Adafruit](https://www.adafruit.com/product/2885) or [Amazon](https://www.amazon.com/gp/product/B06Y593MHV). There are many others to choose from. Note that the official case won't work with the USB A Add on board. +* A case. The "Official" case: [Adafruit](https://www.adafruit.com/product/2885) or [Amazon](https://www.amazon.com/gp/product/B06Y593MHV). There are many others to choose from. Note that the official case won't work with the USB A Add on board. * USB Splitter if you don't want to lose a front USB port. [The Onvian Splitter](https://www.amazon.com/gp/product/B01KX4TKH6) has been reported working by multiple people on reddit. ### Software -Download [Raspbian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/) -Download and install: -* [Etcher](http://etcher.io) +Download: [Raspbian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/) + +Download and install: [Etcher](http://etcher.io) ## Set up the Raspberry Pi There are four phases to setting up the Pi: @@ -47,6 +47,10 @@ There are four phases to setting up the Pi: 1. Set up the archive for dashcam clips. 1. Set up the USB storage functionality. +There is a streamlined process for setting up the Pi which can currently be used if you plan to use Windows file shares, MacOS Sharing, or Samba on Linux for your video archive. [Instructions](doc/OneStepSetup.md). + +If you'd like to host the archive using another technology or would like to set the Pi up, yourself, continue these instructions. + ### Get the OS onto the MicroSD card [These instructions](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) tell you how to get Raspbian onto your MicroSD card. Basically: 1. Connect your SD card to your computer. diff --git a/setup/headless_setup/Readme.md b/doc/OneStepSetup.md similarity index 96% rename from setup/headless_setup/Readme.md rename to doc/OneStepSetup.md index 097981b..38898ce 100644 --- a/setup/headless_setup/Readme.md +++ b/doc/OneStepSetup.md @@ -1,7 +1,6 @@ -# Flashable image to get started more quickly - -# This is a WORK IN PROGRESS, SHOULD CURRENTLY BE WORKING. +# One-step setup +This is a streamlined process for setting up the Pi. You'll flash a preconfigured version of Raspbian Stretch Lite and then fill out a config file. ## Notes @@ -97,8 +96,6 @@ At this point the next boot should start the Dashcam/music drives like normal. I For now the image creation work is at: * Modified pi-gen [rtgoodwin's fork of pi-gen](https://github.com/rtgoodwin/pi-gen) in (whatever current branch I'm working at the time). -* `headless-patch` branch of rtgoodwin fork [https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts](https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts) - ### Image refinement TODOs 1. ~~Patch the hostname to teslausb~~ diff --git a/setup/headless_setup/teslausb_setup_variables.conf.sample b/doc/teslausb_setup_variables.conf.sample similarity index 100% rename from setup/headless_setup/teslausb_setup_variables.conf.sample rename to doc/teslausb_setup_variables.conf.sample From 1f7ff2d89335e2b99693ad60bf42d14408f9e6b7 Mon Sep 17 00:00:00 2001 From: cimryan Date: Mon, 29 Oct 2018 21:00:26 -0700 Subject: [PATCH 67/67] Erase extra paragraph about the one step setup --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 44f0620..e95413c 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,6 @@ If you'd like to host the archive using another technology or would like to set 2. Use Etcher to write the zip file you downloaded to the SD card. > Note: you don't need to uncompress the zip file you downloaded. -#### (Experimental) - -There is an experimental image that requires only a configuration file. Needs testing and issues filed _on this specific image/process_ at [this repo](https://github.com/rtgoodwin/teslausb/tree/headless-patch/headless-scripts). Issues about general functionality should still be filed on the main (cimryan) repo. - ### Get a shell on the Pi Follow the instructions corresponding to the OS you used to flash the OS onto the MicroSD card: * Windows: [Instructions](doc/GetShellWithoutMonitorOnWindows.md).