Merge pull request 'edge-host: fix settings-backup terminator check (trailing newline)' (#121) from fix/edge-zwave-settings-backup-newline into master

Reviewed-on: gitea_admin/homelab#121
This commit was merged in pull request #121.
This commit is contained in:
2026-07-07 11:52:54 +02:00
@@ -11,8 +11,9 @@ bak="$src.bak"
# Only back up a plausibly-intact file: non-empty and JSON-object-terminated.
# This avoids overwriting a good backup with a truncated (mid-write) file.
# Ignore trailing whitespace — settings.json ends with "}\n".
[ -s "$src" ] || { echo "settings.json missing/empty — skip"; exit 0; }
[ "$(tail -c1 "$src")" = "}" ] || { echo "settings.json not }-terminated (mid-write?) — skip"; exit 0; }
[ "$(tail -c 64 "$src" | tr -d '[:space:]' | tail -c1)" = "}" ] || { echo "settings.json not }-terminated (mid-write?) — skip"; exit 0; }
# Skip if unchanged since the last backup.
if [ -f "$bak" ] && cmp -s "$src" "$bak"; then