From 0ffa37d6847e7e5758eab5df5a274a6ce0efbcd0 Mon Sep 17 00:00:00 2001
From: Stefano Pigozzi <me@steffo.eu>
Date: Sun, 19 Jan 2025 14:15:53 +0100
Subject: [PATCH] Fix ntfy messages

---
 backup.sh  | 6 ++++--
 restore.sh | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/backup.sh b/backup.sh
index 5fe5a3d..37cdce0 100755
--- a/backup.sh
+++ b/backup.sh
@@ -39,7 +39,8 @@ if [ -n "${NTFY}" ]; then
 	case "$backup_result" in
 		0)
 			echo "Sending ntfy backup complete notification..." >> /dev/stderr
-			ntfy_message=$(printf "Duplicity has successfully performed a backup to **${DUPLICITY_TARGET_URL}**!\n\n```\n")$(cat "/var/log/gestalt-amadeus/log.txt")$(printf "\n```")
+			backup_summary=$(grep --fixed-strings --after-context='16' --regexp='--------------[ Backup Statistics ]--------------' "/var/log/gestalt-amadeus/log.txt")
+			ntfy_message=$(printf "Duplicity has successfully performed a backup to **%s**!\n\n\`\`\`\n%s\n\`\`\`" "$DUPLICITY_TARGET_URL" "$backup_summary")
 			curl "${NTFY}" \
 				--silent \
 				--header "X-Title: Backup complete" \
@@ -51,7 +52,8 @@ if [ -n "${NTFY}" ]; then
 		;;
 		*)
 			echo "Sending ntfy backup failed notification..." >> /dev/stderr
-			ntfy_message=$(printf "Duplicity failed to perform a backup to **${DUPLICITY_TARGET_URL}**, and exited with status code **${backup_result}**.\n\n```\n")$(cat "/var/log/gestalt-amadeus/log.txt")$(printf "\n```")
+			backup_log=$(grep --fixed-strings --after-context='16' --regexp='--------------[ Backup Statistics ]--------------' "/var/log/gestalt-amadeus/log.txt")
+			ntfy_message=$(printf "Duplicity has failed to perform a backup to **%s**.\n\n\`\`\`\n%s\n\`\`\`" "$DUPLICITY_TARGET_URL" "$backup_log")
 			curl "${NTFY}" \
 				--silent \
 				--header "X-Title: Backup failed" \
diff --git a/restore.sh b/restore.sh
index 93fbac1..52553d1 100755
--- a/restore.sh
+++ b/restore.sh
@@ -18,7 +18,7 @@ duplicity \
 | tee "/var/log/gestalt-amadeus/log.txt"
 
 
-ntfy_message=$(printf "Duplicity has successfully restored a backup from **${DUPLICITY_TARGET_URL}**!\n\n```\n")$(cat "/var/log/gestalt-amadeus/log.txt")$(printf "\n```")
+ntfy_message=$(printf "Duplicity has successfully restored a backup from **%s**!" "${DUPLICITY_TARGET_URL}")
 
 curl "${NTFY}" \
 	--silent \