add notification script
This commit is contained in:
parent
4e0071d93a
commit
c5c1a95a34
1 changed files with 53 additions and 0 deletions
53
scripts/notify.sh
Executable file
53
scripts/notify.sh
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
# author: Daniel Sommer <daniel.sommer@velvettear.de>
|
||||
# license: MIT
|
||||
|
||||
# usage:
|
||||
# notify.sh <topic> <payload> [options]
|
||||
# documentation @ https://docs.ntfy.sh/publish
|
||||
|
||||
url="https://notify.velvettear.de"
|
||||
user="velvettear"
|
||||
password="\$Velvet90"
|
||||
|
||||
[[ -z "$1" ]] && printf "error: no topic specified\n" 1>&2 && exit 1
|
||||
[[ -z "$2" ]] && printf "error: no payload specified\n" 1>&2 && exit 1
|
||||
|
||||
url="$url/$1"
|
||||
payload="$2"
|
||||
|
||||
# check if payload is a file
|
||||
if [[ -e "$payload" ]]; then
|
||||
args+=("-T" "$(realpath $payload)" "-H" "Filename: $(basename $payload)")
|
||||
else
|
||||
args+=("-d" "$payload")
|
||||
fi
|
||||
|
||||
# check for valid priority level
|
||||
function checkPriority() {
|
||||
prio="$(printf "$1" | tr '[:upper:]' '[:lower:]')"
|
||||
if [[ "$prio" == "min" ]] || [[ "$prio" == "low" ]] || [[ "$prio" == "default" ]] || [[ "$prio" == "high" ]] || [[ "$prio" == "max" ]] || [[ "$prio" == "urgent" ]]; then
|
||||
args+=("-H" "Priority: $prio")
|
||||
fi
|
||||
}
|
||||
|
||||
# check arguments
|
||||
index=1
|
||||
for arg in "$@"; do
|
||||
((index++))
|
||||
value="${@[$index]}"
|
||||
case "$arg" in
|
||||
-e|--emoji|-i|--icon)
|
||||
args+=("-H" "Tags: $value")
|
||||
;;
|
||||
-p|--priority)
|
||||
checkPriority "$value"
|
||||
;;
|
||||
-t|--title)
|
||||
args+=("-H" "Title: $value")
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
curl -s -u $user:$password ${args[@]} $url
|
Loading…
Reference in a new issue