Last active
June 11, 2022 18:19
-
-
Save onedr0p/30620a99069fd8dde39bb8d35c9d753c to your computer and use it in GitHub Desktop.
Pushovarr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
export PUSHOVER_API_URL="https://api.pushover.net/1/messages.json" | |
# | |
# Application specific variables | |
# | |
export STARR_APP | |
STARR_APP="$(basename --suffix=.pid -- /config/*.pid)" | |
export STARR_PORT | |
STARR_PORT="$(xmlstarlet sel -t -m '/Config/Port' -v Value </config/config.xml)" | |
export STARR_APIKEY | |
STARR_APIKEY="$(xmlstarlet sel -t -m '/Config/ApiKey' -v Value </config/config.xml)" | |
export STARR_EVENT_TYPE | |
STARR_EVENT_TYPE="${STARR_APP}_eventtype" | |
# TODO: Not all starr apps support InstanceName yet, this will | |
# replace PUSHOVARR_APP_DISPLAY_NAME in the future | |
# export STARR_INSTANCE_NAME | |
# STARR_INSTANCE_NAME="$(xmlstarlet sel -t -m '/Config/InstanceName' -v Value </config/config.xml)" | |
# | |
# Configurable environment variables | |
# | |
# PUSHOVARR_APP_DISPLAY_NAME (required) | |
# PUSHOVARR_APP_URL (required) | |
# PUSHOVARR_PUSHOVER_USER_KEY (required) | |
# PUSHOVARR_PUSHOVER_TOKEN (required) | |
# PUSHOVARR_PUSHOVER_DEVICE (optional) | |
# PUSHOVARR_PUSHOVER_PRIORITY (optional) | |
# PUSHOVARR_PUSHOVER_SOUND (optional) | |
# | |
# Send Notification on Test | |
# | |
if [[ "${!STARR_EVENT_TYPE}" == "Test" ]]; then | |
send "Test Notification" "Test Message" | |
exit 0 | |
fi | |
# | |
# Send notification on Download | |
# | |
if [[ "${!STARR_EVENT_TYPE}" == "Download" ]]; then | |
case "${APPLICATION}" in | |
sonarr) | |
#shellcheck disable=SC2154 | |
printf -v PUSHOVER_TITLE "%s - S%02dE%02d - %s" "${sonarr_series_title}" "${sonarr_episodefile_seasonnumber}" "${sonarr_episodefile_episodenumbers}" "${sonarr_episode_title}" | |
#shellcheck disable=SC2154 | |
printf -v PUSHOVER_MESSAGE "%s" "${sonarr_episode_description}" | |
;; | |
radarr) | |
send | |
;; | |
lidarr) | |
send | |
;; | |
readarr) | |
send | |
;; | |
*) | |
printf "Unknown application" | |
exit 1 | |
;; | |
esac | |
send "${PUSHOVER_TITLE}" "${PUSHOVER_MESSAGE}" | |
exit 0 | |
fi | |
send() { | |
local pushover_title="${1}" | |
local pushover_message="${2}" | |
local msg= | |
msg=$(jq -n \ | |
--arg token "${PUSHOVER_TOKEN}" \ | |
--arg user "${PUSHOVER_USER_KEY}" \ | |
--arg title "${pushover_title}" \ | |
--arg message "${pushover_message}" \ | |
--arg url "${PUSHOVARR_APP_URL}" \ | |
--arg url_title "View in ${PUSHOVARR_APP_DISPLAY_NAME}" \ | |
--arg sound "${PUSHOVER_SOUND}" \ | |
--arg device "${PUSHOVER_DEVICE}" \ | |
'{token: $token, user: $user, title: $title, message: $message, url: $url, url_title: $url_title, sound: $sound, device: $device}' \ | |
) | |
curl \ | |
--header "Content-Type: application/json" \ | |
--data-binary "${msg}" \ | |
--request POST "${PUSHOVER_API_URL}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment