2016-11-04 17:55:54 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-12-05 22:39:10 -08:00
|
|
|
#
|
|
|
|
# Sends a pushover notification.
|
|
|
|
#
|
|
|
|
# -t [TITLE]
|
|
|
|
# -m [MESSAGE]
|
|
|
|
# -p [PRIORITY_LEVEL]
|
|
|
|
# -u [URL]
|
|
|
|
# -U [URL_TITLE]
|
|
|
|
# -d [DEVICE]
|
|
|
|
#
|
|
|
|
|
|
|
|
set -e
|
|
|
|
unset CDPATH
|
|
|
|
|
|
|
|
secret_file=~/.secrets/pushover
|
|
|
|
if [[ ! -f $secret_file ]]; then
|
|
|
|
>&2 echo "No pushover config file found"
|
|
|
|
exit 1
|
2016-12-25 21:24:43 -08:00
|
|
|
fi
|
|
|
|
|
2017-12-05 22:39:10 -08:00
|
|
|
title=${2:+$1}
|
|
|
|
message=${2:-$1}
|
|
|
|
# priority=
|
2016-12-25 21:24:43 -08:00
|
|
|
url=
|
2017-12-05 22:39:10 -08:00
|
|
|
url_title=
|
2016-12-25 21:24:43 -08:00
|
|
|
device=
|
|
|
|
|
|
|
|
while getopts t:m:p:u:d: opt; do
|
2017-12-05 22:39:10 -08:00
|
|
|
case $opt in
|
|
|
|
t) title="$OPTARG" ;;
|
|
|
|
m) message="$OPTARG" ;;
|
|
|
|
# p) priority="$OPTARG" ;;
|
|
|
|
u) url="$OPTARG" ;;
|
|
|
|
U) url_title="$OPTARG" ;;
|
|
|
|
d) device="$OPTARG" ;;
|
|
|
|
*) >&2 echo "Invalid option $OPTARG"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2016-12-25 21:24:43 -08:00
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2017-12-05 22:39:10 -08:00
|
|
|
#USER=...
|
|
|
|
#TOKEN=...
|
|
|
|
eval "$(gpg --decrypt $secret_file)"
|
2016-12-25 21:24:43 -08:00
|
|
|
|
|
|
|
curl -s \
|
2017-12-05 22:39:10 -08:00
|
|
|
--form-string "token=$TOKEN" \
|
|
|
|
--form-string "user=$USER" \
|
|
|
|
--form-string "title=$title" \
|
|
|
|
--form-string "message=$message" \
|
|
|
|
--form-string "url=$url" \
|
|
|
|
--form-string "url_title=$url_title" \
|
|
|
|
--form-string "device=$device" \
|
|
|
|
https://api.pushover.net/1/messages.json
|