From bd90ef535f1c2a7b6067d2ef275042d28dac414a Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Tue, 16 Oct 2018 11:51:26 -0500 Subject: [PATCH 1/8] Initial commit for pushover testing --- .gitignore | 1 + README.md | 12 +++++++++ windows_archive/archive-teslacam-clips | 6 +++++ windows_archive/send-pushover | 9 +++++++ windows_archive/setup-teslausb | 35 ++++++++++++++++++++++++-- 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 windows_archive/send-pushover 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 b88d08b..17e5967 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..ba10801 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -71,12 +71,18 @@ 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)." + log "Sending Pushover message" + /root/bin/send-pushover.sh $move_count log "Finished moving clips to archive." } diff --git a/windows_archive/send-pushover b/windows_archive/send-pushover new file mode 100644 index 0000000..1a20666 --- /dev/null +++ b/windows_archive/send-pushover @@ -0,0 +1,9 @@ +#!/bin/bash -eu + +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 4e40a1b..1e203b8 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -1,5 +1,8 @@ #!/bin/bash -eu +TESLAUSB_REPO=rtgoodwin +TESLAUSB_BRANCH=master + if [ "$(whoami)" != "root" ] then echo "STOP: Run sudo -i." @@ -21,6 +24,32 @@ check_variable "shareuser" check_variable "sharepassword" check_variable "campercent" +function check_pushover_enabled () { + if [ -n "${pushover_enabled+x}" ] + then + if [[ -z "${pushover_user_key+x}" ]] || [[ -z "${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=your_user_key_here" + echo "export pushover_app_key=your_app_key_here" + exit 1 + elif [[ "${pushover_user_key}" = "put_your_user_key_here" ]] || [[ "${pushover_app_key}" = "put_your_app_key_here" ]] + then + echo "STOP: You're trying to setup Pushover but didn't replace the default User and App key values." + exit 1 + else + echo "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 + pushd /root/bin + wget https://raw.githubusercontent.com/"$TESLAUSB_REPO"/teslausb/"$TESLAUSB_BRANCH"/windows_archive/send-pushover + chmod +x send-pushover + popd + fi + fi +} + serverunreachable=false ping -c 1 -w 1 "$archiveserver" 1>/dev/null 2>&1 || serverunreachable=true @@ -71,16 +100,18 @@ echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials mkdir /root/bin -wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/archiveloop +wget https://raw.githubusercontent.com/"$TESLAUSB_REPO"/teslausb/"$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 pushd /root/bin -wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/archive-teslacam-clips +wget https://raw.githubusercontent.com/"$TESLAUSB_REPO"/teslausb/"$TESLAUSB_BRANCH"/windows_archive/archive-teslacam-clips chmod +x archive-teslacam-clips popd +check_pushover_enabled + echo "#!/bin/bash -eu" > ~/rc.local tail -n +2 /etc/rc.local | sed '$d' >> ~/rc.local cat << 'EOF' >> ~/rc.local From adcf8fd2de9053e664cbb3e8c0e64ac8c6a220fe Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Tue, 16 Oct 2018 12:25:15 -0500 Subject: [PATCH 2/8] Better error checking. --- windows_archive/archive-teslacam-clips | 7 +++++-- windows_archive/send-pushover | 5 +++++ windows_archive/setup-teslausb | 16 ++++++---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index ba10801..681392c 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -81,8 +81,11 @@ function move_clips_to_archive () { done log "Moved $move_count file(s)." - log "Sending Pushover message" - /root/bin/send-pushover.sh $move_count + 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 index 1a20666..6948c06 100644 --- a/windows_archive/send-pushover +++ b/windows_archive/send-pushover @@ -1,5 +1,10 @@ #!/bin/bash -eu +function log () { + echo "$( date )" >> "$LOG_FILE" + echo "$1" >> "$LOG_FILE" +} + source /root/.teslaCamPushoverCredentials curl -F "token=$pushover_app_key" \ diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 1e203b8..b5e27f8 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -27,25 +27,21 @@ check_variable "campercent" function check_pushover_enabled () { if [ -n "${pushover_enabled+x}" ] then - if [[ -z "${pushover_user_key+x}" ]] || [[ -z "${pushover_app_key+x}" ]] + 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=your_user_key_here" - echo "export pushover_app_key=your_app_key_here" + 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_user_key_here" ]] || [[ "${pushover_app_key}" = "put_your_app_key_here" ]] + 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." + echo "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." exit 1 else - echo "export pushover_enabled=true" > /root/.teslaCamPushoverCredentials + echo "export pushover_enabled=true" > /root/bin/.teslaCamPushoverCredentials echo "export pushover_user_key=$pushover_user_key" >> /root/.teslaCamPushoverCredentials echo "export pushover_app_key=$pushover_app_key" >> /root/.teslaCamPushoverCredentials - pushd /root/bin - wget https://raw.githubusercontent.com/"$TESLAUSB_REPO"/teslausb/"$TESLAUSB_BRANCH"/windows_archive/send-pushover - chmod +x send-pushover - popd fi fi } From f477fc434865370e39932cb211a7a54919146879 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Tue, 16 Oct 2018 12:48:07 -0500 Subject: [PATCH 3/8] Even more error checking. --- windows_archive/setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index b5e27f8..e601c4a 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -25,7 +25,7 @@ check_variable "sharepassword" check_variable "campercent" function check_pushover_enabled () { - if [ -n "${pushover_enabled+x}" ] + if [ ! -z "${pushover_enabled+x}" ] then if [ ! -n "${pushover_user_key+x}" ] || [ ! -n "${pushover_app_key+x}" ] then From d6e63ff7205bdd4f39fe3e8b7453b76c9bcfde9e Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Tue, 16 Oct 2018 13:27:11 -0500 Subject: [PATCH 4/8] Fixed a hyphen typo. --- windows_archive/setup-teslausb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index e601c4a..9b1efa3 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -1,7 +1,8 @@ #!/bin/bash -eu TESLAUSB_REPO=rtgoodwin -TESLAUSB_BRANCH=master +TESLAUSB_BRANCH=pushover +user_enabled_pushover=false if [ "$(whoami)" != "root" ] then @@ -39,13 +40,16 @@ function check_pushover_enabled () { echo "STOP: You're trying to setup Pushover, but didn't replace the default User and App key values." exit 1 else - echo "export pushover_enabled=true" > /root/bin/.teslaCamPushoverCredentials + 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 + serverunreachable=false ping -c 1 -w 1 "$archiveserver" 1>/dev/null 2>&1 || serverunreachable=true @@ -106,7 +110,13 @@ wget https://raw.githubusercontent.com/"$TESLAUSB_REPO"/teslausb/"$TESLAUSB_BRAN chmod +x archive-teslacam-clips popd -check_pushover_enabled +if [ ${user_enabled_pushover} = "true" ] +then + pushd /root/bin + wget https://raw.githubusercontent.com/"$TESLAUSB_REPO"/teslausb/"$TESLAUSB_BRANCH"/windows_archive/send-pushover + chmod +x archive-teslacam-clips + popd +fi echo "#!/bin/bash -eu" > ~/rc.local tail -n +2 /etc/rc.local | sed '$d' >> ~/rc.local From 5c62ba93a0fa5f6fc88fe540aa684f8be0924119 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Tue, 16 Oct 2018 14:37:09 -0500 Subject: [PATCH 5/8] Finalized to open PR --- windows_archive/setup-teslausb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 9b1efa3..89bf17a 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -1,7 +1,7 @@ #!/bin/bash -eu -TESLAUSB_REPO=rtgoodwin -TESLAUSB_BRANCH=pushover +TESLAUSB_REPO=cimryan +TESLAUSB_BRANCH=master user_enabled_pushover=false if [ "$(whoami)" != "root" ] From efbbe0c7190aa173a7c3f498d063d20302db6157 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Wed, 17 Oct 2018 09:11:07 -0500 Subject: [PATCH 6/8] Merging upstream master --- .DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ad3d1f64d179c06c9343837bf0549eb3f12b7263 GIT binary patch literal 6148 zcmeHK!A=`75FIBec!jFufJBbIaLXZ4pq!9aAso0>S_B6`VV8}_O6fYvZdlPYXn&*p zQNN(S!;I}jM4{@Xs!BB@jo)}YW5>^tXAJBb`gu=|B zp@0kq5W;jLnjQZl19WzEJhcQ;h~f45-N6XG4={|1Y!Z!igpog@$vDaKcKfHORBIo$ zwxyIi@}s;7M!E>{FrQ_;aC$|(&tX1_oPDnKcx8vtMKUY~jolNS=3$Z!rzSaxhZu5w znWV8UdU}?|nVBcB1D@weZ_sGY=iP3nrMicmMN7?(j@m7C(EYSncye#Qb9{FDKNnh`z(pB6?8xL%`6$4Kwgp8F&Fq C`&eTD literal 0 HcmV?d00001 From dc62ce2ee474a9852e32c83b9b56fdb0cefbcfe7 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Wed, 17 Oct 2018 10:07:43 -0500 Subject: [PATCH 7/8] Typo on line to grab pushover script. --- windows_archive/setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index a0f6abb..daa1630 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -139,7 +139,7 @@ function configure_pushover_scripts() { if [ ${user_enabled_pushover} = "true" ] then pushd /root/bin - wget https://raw.githubusercontent.com/"$TESLAUSB_REPO"/teslausb/"$TESLAUSB_BRANCH"/windows_archive/send-pushover + wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover chmod +x archive-teslacam-clips popd fi From 24035c5e8697068f40c5bc1a18f748c9e6d7ef33 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Wed, 17 Oct 2018 10:24:59 -0500 Subject: [PATCH 8/8] LAST typo on chmod. Tested working at this point. --- windows_archive/setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index daa1630..045360c 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -140,7 +140,7 @@ if [ ${user_enabled_pushover} = "true" ] then pushd /root/bin wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/send-pushover - chmod +x archive-teslacam-clips + chmod +x send-pushover popd fi }