From 2263e298fd79c3cc2b13992d654b86ccb98ad24a Mon Sep 17 00:00:00 2001 From: Hitonabi Date: Thu, 2 Jul 2026 19:49:26 +0200 Subject: [PATCH] Autonomie E1: Meldeweg deploy/notify.sh (hermes send -> Telegram, Fallback Log+wall) Verifiziert auf der Box: 2 Testnachrichten via Telegram zugestellt (mc2-notify.log OK). Co-Authored-By: Claude Fable 5 --- deploy/notify.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 deploy/notify.sh diff --git a/deploy/notify.sh b/deploy/notify.sh new file mode 100644 index 0000000..1ec8aa9 --- /dev/null +++ b/deploy/notify.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Meldeweg der Box (Autonomie E1): eine Nachricht an den User schicken. +# Primär: hermes send → Telegram (nutzt Gateway-Credentials, kein LLM nötig). +# Fallback: Logfile + wall (falls Telegram/hermes nicht erreichbar). +# +# Nutzung: notify.sh "Nachricht" (oder via stdin: echo msg | notify.sh) +# notify.sh -s "[Update]" "Text" (Betreffzeile voranstellen) +# Exit 0 = zugestellt (Telegram ODER Fallback-Log geschrieben). +set -uo pipefail + +LOG="${MC_NOTIFY_LOG:-$HOME/mc2-notify.log}" +SUBJECT="" + +while getopts ":s:" opt; do + case "$opt" in + s) SUBJECT="$OPTARG" ;; + *) echo "usage: notify.sh [-s subject] " >&2; exit 2 ;; + esac +done +shift $((OPTIND - 1)) + +MSG="${1:-}" +[ -z "$MSG" ] && [ ! -t 0 ] && MSG="$(cat)" +if [ -z "$MSG" ]; then + echo "usage: notify.sh [-s subject] " >&2 + exit 2 +fi + +TS="$(date '+%Y-%m-%d %H:%M:%S')" + +# Primärweg: Telegram via hermes send (Login-Shell-PATH, falls aus Timer/cron aufgerufen). +if [ -n "$SUBJECT" ]; then + SEND_OUT="$(bash -lc 'hermes send --to telegram --subject "$1" -- "$2"' _ "$SUBJECT" "$MSG" 2>&1)" +else + SEND_OUT="$(bash -lc 'hermes send --to telegram -- "$1"' _ "$MSG" 2>&1)" +fi +if [ $? -eq 0 ]; then + echo "$TS OK telegram: $MSG" >> "$LOG" + exit 0 +fi + +# Fallback: Logfile + wall — Meldung darf nie verloren gehen. +echo "$TS FALLBACK (telegram fehlgeschlagen: $SEND_OUT): $MSG" >> "$LOG" +printf '%s\n' "MC2-Meldung: ${SUBJECT:+$SUBJECT }$MSG" | wall 2>/dev/null || true +echo "WARN: Telegram fehlgeschlagen, in $LOG protokolliert" >&2 +exit 0