124 lines
3.4 KiB
Bash
Executable file
124 lines
3.4 KiB
Bash
Executable file
#!/bin/bash
|
|
# ./pushover.sh -t "Pushover via Bash" -m "Pushover message sent with bash from $(hostname -f)" -p1 -s siren -u http://www.google.com -n "Google"
|
|
|
|
USER_TOKEN="uscT77WKKzaNoLWXZDiBaECab3pE9z"
|
|
|
|
# YOUR APPS TOKENS / UPPERCASE NAME WITH _TOKEN (usage: "-a monitor" uses MONITOR_TOKEN)
|
|
SERVER_TOKEN="a484bt3qn6d78noowrik1rwhk3beuk"
|
|
#BACKUP_TOKEN=APP_TOKEN
|
|
#ALERT_TOKEN=APP_TOKEN
|
|
APP_LIST="server" # FOR USAGE
|
|
|
|
# v1.6
|
|
# 12-03-2018 : Added image attachment
|
|
# 30-01-2016 : Added -getopts- arguments to set retry/expire
|
|
# 23-04-2015 : HTML markup language option
|
|
|
|
usage()
|
|
{
|
|
cat << EOF
|
|
|
|
usage: $0 options
|
|
|
|
Send a notification via pushover.
|
|
|
|
OPTIONS:
|
|
-a Application name : "$APP_LIST" (required)
|
|
-m Message (required)
|
|
-t Title of your notification
|
|
-p Priority of your message : -2 (Silent), -1 (Quiet), 1 (High), 2 (Emergency)
|
|
-s Sound (https://pushover.net/api#sounds)
|
|
-i Attach an image (up to 2.5mb)
|
|
-u URL Link
|
|
-n URL Title
|
|
-r Retry (seconds)
|
|
-e Expire (seconds)
|
|
-d Send to a specific device name
|
|
|
|
-f HTML Format
|
|
-x Debug
|
|
-h Show this message
|
|
|
|
EOF
|
|
}
|
|
# FIXME: Missing date setting from options - see:
|
|
# https://pushover.net/api
|
|
|
|
APP_ID=
|
|
TITLE=
|
|
URL=
|
|
URL_TITLE=
|
|
PRIORITY=0
|
|
RETRY=60
|
|
EXPIRE=86400
|
|
SOUND="pushover"
|
|
HTML=0
|
|
MESSAGE=
|
|
DEVICE=
|
|
IMAGE=
|
|
|
|
while getopts “hfret:u:n:p:s:m:a:d:i:x” OPTION
|
|
do
|
|
case $OPTION in
|
|
t) TITLE=$OPTARG ;;
|
|
u) URL=$OPTARG ;;
|
|
n) URL_TITLE=$OPTARG ;;
|
|
p) PRIORITY=$OPTARG ;;
|
|
s) SOUND=$OPTARG ;;
|
|
f) HTML=1 ;;
|
|
r) [ ! -z $OPTARG ] && RETRY=$OPTARG ;;
|
|
e) [ ! -z $OPTARG ] && EXPIRE=$OPTARG ;;
|
|
d) DEVICE=$OPTARG ;;
|
|
i) IMAGE="$OPTARG" ;;
|
|
a)
|
|
APP_ID=`echo $OPTARG | tr '[:lower:]' '[:upper:]'`
|
|
APP_NAME="$APP_ID""_TOKEN"
|
|
APP_TOKEN=${!APP_NAME}
|
|
;;
|
|
m) MESSAGE=$OPTARG ;;
|
|
x)
|
|
echo "TITLE ...... "$TITLE
|
|
echo "URL ........ "$URL
|
|
echo "URL TITLE .. "$URL_TITLE
|
|
echo "PRIORITY ... "$PRIORITY
|
|
echo "SOUND ...... "$SOUND
|
|
echo "MESSAGE .... "$MESSAGE
|
|
echo "DEVIC ...... "$DEVICE
|
|
echo "IMAGE ..... "$IMAGE
|
|
echo "APP ID ..... "$APP_ID
|
|
echo "APP TOKEN .. "$APP_TOKEN
|
|
exit 0
|
|
;;
|
|
:) echo "Option -$OPTARG requires an argument." >&2; exit 1 ;;
|
|
h) usage; exit 1 ;;
|
|
?) usage; exit ;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z $MESSAGE ]] || [[ -z $APP_TOKEN ]]; then
|
|
echo -e "\n\\033[31mMessage and Application token are required.\\033[0m"
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
#curl -s \
|
|
#curl \
|
|
# -F "token=$APP_TOKEN" \
|
|
# -F "user=$USER_TOKEN" \
|
|
# -F "title=$TITLE" \
|
|
# -F "url=$URL" \
|
|
# -F "url_title=$URL_TITLE" \
|
|
# -F "priority=$PRIORITY" \
|
|
# -F "device=$DEVICE" \
|
|
# -F "attachment=@${IMAGE}" \
|
|
# -F "retry=$RETRY" \
|
|
# -F "expire=$EXPIRE" \
|
|
# -F "sound=$SOUND" \
|
|
# -F "html=$HTML" \
|
|
# -F "message=$MESSAGE" \
|
|
# https://api.pushover.net/1/messages.json
|
|
|
|
# This is the same as the curl above (except for attachment=), but actually works.
|
|
wget --hsts-file=/dev/null --no-check-certificate --hsts-file /dev/null --post-data \
|
|
"token=$APP_TOKEN&user=$USER_TOKEN&title=$TITLE&url=$URL&url_title=$URL_TITLE&priority=$PRIORITY&device=$DEVICE&retry=$RETRY&expire=$EXPIRE&sound=$SOUND&html=$HTML&message=$MESSAGE" \
|
|
-O - https://api.pushover.net/1/messages.json 2>/dev/null
|