.dots/scripts/notify.sh

59 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2024-08-28 15:22:02 +02:00
#!/usr/bin/env bash
# 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
echo "user: $user"
echo "pw: $password"
echo "url: $url"
echo "args: ${args[@]}"
2024-08-29 15:53:24 +02:00
curl -s -u $user:$password "${args[@]}" $url