#! /bin/sh main() { set -e set -o pipefail pull } pull() { local last_f=/tmp/ntfy_to_alert.since touch "$last_f" local since="$(cat "$last_f" | grep . || echo $(($(date +%s)-60*60*4)))" for line_b64 in $( curl \ -sS \ -u "squeaky2x3:dYbtypGkHXFtq1E00k2H42SPGUowi" \ "https://ntfy.home.blapointe.com/alerts/json?since=$since&poll=1" \ | grep . \ | while read -r line; do echo "$line" | base64 done ); do local line="$(echo "$line_b64" | base64 --decode)" local ts=$(echo "$line" | jq -r .time) if ((ts+1>since)); then since=$((ts+1)) fi if which say &> /dev/null; then say "$(echo "$line" | jq -r '.title+" "+.message')" else echo "!!! $line" fi done echo "$since" | tee "$last_f" >&2 } if [ "$0" == "$BASH_SOURCE" ]; then main "$@" fi