diff --git a/bin/0km b/bin/0km index 4f13f5b..8eee235 100755 --- a/bin/0km +++ b/bin/0km @@ -656,6 +656,156 @@ EOF } +NTFY_TOPIC_FILE="/etc/ntfy/topics.yml" +NTFY_CONFIG_FILE="/etc/ntfy/ntfy.conf" +subscribe:ntfy:topic-file-exists() { + local vps="$1" + if ! out=$(echo "[ -f \"$NTFY_TOPIC_FILE\" ] && echo ok || true" | \ + ssh:run "root@$vps" -- bash); then + err "Unable to check for existence of '$NTFY_TOPIC_FILE'." + fi + if [ -z "$out" ]; then + err "File '$NTFY_TOPIC_FILE' not found on $vps." + return 1 + fi +} + +subscribe:ntfy:config-file-exists() { + local vps="$1" + if ! out=$(echo "[ -f \"$NTFY_CONFIG_FILE\" ] && echo ok || true" | \ + ssh:run "root@$vps" -- bash); then + err "Unable to check for existence of '$NTFY_CONFIG_FILE'." + fi + if [ -z "$out" ]; then + err "File '$NTFY_CONFIG_FILE' not found on $vps." + return 1 + fi +} + + +ntfy:rm() { + local channel="$1" topic="$2" vps="$3" + subscribe:ntfy:topic-file-exists "$vps" || return 1 + if ! out=$(echo "yq -i 'del(.[\"$channel\"][] | select(. == \"$TOPIC\"))' \"$NTFY_TOPIC_FILE\"" | \ + ssh:run "root@$vps" -- bash); then + err "Failed to remove channel '$channel' from '$NTFY_TOPIC_FILE'." + return 1 + fi + info "Channel '$channel' removed from '$NTFY_TOPIC_FILE' on $vps." + ssh:run "root@$vps" -- cat "$NTFY_TOPIC_FILE" +} + +ntfy:add() { + local channel="$1" topic="$2" vps="$3" + vps_connection_check "$vps" &2 + ntfy:topic-access "remove" "$topic" "$vps"