Initial commit: combine nas_tool, nas_webdav, sync-utils

This commit is contained in:
Gan, Jimmy
2026-02-18 22:59:43 +08:00
commit 526c6a5521
77 changed files with 7898 additions and 0 deletions
+156
View File
@@ -0,0 +1,156 @@
#!/bin/bash
# Free Space Without Triggering Snapshot Growth
# Delete files that are ALREADY in snapshots or don't trigger snapshots
set -e
echo "=== Free Space Without Snapshot Growth ==="
echo ""
echo "⚠️ CRITICAL: Stop deleting regular files!"
echo " Every file you delete is preserved in the OS snapshot,"
echo " making System Data grow."
echo ""
echo "Instead, delete files that DON'T trigger snapshot growth:"
echo ""
FREE_SPACE_BEFORE=$(df / | tail -1 | awk '{print $4}')
FREE_SPACE_GB_BEFORE=$(echo "scale=2; $FREE_SPACE_BEFORE / 1024 / 1024" | bc)
echo "Current free space: ${FREE_SPACE_GB_BEFORE}GB"
echo ""
echo "🔧 Safe to Delete (Won't Grow System Data):"
echo ""
# 1. Caches (already cached, deleting doesn't create new snapshots)
echo "1. Library Caches (~6GB):"
CACHE_SIZE=$(du -sh ~/Library/Caches 2>/dev/null | awk '{print $1}' || echo "0")
echo " Size: $CACHE_SIZE"
echo " Command: rm -rf ~/Library/Caches/*"
echo " ✅ Safe - caches are temporary"
echo ""
# 2. User cache
echo "2. User Cache (~3GB):"
USER_CACHE=$(du -sh ~/.cache 2>/dev/null | awk '{print $1}' || echo "0")
echo " Size: $USER_CACHE"
echo " Command: rm -rf ~/.cache/*"
echo " ✅ Safe - temporary files"
echo ""
# 3. Downloads (if already backed up)
echo "3. Downloads (~9GB):"
DOWNLOADS_SIZE=$(du -sh ~/Downloads 2>/dev/null | awk '{print $1}' || echo "0")
echo " Size: $DOWNLOADS_SIZE"
echo " ⚠️ Only if files are already on NAS"
echo " Command: rm -rf ~/Downloads/*"
echo ""
# 4. Trash
echo "4. Trash:"
TRASH_SIZE=$(du -sh ~/.Trash 2>/dev/null | awk '{print $1}' || echo "0")
echo " Size: $TRASH_SIZE"
echo " Command: rm -rf ~/.Trash/*"
echo " ✅ Safe - already deleted"
echo ""
# 5. npm cache
echo "5. npm Cache (~1GB):"
NPM_SIZE=$(du -sh ~/.npm 2>/dev/null | awk '{print $1}' || echo "0")
echo " Size: $NPM_SIZE"
echo " Command: npm cache clean --force"
echo " ✅ Safe - can be regenerated"
echo ""
TOTAL_SAFE=$(echo "6 + 3 + 1" | bc)
echo "Estimated safe space to free: ~${TOTAL_SAFE}GB"
echo ""
read -p "Clean these safe items now? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
echo "🧹 Cleaning safe items..."
# Clean caches
if [ -d ~/Library/Caches ]; then
rm -rf ~/Library/Caches/* 2>/dev/null || true
echo " ✅ Cleaned Library/Caches"
fi
if [ -d ~/.cache ]; then
rm -rf ~/.cache/* 2>/dev/null || true
echo " ✅ Cleaned user cache"
fi
# Clean trash
if [ -d ~/.Trash ]; then
rm -rf ~/.Trash/* 2>/dev/null || true
echo " ✅ Emptied Trash"
fi
# Clean npm
if command -v npm &> /dev/null && [ -d ~/.npm ]; then
npm cache clean --force 2>/dev/null || true
echo " ✅ Cleaned npm cache"
fi
echo ""
echo "⏳ Waiting for system to update..."
sleep 5
fi
# Check results
FREE_SPACE_AFTER=$(df / | tail -1 | awk '{print $4}')
FREE_SPACE_GB_AFTER=$(echo "scale=2; $FREE_SPACE_AFTER / 1024 / 1024" | bc)
FREED_GB=$(echo "scale=2; $FREE_SPACE_GB_AFTER - $FREE_SPACE_GB_BEFORE" | bc)
echo ""
echo "=== Results ==="
echo " Before: ${FREE_SPACE_GB_BEFORE}GB free"
echo " After: ${FREE_SPACE_GB_AFTER}GB free"
if (( $(echo "$FREED_GB > 0" | bc -l) )); then
echo " ✅ Freed: ${FREED_GB}GB"
else
echo " ⚠️ No space freed (may need restart)"
fi
echo ""
echo "=== CRITICAL INSTRUCTIONS ==="
echo ""
echo "1. ⛔ STOP DELETING REGULAR FILES"
echo " Every file you delete makes System Data grow!"
echo ""
echo "2. ✅ Only delete:"
echo " - Caches (already done above)"
echo " - Trash (already done above)"
echo " - Files that are already on NAS"
echo ""
echo "3. 🚀 Install macOS Update NOW:"
echo " System Settings → General → Software Update"
echo " Install macOS Tahoe 26.2"
echo ""
echo " The update will:"
echo " - Clear the old snapshot"
echo " - Free the 351GB in System Data"
echo " - Stop the snapshot growth problem"
echo ""
echo "4. ⏳ If you don't have enough space for update:"
echo " - The update needs ~3.6GB"
echo " - Try downloading it first (may work with less space)"
echo " - Or move files to NAS instead of deleting"
echo ""
if (( $(echo "$FREE_SPACE_GB_AFTER < 4" | bc -l) )); then
echo "⚠️ Still low on space for update."
echo ""
echo " Try downloading the update first:"
echo " sudo softwareupdate --download --all"
echo ""
echo " Or move (don't delete) large files to NAS:"
echo " - Documents folder (40GB)"
echo " - .ollama models (17GB)"
echo ""
fi
echo ""