From ae7a71574a3462e895083d2b714dc20a532a272a Mon Sep 17 00:00:00 2001 From: Pipo Date: Sat, 27 Sep 2025 17:26:05 +0200 Subject: [PATCH 1/2] Bugfixes --- .DS_Store | Bin 6148 -> 6148 bytes scripts/auto-snapclean-listener.sh | 44 +++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.DS_Store b/.DS_Store index a970548a0242c742fe5402e6a1cba76893c96ed3..ecb783bfb53febc44c2c3f90757aacfc4c44147d 100644 GIT binary patch delta 53 zcmZoMXfc@JFUroqz`)4BAi%(o%#gv5;+d15oRqWqAoFrYM)u7KOp1(~&oEoFOl+9H JnVsV=KLAuV4we7_ delta 140 zcmZoMXfc@JFUrZlz`)4BAi%(&%TUaa$B@WSz>vJzka;L L$FiB7<1aq|B1#*m diff --git a/scripts/auto-snapclean-listener.sh b/scripts/auto-snapclean-listener.sh index 935f82f..6f13e4d 100644 --- a/scripts/auto-snapclean-listener.sh +++ b/scripts/auto-snapclean-listener.sh @@ -1,40 +1,60 @@ #!/bin/zsh -set -euo pipefail +set -e -u +set -o pipefail # zsh: pipefail so wirklich aktiv LOGF="/var/log/snapclean.log" log() { print -r -- "$(date '+%F %T') $*" >> "$LOGF"; } +# minimaler PATH für launchd-Umgebung +export PATH="/usr/bin:/bin:/usr/sbin:/sbin" + is_running() { - /usr/bin/tmutil status 2>/dev/null | /usr/bin/grep -Eq '"Running" = 1|Running = 1' + if /usr/bin/tmutil status 2>/dev/null | /usr/bin/grep -Eq '"Running" = 1|Running = 1'; then + return 0 # running + else + return 1 # idle + fi } wait_until_tm_idle() { + set +e local i=0 while is_running; do sleep 2 (( i++ )) - [[ $i -gt 150 ]] && log "Timeout: TM still running. Waiting until it's finished." && break + [[ $i -gt 150 ]] && log "Timeout: TM noch Running, breche Warten ab." && break done + set -e + log "TM jetzt idle (oder Timeout erreicht)." + return 0 } delete_all_snapshots() { - log "Deletes all local Snapshots at / …" - /usr/bin/tmutil deletelocalsnapshots / || true - log "Finished deleting." + log "Snapshots vor Delete (/):" + /usr/bin/tmutil listlocalsnapshots / >>"$LOGF" 2>&1 || log "listlocalsnapshots(/): none/error" + + log "Lösche alle lokalen Snapshots auf / …" + set +e + /usr/bin/tmutil deletelocalsnapshots / >>"$LOGF" 2>&1 + local rc=$? + set -e + log "Fertig gelöscht. (rc=${rc})" } -# Make sure logfile exists -[[ -f "$LOGF" ]] || { sudo touch "$LOGF"; sudo chmod 644 "$LOGF"; } +# Sicherstellen, dass Logfile existiert (läuft als root – kein sudo nötig) +[[ -f "$LOGF" ]] || { : > "$LOGF"; /bin/chmod 644 "$LOGF"; } +# KEINE Pipe → keine Subshell-Probleme while IFS= read -r line; do + # nur die konkrete Zeile matchen, die du gepostet hast if print -r -- "$line" | /usr/bin/grep -q \ "com.apple.TimeMachine:LocalSnapshotManagement] Created Time Machine local snapshot"; then log "Event erkannt: $line" - # Short break until the snapshot is in index - sleep 2 - # Waiting until TM is finished + # Warten bis Time Machine fertig ist wait_until_tm_idle - # delete all local snapshots + # Ein Hauch warten, bis der Snapshot sicher im Index steht + sleep 10 + # Dann alle lokalen Snapshots löschen delete_all_snapshots fi done < <( From 65789f532855cb35bc6c4e96159c97744ce6dc4b Mon Sep 17 00:00:00 2001 From: Pipo Date: Sat, 27 Sep 2025 17:32:23 +0200 Subject: [PATCH 2/2] correctes comments --- scripts/auto-snapclean-listener.sh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/scripts/auto-snapclean-listener.sh b/scripts/auto-snapclean-listener.sh index 6f13e4d..36cf068 100644 --- a/scripts/auto-snapclean-listener.sh +++ b/scripts/auto-snapclean-listener.sh @@ -1,11 +1,10 @@ #!/bin/zsh set -e -u -set -o pipefail # zsh: pipefail so wirklich aktiv +set -o pipefail LOGF="/var/log/snapclean.log" log() { print -r -- "$(date '+%F %T') $*" >> "$LOGF"; } -# minimaler PATH für launchd-Umgebung export PATH="/usr/bin:/bin:/usr/sbin:/sbin" is_running() { @@ -22,39 +21,36 @@ wait_until_tm_idle() { while is_running; do sleep 2 (( i++ )) - [[ $i -gt 150 ]] && log "Timeout: TM noch Running, breche Warten ab." && break + [[ $i -gt 150 ]] && log "Timeout: TM still running. Abort" && break done set -e - log "TM jetzt idle (oder Timeout erreicht)." return 0 } delete_all_snapshots() { - log "Snapshots vor Delete (/):" + log "Snapshots before deletion (/):" /usr/bin/tmutil listlocalsnapshots / >>"$LOGF" 2>&1 || log "listlocalsnapshots(/): none/error" - log "Lösche alle lokalen Snapshots auf / …" + log "Delete all local snapshots at / …" set +e /usr/bin/tmutil deletelocalsnapshots / >>"$LOGF" 2>&1 local rc=$? set -e - log "Fertig gelöscht. (rc=${rc})" + log "Deletion successfull. (rc=${rc})" } -# Sicherstellen, dass Logfile existiert (läuft als root – kein sudo nötig) +# Make sure the logfile exists [[ -f "$LOGF" ]] || { : > "$LOGF"; /bin/chmod 644 "$LOGF"; } -# KEINE Pipe → keine Subshell-Probleme while IFS= read -r line; do - # nur die konkrete Zeile matchen, die du gepostet hast if print -r -- "$line" | /usr/bin/grep -q \ "com.apple.TimeMachine:LocalSnapshotManagement] Created Time Machine local snapshot"; then log "Event erkannt: $line" - # Warten bis Time Machine fertig ist + # Wait until Timemachine has finished wait_until_tm_idle - # Ein Hauch warten, bis der Snapshot sicher im Index steht + # Wait a moment until the the snapshot is in index sleep 10 - # Dann alle lokalen Snapshots löschen + # Delete all local snapshots delete_all_snapshots fi done < <(