feat: make gotify optional (#14)
All checks were successful
CD / Check changes (push) Successful in 6s
CD / Create tag (push) Successful in 14s
CD / Build and push (amd64) (push) Successful in 24s
CD / Build and push (arm64) (push) Successful in 1m25s
CD / Create manifest (push) Successful in 21s

Reviewed-on: #14
Co-authored-by: Timo Behrendt <t.behrendt@t00n.de>
Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
This commit was merged in pull request #14.
This commit is contained in:
2025-09-04 19:34:53 +02:00
committed by t.behrendt
parent 4cfb634397
commit cd92ce697e
2 changed files with 37 additions and 11 deletions

View File

@@ -26,10 +26,17 @@ done
#######################################
# Validate common required environment variables.
#######################################
# Gotify notification settings.
: "${GOTIFYHOST:?Environment variable GOTIFYHOST is not set}"
: "${GOTIFYTOKEN:?Environment variable GOTIFYTOKEN is not set}"
: "${GOTIFYTOPIC:?Environment variable GOTIFYTOPIC is not set}"
# Gotify notification settings (optional).
# Set ENABLE_GOTIFY to "true" to enable notifications, any other value or unset disables them.
ENABLE_GOTIFY="${ENABLE_GOTIFY:-true}"
if [ "$ENABLE_GOTIFY" = "true" ]; then
: "${GOTIFYHOST:?Environment variable GOTIFYHOST is not set (required when ENABLE_GOTIFY=true)}"
: "${GOTIFYTOKEN:?Environment variable GOTIFYTOKEN is not set (required when ENABLE_GOTIFY=true)}"
: "${GOTIFYTOPIC:?Environment variable GOTIFYTOPIC is not set (required when ENABLE_GOTIFY=true)}"
else
log "Gotify notifications disabled. Backup status will be logged to console only."
fi
# Restic encryption password.
: "${RESTIC_PASSWORD:?Environment variable RESTIC_PASSWORD is not set}"
@@ -62,9 +69,11 @@ case "$BACKUP_MODE" in
esac
#######################################
# Build the Gotify URL.
# Build the Gotify URL (only if Gotify is enabled).
#######################################
GOTIFYURL="${GOTIFYHOST}/message?token=${GOTIFYTOKEN}"
if [ "$ENABLE_GOTIFY" = "true" ]; then
GOTIFYURL="${GOTIFYHOST}/message?token=${GOTIFYTOKEN}"
fi
#######################################
# Date format for logging.
@@ -87,6 +96,13 @@ log() {
#######################################
send_notification() {
local message="$1"
# Only send notification if Gotify is enabled
if [ "$ENABLE_GOTIFY" != "true" ]; then
log "$message"
return 0
fi
if ! curl -s -X POST "$GOTIFYURL" -F "title=${GOTIFYTOPIC}" -F "message=${message}" >/dev/null; then
log "Warning: Failed to send notification with message: ${message}"
fi