Added new pushover script + config. Adjust command line usage for new script.
This commit is contained in:
parent
3d665e5e11
commit
68b98281bd
7 changed files with 365 additions and 2 deletions
|
@ -38,3 +38,8 @@ chmod 755 /etc/profile.d/less.sh
|
|||
chmod 755 /etc/profile.d/optpaths.csh
|
||||
chmod 755 /etc/profile.d/optpaths.sh
|
||||
chmod 750 /etc/sudoers.d
|
||||
|
||||
# Decrypt the pushover-config.
|
||||
echo "Decrypting /etc/pushover/pushover-config..."
|
||||
gpg -d -o /etc/pushover/pushover-config /etc/pushover/pushover-config.gpg
|
||||
chmod 640 /etc/pushover/pushover-config
|
||||
|
|
1
base-files/.gitignore
vendored
1
base-files/.gitignore
vendored
|
@ -2,6 +2,7 @@
|
|||
gshadow
|
||||
shadow
|
||||
ssh/*_key
|
||||
pubshover/pushover-config
|
||||
|
||||
# Temporary, backup, sample and dist files.
|
||||
*.swp
|
||||
|
|
2
base-files/pushover/pushover-config.gpg
Normal file
2
base-files/pushover/pushover-config.gpg
Normal file
|
@ -0,0 +1,2 @@
|
|||
Œ
ïâ<C3AF>3®åÖ`ÒÀº£aÅ[«¬µ»}ºdhÊU¡Ñþ!t vÕ<76>MSlP¬á…ïŽ:í'¾œë¹V¹h„pöõ ‹Sã>±
|
||||
ÚdûJI<4A>
:å÷K΀PPzÝ)ãH`ä0é7ieæµ`SŸw^ÊZ"ŸÕ˜v¾œÐŽ<C390>—å¦F=÷ÔíeóQ…ÍÈ3¸k1å:kqªDªÂQYd*J•É!š'¾Å—ÂktT—K@üA<>l=¯?¬K¤)ƒyÍnC3Ð5>[ͯ„‹ÄÇè
|
|
@ -63,4 +63,4 @@ grep "^seeder:" /etc/passwd >/dev/null 2>&1 && su - seeder -c /home/seeder/start
|
|||
}
|
||||
|
||||
# Notify that the server has booted.
|
||||
/opt/bin/pushover -a server -t "Successful boot up: ${HOSTNAME%%.*}" -p 1 -m "$(printf '%(%d %b %Y - %H:%M:%S)T')" >/dev/null
|
||||
/opt/bin/pushover -T "Successful boot up: ${HOSTNAME%%.*}" -p 1 -m "$(printf '%(%d %b %Y - %H:%M:%S)T')"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# This script will be run when the system is shutdown or rebooted.
|
||||
|
||||
# Notify that the server is shutting down.
|
||||
/opt/bin/pushover -a server -t "Shutting down: ${HOSTNAME%%.*}" -p 1 -m "$(printf '%(%d %b %Y - %H:%M:%S)T')" >/dev/null
|
||||
/opt/bin/pushover -T "Shutting down: ${HOSTNAME%%.*}" -p 1 -m "$(printf '%(%d %b %Y - %H:%M:%S)T')"
|
||||
|
||||
# Stop containers.
|
||||
[ -x /etc/rc.d/rc.lxc ] && /etc/rc.d/rc.lxc stop
|
||||
|
|
231
utils/pushover
Executable file
231
utils/pushover
Executable file
|
@ -0,0 +1,231 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
readonly API_URL="https://api.pushover.net/1/messages.json"
|
||||
readonly CONFIG_FILE="pushover-config"
|
||||
readonly DEFAULT_CONFIG="/etc/pushover/${CONFIG_FILE}"
|
||||
readonly USER_OVERRIDE="${HOME}/.pushover/${CONFIG_FILE}"
|
||||
readonly EXPIRE_DEFAULT=180
|
||||
readonly RETRY_DEFAULT=30
|
||||
HIDE_REPLY=true
|
||||
|
||||
showHelp()
|
||||
{
|
||||
local script=`basename "$0"`
|
||||
echo "Send Pushover v1.2 scripted by Nathan Martini"
|
||||
echo "Push notifications to your Android, iOS, or desktop devices"
|
||||
echo
|
||||
echo "NOTE: This script requires an account at http://www.pushover.net"
|
||||
echo
|
||||
echo "usage: ${script} <-t|--token apikey> <-u|--user userkey> <-m|--message message> [options]"
|
||||
echo
|
||||
echo " -t, --token APIKEY The pushover.net API Key for your application"
|
||||
echo " -u, --user USERKEY Your pushover.net user key"
|
||||
echo " -m, --message MESSAGE The message to send; supports HTML formatting"
|
||||
echo " -a, --attachment filename The Picture you want to send"
|
||||
echo " -T, --title TITLE Title of the message"
|
||||
echo " -d, --device NAME Comma seperated list of devices to receive message"
|
||||
echo " -U, --url URL URL to send with message"
|
||||
echo " --url-title URLTITLE Title of the URL"
|
||||
echo " -p, --priority PRIORITY Priority of the message"
|
||||
echo " -2 - no notification/alert"
|
||||
echo " -1 - quiet notification"
|
||||
echo " 0 - normal priority"
|
||||
echo " 1 - bypass the user's quiet hours"
|
||||
echo " 2 - require confirmation from the user"
|
||||
echo " -e, --expire SECONDS Set expiration time for notifications with priority 2 (default ${EXPIRE_DEFAULT})"
|
||||
echo " -r, --retry COUNT Set retry period for notifications with priority 2 (default ${RETRY_DEFAULT})"
|
||||
echo " -s, --sound SOUND Notification sound to play with message"
|
||||
echo " pushover - Pushover (default)"
|
||||
echo " bike - Bike"
|
||||
echo " bugle - Bugle"
|
||||
echo " cashregister - Cash Register"
|
||||
echo " classical - Classical"
|
||||
echo " cosmic - Cosmic"
|
||||
echo " falling - Falling"
|
||||
echo " gamelan - Gamelan"
|
||||
echo " incoming - Incoming"
|
||||
echo " intermission - Intermission"
|
||||
echo " magic - Magic"
|
||||
echo " mechanical - Mechanical"
|
||||
echo " pianobar - Piano Bar"
|
||||
echo " siren - Siren"
|
||||
echo " spacealarm - Space Alarm"
|
||||
echo " tugboat - Tug Boat"
|
||||
echo " alien - Alien Alarm (long)"
|
||||
echo " climb - Climb (long)"
|
||||
echo " persistent - Persistent (long)"
|
||||
echo " echo - Pushover Echo (long)"
|
||||
echo " updown - Up Down (long)"
|
||||
echo " none - None (silent)"
|
||||
echo " -v, --verbose Return API execution reply to stdout"
|
||||
echo
|
||||
echo "EXAMPLES:"
|
||||
echo
|
||||
echo " ${script} -t xxxxxxxxxx -u yyyyyyyyyy -m \"This is a test\""
|
||||
echo " Sends a simple \"This is a test\" message to all devices."
|
||||
echo
|
||||
echo " ${script} -t xxxxxxxxxx -u yyyyyyyyyy -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} -t xxxxxxxxxx -u yyyyyyyyyy -m \"This is a test\" -d \"Phone,Home Desktop\""
|
||||
echo " Sends a simple \"This is a test\" message to the devices named \"Phone\" and \"Home Desktop\"."
|
||||
echo
|
||||
echo " ${script} -t xxxxxxxxxx -u yyyyyyyyyy -m \"This is a test\" -U \"http://www.google.com\" --url-title 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} -t xxxxxxxxxx -u yyyyyyyyyy -m \"This is a test\" -p 1"
|
||||
echo " Sends a simple \"This is a test\" high priority message to all devices."
|
||||
echo
|
||||
echo " ${script} -t xxxxxxxxxx -u yyyyyyyyyy -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} -t xxxxxxxxxx -u yyyyyyyyyy -m \"This is a test Pic\" -a /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
|
||||
}
|
||||
|
||||
curl --version > /dev/null 2>&1 || { echo "This script requires curl; aborting."; echo; exit 1; }
|
||||
|
||||
if [ -f ${DEFAULT_CONFIG} ]; then
|
||||
source ${DEFAULT_CONFIG}
|
||||
fi
|
||||
if [ -f ${USER_OVERRIDE} ]; then
|
||||
source ${USER_OVERRIDE}
|
||||
fi
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case "${1:-}" in
|
||||
-t|--token)
|
||||
api_token="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-u|--user)
|
||||
user_key="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-m|--message)
|
||||
message="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-a|--attachment)
|
||||
attachment="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-T|--title)
|
||||
title="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-d|--device)
|
||||
device="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-U|--url)
|
||||
url="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
--url-title)
|
||||
url_title="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-p|--priority)
|
||||
priority="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-s|--sound)
|
||||
sound="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-e|--expire)
|
||||
expire="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-r|--retry)
|
||||
retry="${2:-}"
|
||||
shift
|
||||
;;
|
||||
|
||||
-v|--verbose)
|
||||
unset HIDE_REPLY
|
||||
;;
|
||||
|
||||
-h|--help)
|
||||
showHelp
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
shift
|
||||
done
|
||||
|
||||
if [ $priority -eq 2 ]; then
|
||||
if [ -z "${expire:-}" ]; then
|
||||
expire=${EXPIRE_DEFAULT}
|
||||
fi
|
||||
if [ -z "${retry:-}" ]; then
|
||||
retry=${RETRY_DEFAULT}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${api_token:-}" ]; then
|
||||
echo "-t|--token must be set"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${user_key:-}" ]; then
|
||||
echo "-u|--user must be set"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${message:-}" ]; then
|
||||
echo "-m|--message must be set"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -z "${attachment:-}" ] && [ ! -f "${attachment}" ]; then
|
||||
echo "${attachment} not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${attachment:-}" ]; then
|
||||
json="{\"token\":\"${api_token}\",\"user\":\"${user_key}\",\"message\":\"${message}\""
|
||||
if [ "${device:-}" ]; then json="${json},\"device\":\"${device}\""; fi
|
||||
if [ "${title:-}" ]; then json="${json},\"title\":\"${title}\""; fi
|
||||
if [ "${url:-}" ]; then json="${json},\"url\":\"${url}\""; fi
|
||||
if [ "${url_title:-}" ]; then json="${json},\"url_title\":\"${url_title}\""; fi
|
||||
if [ "${priority:-}" ]; then json="${json},\"priority\":${priority}"; fi
|
||||
if [ "${expire:-}" ]; then json="${json},\"expire\":${expire}"; fi
|
||||
if [ "${retry:-}" ]; then json="${json},\"retry\":${retry}"; fi
|
||||
if [ "${sound:-}" ]; then json="${json},\"sound\":\"${sound}\""; fi
|
||||
json="${json}}"
|
||||
|
||||
curl -s ${HIDE_REPLY:+ -o /dev/null} -H "Content-Type: application/json" -d "${json}" "${API_URL}" ${HIDE_REPLY:+ > /dev/null} 2>&1
|
||||
else
|
||||
curl -s ${HIDE_REPLY:+ -o /dev/null} \
|
||||
--form-string "token=${api_token}" \
|
||||
--form-string "user=${user_key}" \
|
||||
--form-string "message=${message}" \
|
||||
--form "attachment=@${attachment}" \
|
||||
${priority:+ --form-string "priority=${priority}"} \
|
||||
${sound:+ --form-string "sound=${sound}"} \
|
||||
${device:+ --form-string "device=${device}"} \
|
||||
${title:+ --form-string "title=${title}"} \
|
||||
"${API_URL}" ${HIDE_REPLY:+ > /dev/null} 2>&1
|
||||
fi
|
124
utils/pushover.old
Executable file
124
utils/pushover.old
Executable file
|
@ -0,0 +1,124 @@
|
|||
#!/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
|
Loading…
Add table
Add a link
Reference in a new issue