2025-07-01 23:27:50 -06:00
|
|
|
#!/bin/bash
|
2025-06-27 09:01:51 -06:00
|
|
|
|
2025-07-01 23:27:50 -06:00
|
|
|
# Enhanced NAS cleanup script with thumbnail protection
|
|
|
|
|
# Usage: ./nascleanup.sh /volume1/Hydra/path/to/directory
|
2025-06-27 09:01:51 -06:00
|
|
|
|
2025-07-01 23:27:50 -06:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
|
echo "Usage: $0 <directory_path>"
|
|
|
|
|
echo "Example: $0 /volume1/Hydra/Creative/artsy"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
TARGET_DIR="$1"
|
|
|
|
|
|
|
|
|
|
echo "=== Enhanced Synology Thumbnail Cleanup ==="
|
|
|
|
|
echo "Target directory: $TARGET_DIR"
|
|
|
|
|
|
|
|
|
|
# 1. Stop indexing services temporarily
|
2025-10-15 18:28:09 -06:00
|
|
|
echo "Stopping indexing services (best effort)..."
|
|
|
|
|
if command -v synoservicectl >/dev/null 2>&1; then
|
|
|
|
|
synoservicectl --stop synoindexd 2>/dev/null || true
|
|
|
|
|
synoservicectl --stop pkgctl-SynoFinder 2>/dev/null || true
|
|
|
|
|
elif command -v systemctl >/dev/null 2>&1; then
|
|
|
|
|
systemctl stop synoindexd 2>/devnull || true
|
|
|
|
|
systemctl stop pkgctl-SynoFinder 2>/dev/null || true
|
|
|
|
|
else
|
|
|
|
|
echo " -> Service control unavailable; skipping"
|
|
|
|
|
fi
|
2025-07-01 23:27:50 -06:00
|
|
|
|
|
|
|
|
# 2. Clear indexing queue to prevent regeneration
|
2025-10-15 18:28:09 -06:00
|
|
|
echo "Clearing indexing queue (if accessible)..."
|
|
|
|
|
if [ -w /var/spool ]; then
|
|
|
|
|
rm -f /var/spool/syno_indexing_queue* 2>/dev/null || true
|
|
|
|
|
fi
|
2025-07-01 23:27:50 -06:00
|
|
|
|
|
|
|
|
# 3. Dry-run check (see what @eaDir directories exist)
|
|
|
|
|
echo "=== Existing @eaDir directories ==="
|
|
|
|
|
find "$TARGET_DIR" -type d -name '@eaDir' -exec echo '{}' \;
|
|
|
|
|
|
|
|
|
|
# 4. Remove any existing @eaDir directories
|
|
|
|
|
echo "=== Removing existing @eaDir directories ==="
|
|
|
|
|
find "$TARGET_DIR" -type d -name '@eaDir' -exec rm -rf '{}' \; 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
# 5. Rename eaDir_tmp to @eaDir (your custom thumbnails)
|
|
|
|
|
echo "=== Installing custom thumbnails ==="
|
2025-10-15 18:28:09 -06:00
|
|
|
# Use -depth so we process children before parents, and use $1 in bash -c for safety
|
|
|
|
|
find "$TARGET_DIR" -depth -type d -name 'eaDir_tmp' -exec bash -c 'd="$1"; mv "$d" "${d%/*}/@eaDir"' _ {} \; 2>/dev/null || true
|
2025-07-01 23:27:50 -06:00
|
|
|
|
|
|
|
|
# 6. Protect custom thumbnails with read-only permissions
|
|
|
|
|
echo "=== Adding indexing exclusion hints ==="
|
2025-10-15 18:28:09 -06:00
|
|
|
find "$TARGET_DIR" -type d -name '@eaDir' -exec sh -c 'touch "$1/.noindex" 2>/dev/null || true' _ {} \;
|
|
|
|
|
|
|
|
|
|
# 7. Protect custom thumbnails with read-only permissions (after .noindex)
|
|
|
|
|
echo "=== Protecting custom thumbnails ==="
|
|
|
|
|
find "$TARGET_DIR" -type d -name '@eaDir' -exec chmod 555 '{}' \; 2>/dev/null || true
|
|
|
|
|
find "$TARGET_DIR" -path '*/@eaDir/*' -type f -exec chmod 444 '{}' \; 2>/dev/null || true
|
2025-07-01 23:27:50 -06:00
|
|
|
|
|
|
|
|
echo "=== Cleanup complete! ==="
|
2025-10-15 18:28:09 -06:00
|
|
|
echo "Note: If indexing was stopped and needs restarting, use DSM UI or your NAS service tools."
|