From 1245ea5a5c7e3b8f0552b4a6811d697290852850 Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Sun, 25 Aug 2024 18:49:58 +0200 Subject: [PATCH] Pushover # ./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" --- pushover.sh | 241 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100755 pushover.sh diff --git a/pushover.sh b/pushover.sh new file mode 100755 index 0000000..dd9d3c4 --- /dev/null +++ b/pushover.sh @@ -0,0 +1,241 @@ +#!/usr/bin/env 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" + +dotenv () { + set -a + # shellcheck disable=SC1091 + [ -f "$HOME/.env" ] && . "$HOME/.env" || echo -e "${red}\nNo $HOME/.env file found ! Could'nt get update from Github.'.${reset}" + set +a +} + +dotenv + +USER_TOKEN=$USER_KEY + +# YOUR APPS TOKENS / UPPERCASE NAME WITH _TOKEN (usage: "-a monitor" uses MONITOR_TOKEN) +BASH_TOKEN=$BASH_APP +SYNO_TOKEN=$SYNO_APP +APP_LIST="bash, syno" # FOR USAGE + +APP_ID="bash" # Default app + +# v1.8 +# 24-08-2024 : +# 14-03-2018 : - Request send only necessary fields. +# - Added message pipe. +# - Added monospace option. +# - Default monitor name +# 12-03-2018 : Added image attachment. +# 30-01-2016 : Added -getopts- arguments to set retry/expire. +# 23-04-2015 : HTML markup language option. + +VERSION=1.8 + +TITLE="" +URL="" +URL_TITLE="untitled" +PRIORITY=0 +RETRY=60 +EXPIRE=86400 +SOUND="pushover" +HTML=0 +MONOSPACE=0 +DEVICE="all" +IMAGE= +DEBUG=0 + +usage() +{ +cat << EOF + +usage: $0 options + +Push notifications to your Android, iOS, or desktop devices + +OPTIONS: + -a Application name : "$APP_LIST" (required) + -m Message (required) If the -f (html) flag = 1, message must be surrounded by a single quote + Example: -m \"'This is a HTML test'\" + + -t Title of your notification + -d Send to a specific device name Comma seperated list of devices to receive message + -p Priority of your message : -2 (Silent), -1 (Quiet), 0 (Normal), 1 (High), 2 (Emergency) + -s Sound (https://pushover.net/api#sounds): + pushover - Pushover (default) + bike - Bike + bugle - Bugle + cashregister - Cash Register + classical - Classical + cosmic - Cosmic + falling - Falling + gamelan - Gamelan + incoming - Incoming + intermission - Intermission + magic - Magic + mechanical - Mechanical + pianobar - Piano Bar + siren - Siren + spacealarm - Space Alarm + tugboat - Tug Boat + alien - Alien Alarm (long) + climb - Climb (long) + persistent - Persistent (long) + echo - Pushover Echo (long) + updown - Up Down (long) + none - None (silent) + -i Attach an image (up to 2.5mb) + -u URL Link + -n URL Title + -r Retry (seconds) Set retry period for notifications with priority 2 (default ${RETRY})" + -e Expire (seconds) Set expiration time for notifications with priority 2 (default ${EXPIRE})" + + -f HTML Format Enable HTML formatting, cannot be used with the -k (monospace) flag + -k Monospace Format Enable monospace messages, cannot be used with the -f (html) flag + -x Debug Must be the first argument !! + -z Show some examples + -h Show this message + +EOF +} + +examples() +{ + local script=`basename "$0"` + + echo "EXAMPLES:" + echo + echo " ${script} -a \"bash\" -m \"This is a test\"" + echo " Sends a simple \"This is a test\" message to all devices." + echo + echo " ${script} -a \"bash\" -m \"This is a test\" -t \"Test Title\"" + echo " Sends a simple \"This is a test\" message with the title \"Test Title\" to all devices." + echo + echo " ${script} -a \"bash\" -m \"This is a test\" -d \"pixel8,Safari_airbook\"" + echo " Sends a simple \"This is a test\" message to the devices named \"pixel8\" and \"Safari_airbook\"." + echo + echo " ${script} -a \"bash\" -m \"This is a test\" -u \"http://www.google.com\" -n Google" + echo " Sends a simple \"This is a test\" message to all devices that contains a link to www.google.com titled \"Google\"." + echo + echo " ${script} -a \"bash\" -m \"This is a test\" -p 1" + echo " Sends a simple \"This is a test\" high priority message to all devices." + echo + echo " ${script} -a \"bash\" -m \"This is a test\" -s bike" + echo " Sends a simple \"This is a test\" message to all devices that uses the sound of a bike bell as the notification sound." + echo + echo " ${script} -a \"bash\" -m \"This is a test Pic\" -i /path/to/pic.jpg " + echo " Sends a simple \"This is a test Pic\" message to all devices and send the Picture with the message." + echo + echo " ${script} -a \"bash\" -m \"'This is a HTML test'\" -f 1 " + echo " Sends a simple \"This is a HTML test\" message with html tag" + echo +} +ARGS=( -F "user=$USER_TOKEN" ) + +# MESSAGE PIPE +if [ -p /dev/stdin ] +then + MESSAGE=$(&2; exit 1 ;; + h) usage; exit 1 ;; + z) examples; exit 1 ;; + ?) usage; exit ;; + esac +done + +# APP TOKEN +if [[ ! -z $APP_ID ]] +then + APP_ID=`echo $APP_ID | tr '[:lower:]' '[:upper:]'` + APP_NAME="${APP_ID}_TOKEN" + APP_TOKEN="${!APP_NAME}" + ARGS+=( -F "token=$APP_TOKEN" ) +fi + +# EMERGENCY PRIORITY +if [[ $PRIORITY == 2 ]] +then + ARGS+=( -F "retry=$RETRY" ) + ARGS+=( -F "expire=$EXPIRE" ) +fi + +# REQUIRED FIELDS +if [[ -z $MESSAGE ]] || [[ -z $APP_TOKEN ]] +then + echo -e "\n\\033[31mMessage and Application token are required.\\033[0m" + usage + exit 1 +fi + + +if [[ $HTML == 1 ]] +then + MESSAGE="'$MESSAGE'" +fi + +# DEBUG PRINT +if [[ $DEBUG == 1 ]] +then + echo "TITLE ...... $TITLE" + echo "DEVICE ..... $DEVICE" + echo "URL ........ ${URL} (${URL_TITLE})" + echo "FORMAT ..... HTML ${HTML} MONOSPACE ${MONOSPACE}" + echo "APP ........ ID:${APP_ID} TOKEN:${APP_TOKEN}" + echo "PRIORITY ... $PRIORITY" + if [[ $PRIORITY == 2 ]] + then + echo "RETRY ...... $RETRY" + echo "EXPIRE ..... $EXPIRE" + fi + echo "SOUND ...... $SOUND" + echo "IMAGE ..... $IMAGE" + echo "MESSAGE -----------------------------------------" + echo "${MESSAGE}" + echo "-------------------------------------------------" + exit 0 +fi + +# SEND NOTIFICATION +#curl -s "${ARGS[@]}" https://api.pushover.net/1/messages.json +echo "${ARGS[@]}" \ No newline at end of file