From 6f654ffdb3ff9b3600317945683e14924fb5aa94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Mathieu?= Date: Sun, 8 Mar 2026 15:25:22 +0100 Subject: [PATCH] Harden Pushover error notifications on abort --- scripts/agathe_backup.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/scripts/agathe_backup.sh b/scripts/agathe_backup.sh index 69a8081..b875782 100755 --- a/scripts/agathe_backup.sh +++ b/scripts/agathe_backup.sh @@ -18,6 +18,7 @@ set -Eeuo pipefail WG_IF="wg0" VPN_TEST_IP="10.202.101.10" WG_WAS_STARTED_BY_SCRIPT=0 +PUSHOVER_FAILURE_SENT=0 LOCK_FILE="/var/lock/agathe_backup.lock" @@ -89,16 +90,27 @@ send_pushover() { local priority="${2:-0}" if command -v curl >/dev/null 2>&1; then - curl -s \ + local rc + set +e + curl -fsS --max-time 20 --retry 2 --retry-delay 2 \ --form-string "token=${PUSHOVER_API_TOKEN}" \ --form-string "user=${PUSHOVER_USER_TOKEN}" \ --form-string "title=${PUSHOVER_TITLE}" \ --form-string "message=${message}" \ --form-string "priority=${priority}" \ - https://api.pushover.net/1/messages.json >/dev/null || true + https://api.pushover.net/1/messages.json >/dev/null + rc=$? + set -e + if [[ "$rc" -ne 0 ]]; then + log "WARNUNG: Pushover konnte nicht gesendet werden (curl Exit-Code: $rc)." + return 1 + fi else log "WARNUNG: curl fehlt, Pushover konnte nicht gesendet werden." + return 1 fi + + return 0 } need_root() { @@ -148,13 +160,22 @@ on_error() { local exit_code=$? local line_no="${1:-unknown}" log "FEHLER in Zeile ${line_no}, Exit-Code ${exit_code}" - send_pushover "Backup FEHLER auf $(hostname): Zeile ${line_no}, Exit-Code ${exit_code}" 1 + if send_pushover "Backup FEHLER auf $(hostname): Zeile ${line_no}, Exit-Code ${exit_code}" 1; then + PUSHOVER_FAILURE_SENT=1 + fi trap - EXIT cleanup exit "$exit_code" } on_exit() { + local exit_code=$? + if [[ "$exit_code" -ne 0 && "$PUSHOVER_FAILURE_SENT" -eq 0 ]]; then + log "WARNUNG: Abbruch ohne ERR-Notification erkannt (Exit-Code ${exit_code}), sende Fallback-Pushover." + if send_pushover "Backup FEHLER auf $(hostname): Exit-Code ${exit_code} (EXIT trap)." 1; then + PUSHOVER_FAILURE_SENT=1 + fi + fi cleanup }