diff --git a/.DS_Store b/.DS_Store index ecb783b..a970548 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md index 677987c..ce6070c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ cd macOS-snapcleaner/scripts Run the installer: ```bash -chmod +x install.sh sudo ./install.sh ``` @@ -43,7 +42,6 @@ This will: To uninstall SnapCleaner: ```bash -chmod +x uninstall.sh sudo ./uninstall.sh ``` diff --git a/scripts/auto-snapclean-listener.sh b/scripts/auto-snapclean-listener.sh index 36cf068..935f82f 100644 --- a/scripts/auto-snapclean-listener.sh +++ b/scripts/auto-snapclean-listener.sh @@ -1,56 +1,40 @@ #!/bin/zsh -set -e -u -set -o pipefail +set -euo pipefail LOGF="/var/log/snapclean.log" log() { print -r -- "$(date '+%F %T') $*" >> "$LOGF"; } -export PATH="/usr/bin:/bin:/usr/sbin:/sbin" - is_running() { - 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 + /usr/bin/tmutil status 2>/dev/null | /usr/bin/grep -Eq '"Running" = 1|Running = 1' } wait_until_tm_idle() { - set +e local i=0 while is_running; do sleep 2 (( i++ )) - [[ $i -gt 150 ]] && log "Timeout: TM still running. Abort" && break + [[ $i -gt 150 ]] && log "Timeout: TM still running. Waiting until it's finished." && break done - set -e - return 0 } delete_all_snapshots() { - log "Snapshots before deletion (/):" - /usr/bin/tmutil listlocalsnapshots / >>"$LOGF" 2>&1 || log "listlocalsnapshots(/): none/error" - - log "Delete all local snapshots at / …" - set +e - /usr/bin/tmutil deletelocalsnapshots / >>"$LOGF" 2>&1 - local rc=$? - set -e - log "Deletion successfull. (rc=${rc})" + log "Deletes all local Snapshots at / …" + /usr/bin/tmutil deletelocalsnapshots / || true + log "Finished deleting." } -# Make sure the logfile exists -[[ -f "$LOGF" ]] || { : > "$LOGF"; /bin/chmod 644 "$LOGF"; } +# Make sure logfile exists +[[ -f "$LOGF" ]] || { sudo touch "$LOGF"; sudo chmod 644 "$LOGF"; } while IFS= read -r line; do if print -r -- "$line" | /usr/bin/grep -q \ "com.apple.TimeMachine:LocalSnapshotManagement] Created Time Machine local snapshot"; then log "Event erkannt: $line" - # Wait until Timemachine has finished + # Short break until the snapshot is in index + sleep 2 + # Waiting until TM is finished wait_until_tm_idle - # Wait a moment until the the snapshot is in index - sleep 10 - # Delete all local snapshots + # delete all local snapshots delete_all_snapshots fi done < <(