feat: amke gotify optional

This commit is contained in:
2025-09-04 19:33:48 +02:00
parent 0c0305301e
commit eadb21d4b5
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