diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..ad3d1f6 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/README.md b/README.md index 173eb73..59b045c 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,18 @@ Now that you have a shell on the Pi you can turn the Pi into a smart USB drive. export sharepassword=pa$$w0rd export campercent=100 ``` +1. OPTIONAL: You can choose to integrate with [Pushover](https://pushover.net) to get a push notification to your phone when the copy process is done. Depending on your wireless network speed/connection, copying files may take some time, so a push notification can help confirm that the process finished. If no files were copied (i.e. all manually saved dashcam files were already copied, no notification will be sent.). The Pushover service is free for up to 7,500 messages per month, but the [iOS](https://pushover.net/clients/ios)/[Android](https://pushover.net/clients/android) apps do have a one time cost, after a free trial period. *This also assumes your Pi is connected to a network with internet access.* + + * Create a free account at Pushover.net, and install and log into the mobile Pushover app. + * On the Pushover dashboard on the web, copy your **User key**. + * [Create a new Application](https://pushover.net/apps/build) at Pushover.net. The description and icon don't matter, choose what you prefer. + * Copy the **Application Key** for the application you just created. The User key + Application Key are basically a username/password combination to needed to send the push. + * Run these commands, substituting your user key and app key in the appropriate places. No `"` are needed. + ``` + export pushover_enabled=true + export pushover_user_key=put_your_userkey_here + export pushover_app_key=put_your_appkey_here + ``` 1. Run these commands: ``` wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/setup-teslausb diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index 063c7d0..681392c 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -71,12 +71,21 @@ function ensure_mountpoint_is_mounted_with_retry () { function move_clips_to_archive () { log "Moving clips to archive..." + local move_count=0 for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do [ -e "$file_name" ] || continue log "Moving $file_name ..." mv -- "$file_name" "$ARCHIVE_MOUNT" >> "$LOG_FILE" 2>&1 || echo "" log "Moved $file_name." + move_count=$((move_count + 1)) + done + log "Moved $move_count file(s)." + if [ -r "/root/.teslaCamPushoverCredentials" ] + then + log "Sending Pushover message for copied files." + /root/bin/send-pushover.sh $move_count + fi log "Finished moving clips to archive." } diff --git a/windows_archive/send-pushover b/windows_archive/send-pushover new file mode 100644 index 0000000..6948c06 --- /dev/null +++ b/windows_archive/send-pushover @@ -0,0 +1,14 @@ +#!/bin/bash -eu + +function log () { + echo "$( date )" >> "$LOG_FILE" + echo "$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 diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 25466a2..045360c 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -1,6 +1,9 @@ #!/bin/bash -eu +REPO=cimryan BRANCH=master +user_enabled_pushover=false + if ! [ $(id -u) = 0 ] then @@ -17,23 +20,48 @@ 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 + 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 +} + +check_pushover_enabled + 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 ] @@ -41,22 +69,22 @@ function check_available_space () { 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/cimryan/teslausb/"$BRANCH"/windows_archive/create-backingfiles-partition.sh + 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/cimryan/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh chmod +x ./create-backingfiles.sh - wget https://raw.githubusercontent.com/cimryan/teslausb/"$BRANCH"/windows_archive/make-root-fs-readonly.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 () +function fix_cmdline_txt_modules_load () { echo "Fixing the modules-load parameter in /boot/cmdline.txt..." cp /boot/cmdline.txt ~ @@ -70,12 +98,12 @@ 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" + + /tmp/create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT" } function configure_archive () { @@ -83,7 +111,7 @@ function configure_archive () { mkdir /mnt/archive local archive_server_ip_address="$(getent hosts $archiveserver | cut -d' ' -f1)" 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." @@ -93,20 +121,30 @@ function configure_archive_scripts () { echo "Configuring the archive scripts..." mkdir /root/bin - pushd ~ - wget https://raw.githubusercontent.com/cimryan/teslausb/"$BRANCH"/windows_archive/archiveloop + 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/cimryan/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips chmod +x archive-teslacam-clips popd echo "Configured the archive scripts." } +function configure_pushover_scripts() { +if [ ${user_enabled_pushover} = "true" ] +then + pushd /root/bin + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover + chmod +x send-pushover + popd +fi +} + function configure_rc_local () { echo "Configuring /etc/rc.local to run the archive scripts at startup..." echo "#!/bin/bash -eu" > ~/rc.local @@ -132,11 +170,11 @@ EOF 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." @@ -154,6 +192,8 @@ check_variable "shareuser" check_variable "sharepassword" check_variable "campercent" +check_pushover_enabled + check_archive_server_reachable check_available_space @@ -164,6 +204,8 @@ pushd ~ configure_archive_scripts +configure_pushover_scripts + fix_cmdline_txt_modules_load echo "" >> /etc/fstab