Sync workstation helpers and preserve baseline deployment
This commit is contained in:
1 parent
8641464a6c
commit
3c1080e152
15 files changed
+282
-138
No files matched your search
+72
-71
@@ -1,83 +1,84 @@
|
||||
#!/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"
|
||||
|
||||
[[ -n "${*:-}" ]] || exit 2
|
||||
CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/hermes-stack-maintenance/config.env"
|
||||
if [[ ! -r "$CONFIG_FILE" ]]; then
|
||||
log "Benachrichtigung übersprungen: $CONFIG_FILE ist nicht lesbar."
|
||||
log "$*"
|
||||
log "Benachrichtigung übersprungen: Maintenance-Konfiguration 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
|
||||
source "$CONFIG_FILE" || { log "$*"; exit 0; }
|
||||
|
||||
notify_user() {
|
||||
local text="$1"
|
||||
local telegram_notify="${TELEGRAM_NOTIFY:-0}"
|
||||
local signal_notify="${SIGNAL_NOTIFY:-0}"
|
||||
local signal_payload
|
||||
log "$text"
|
||||
|
||||
if [[ -r "${HERMES_ENV:-}" ]] &&
|
||||
[[ "$telegram_notify" == "1" || "$signal_notify" == "1" ]]; then
|
||||
set +u
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$HERMES_ENV"
|
||||
set +a
|
||||
set -u
|
||||
fi
|
||||
|
||||
if [[ "$telegram_notify" == "1" &&
|
||||
-n "${TELEGRAM_BOT_TOKEN:-}" &&
|
||||
-n "${TELEGRAM_HOME_CHANNEL:-}" ]]; then
|
||||
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 || true
|
||||
fi
|
||||
|
||||
if [[ "$signal_notify" == "1" &&
|
||||
-n "${SIGNAL_HTTP_URL:-}" &&
|
||||
-n "${SIGNAL_ACCOUNT:-}" &&
|
||||
-n "${SIGNAL_HOME_CHANNEL:-}" ]]; then
|
||||
if [[ "$SIGNAL_HOME_CHANNEL" == group:* ]]; then
|
||||
if ! 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"}'
|
||||
)"; then
|
||||
log "Signal-Benachrichtigung konnte nicht vorbereitet werden."
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
if ! 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"}'
|
||||
)"; then
|
||||
log "Signal-Benachrichtigung konnte nicht vorbereitet werden."
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! 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
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
notify_user "$*" || true
|
||||
exit 0
|
||||
Reference in new issue
Block a user