Merge pull request #24 from rtgoodwin/pushover

Added Pushover support
This commit is contained in:
cimryan
2018-10-17 10:06:22 -07:00
committed by GitHub
6 changed files with 96 additions and 18 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.DS_Store

View File

@@ -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 sharepassword=pa$$w0rd
export campercent=100 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: 1. Run these commands:
``` ```
wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/setup-teslausb wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/setup-teslausb

View File

@@ -71,12 +71,21 @@ function ensure_mountpoint_is_mounted_with_retry () {
function move_clips_to_archive () { function move_clips_to_archive () {
log "Moving clips to archive..." log "Moving clips to archive..."
local move_count=0
for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do
[ -e "$file_name" ] || continue [ -e "$file_name" ] || continue
log "Moving $file_name ..." log "Moving $file_name ..."
mv -- "$file_name" "$ARCHIVE_MOUNT" >> "$LOG_FILE" 2>&1 || echo "" mv -- "$file_name" "$ARCHIVE_MOUNT" >> "$LOG_FILE" 2>&1 || echo ""
log "Moved $file_name." log "Moved $file_name."
move_count=$((move_count + 1))
done 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." log "Finished moving clips to archive."
} }

View File

@@ -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

View File

@@ -1,6 +1,9 @@
#!/bin/bash -eu #!/bin/bash -eu
REPO=cimryan
BRANCH=master BRANCH=master
user_enabled_pushover=false
if ! [ $(id -u) = 0 ] if ! [ $(id -u) = 0 ]
then then
@@ -17,23 +20,48 @@ function check_variable () {
fi 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 () { function check_archive_server_reachable () {
echo "Verifying that the archive server $archiveserver is reachable..." echo "Verifying that the archive server $archiveserver is reachable..."
local serverunreachable=false local serverunreachable=false
ping -c 1 -w 1 "$archiveserver" 1>/dev/null 2>&1 || serverunreachable=true ping -c 1 -w 1 "$archiveserver" 1>/dev/null 2>&1 || serverunreachable=true
if [ "$serverunreachable" = true ] if [ "$serverunreachable" = true ]
then then
echo "STOP: The archive server $archiveserver is unreachable. Try specifying its IP address instead." echo "STOP: The archive server $archiveserver is unreachable. Try specifying its IP address instead."
exit 1 exit 1
fi fi
echo "The archive server is reachable." echo "The archive server is reachable."
} }
function check_available_space () { function check_available_space () {
echo "Verifying that there is sufficient space available on the MicroSD card..." 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' )" 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 ] if [ "$available_space" -lt 4294967296 ]
@@ -41,22 +69,22 @@ function check_available_space () {
echo "STOP: The MicroSD card is too small." echo "STOP: The MicroSD card is too small."
exit 1 exit 1
fi fi
echo "There is sufficient space available." echo "There is sufficient space available."
} }
function get_ancillary_setup_scripts () { function get_ancillary_setup_scripts () {
pushd /tmp 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 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 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 chmod +x ./make-root-fs-readonly.sh
popd popd
} }
function fix_cmdline_txt_modules_load () function fix_cmdline_txt_modules_load ()
{ {
echo "Fixing the modules-load parameter in /boot/cmdline.txt..." echo "Fixing the modules-load parameter in /boot/cmdline.txt..."
cp /boot/cmdline.txt ~ cp /boot/cmdline.txt ~
@@ -70,12 +98,12 @@ BACKINGFILES_MOUNTPOINT=/backingfiles
function create_usb_drive_backing_files () { function create_usb_drive_backing_files () {
mkdir "$BACKINGFILES_MOUNTPOINT" mkdir "$BACKINGFILES_MOUNTPOINT"
/tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" /tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT"
echo "Mounting the partition for the backing files..." echo "Mounting the partition for the backing files..."
mount /backingfiles mount /backingfiles
echo "Mounted the partition for the backing files." 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 () { function configure_archive () {
@@ -83,7 +111,7 @@ function configure_archive () {
mkdir /mnt/archive mkdir /mnt/archive
local archive_server_ip_address="$(getent hosts $archiveserver | cut -d' ' -f1)" 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 "//$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 "username=$shareuser" > /root/.teslaCamArchiveCredentials
echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials
echo "Configured the archive." echo "Configured the archive."
@@ -93,20 +121,30 @@ function configure_archive_scripts () {
echo "Configuring the archive scripts..." echo "Configuring the archive scripts..."
mkdir /root/bin mkdir /root/bin
pushd ~ pushd ~
wget https://raw.githubusercontent.com/cimryan/teslausb/"$BRANCH"/windows_archive/archiveloop 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 sed s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/ ~/archiveloop > /root/bin/archiveloop
rm ~/archiveloop rm ~/archiveloop
chmod +x /root/bin/archiveloop chmod +x /root/bin/archiveloop
popd popd
pushd /root/bin 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 chmod +x archive-teslacam-clips
popd popd
echo "Configured the archive scripts." 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 () { function configure_rc_local () {
echo "Configuring /etc/rc.local to run the archive scripts at startup..." echo "Configuring /etc/rc.local to run the archive scripts at startup..."
echo "#!/bin/bash -eu" > ~/rc.local echo "#!/bin/bash -eu" > ~/rc.local
@@ -132,11 +170,11 @@ EOF
function configure_hostname () { function configure_hostname () {
echo "Configuring the hostname..." echo "Configuring the hostname..."
local new_host_name="teslausb" local new_host_name="teslausb"
cp /etc/hosts ~ cp /etc/hosts ~
sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts sed "s/raspberrypi/$new_host_name/g" ~/hosts > /etc/hosts
cp /etc/hostname ~ cp /etc/hostname ~
sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname sed "s/raspberrypi/$new_host_name/g" ~/hostname > /etc/hostname
echo "Configured the hostname." echo "Configured the hostname."
@@ -154,6 +192,8 @@ check_variable "shareuser"
check_variable "sharepassword" check_variable "sharepassword"
check_variable "campercent" check_variable "campercent"
check_pushover_enabled
check_archive_server_reachable check_archive_server_reachable
check_available_space check_available_space
@@ -164,6 +204,8 @@ pushd ~
configure_archive_scripts configure_archive_scripts
configure_pushover_scripts
fix_cmdline_txt_modules_load fix_cmdline_txt_modules_load
echo "" >> /etc/fstab echo "" >> /etc/fstab