Initial commit
This commit is contained in:
commit
8641464a6c
44 files changed
+2192
No files matched your search
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Euo pipefail
|
||||
|
||||
CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/hermes-stack-maintenance/config.env"
|
||||
|
||||
log() {
|
||||
printf '%s\n' "$*" | systemd-cat -t hermes-stack-maintenance 2>/dev/null || true
|
||||
}
|
||||
|
||||
text="${*:-}"
|
||||
if [[ -z "$text" ]]; then
|
||||
printf 'Verwendung: %s TEXT\n' "${0##*/}" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
log "$text"
|
||||
|
||||
if [[ ! -r "$CONFIG_FILE" ]]; then
|
||||
log "Benachrichtigung übersprungen: $CONFIG_FILE ist nicht lesbar."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
set +u
|
||||
# shellcheck disable=SC1090
|
||||
source "$CONFIG_FILE" || {
|
||||
set -u
|
||||
log "Benachrichtigung übersprungen: Maintenance-Konfiguration ist ungültig."
|
||||
exit 0
|
||||
}
|
||||
|
||||
telegram_notify="${TELEGRAM_NOTIFY:-0}"
|
||||
signal_notify="${SIGNAL_NOTIFY:-0}"
|
||||
|
||||
if [[ -r "${HERMES_ENV:-}" ]] &&
|
||||
[[ "$telegram_notify" == 1 || "$signal_notify" == 1 ]]; then
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$HERMES_ENV" || true
|
||||
set +a
|
||||
fi
|
||||
set -u
|
||||
|
||||
if [[ "$telegram_notify" == 1 &&
|
||||
-n "${TELEGRAM_BOT_TOKEN:-}" &&
|
||||
-n "${TELEGRAM_HOME_CHANNEL:-}" ]]; then
|
||||
if ! curl --fail --silent --show-error --max-time 15 \
|
||||
--request POST \
|
||||
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||
--data-urlencode "chat_id=${TELEGRAM_HOME_CHANNEL}" \
|
||||
--data-urlencode "text=${text}" >/dev/null; then
|
||||
log "Telegram-Benachrichtigung konnte nicht zugestellt werden."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$signal_notify" == 1 &&
|
||||
-n "${SIGNAL_HTTP_URL:-}" &&
|
||||
-n "${SIGNAL_ACCOUNT:-}" &&
|
||||
-n "${SIGNAL_HOME_CHANNEL:-}" ]]; then
|
||||
if [[ "$SIGNAL_HOME_CHANNEL" == group:* ]]; then
|
||||
signal_payload="$(
|
||||
jq -nc --arg account "$SIGNAL_ACCOUNT" --arg message "$text" \
|
||||
--arg group_id "${SIGNAL_HOME_CHANNEL#group:}" \
|
||||
'{jsonrpc:"2.0",method:"send",params:{account:$account,message:$message,groupId:$group_id},id:"hermes-maintenance"}'
|
||||
)" || signal_payload=""
|
||||
else
|
||||
signal_payload="$(
|
||||
jq -nc --arg account "$SIGNAL_ACCOUNT" --arg message "$text" \
|
||||
--arg recipient "$SIGNAL_HOME_CHANNEL" \
|
||||
'{jsonrpc:"2.0",method:"send",params:{account:$account,message:$message,recipient:[$recipient]},id:"hermes-maintenance"}'
|
||||
)" || signal_payload=""
|
||||
fi
|
||||
|
||||
if [[ -z "$signal_payload" ]] ||
|
||||
! curl --fail --silent --show-error --max-time 30 \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-binary "$signal_payload" \
|
||||
"${SIGNAL_HTTP_URL%/}/api/v1/rpc" |
|
||||
jq -e '((.error // null) == null) and (.result != null)' >/dev/null; then
|
||||
log "Signal-Benachrichtigung konnte nicht zugestellt werden."
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in new issue
Block a user