#!/bin/bash # Enhanced NAS cleanup script with thumbnail protection # Usage: ./nascleanup.sh /volume1/Hydra/path/to/directory if [ $# -eq 0 ]; then echo "Usage: $0 " 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 echo "Stopping indexing services..." sudo synoservicectl --stop synoindexd 2>/dev/null || true sudo synoservicectl --stop pkgctl-SynoFinder 2>/dev/null || true # 2. Clear indexing queue to prevent regeneration echo "Clearing indexing queue..." sudo rm -f /var/spool/syno_indexing_queue* 2>/dev/null || true # 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 ===" find "$TARGET_DIR" -type d -name 'eaDir_tmp' -exec bash -c 'mv "$0" "${0%/*}/@eaDir"' {} \; # 6. Protect custom thumbnails with read-only permissions echo "=== Protecting custom thumbnails ===" find "$TARGET_DIR" -type d -name '@eaDir' -exec chmod 555 '{}' \; find "$TARGET_DIR" -path '*/@eaDir/*' -type f -exec chmod 444 '{}' \; # 7. Create .noindex files to hint indexing services to avoid these directories echo "=== Adding indexing exclusion hints ===" find "$TARGET_DIR" -type d -name '@eaDir' -exec touch '{}/.noindex' \; echo "=== Cleanup complete! ===" echo "Note: Indexing services stopped. They may restart automatically." echo "Run 'sudo synoservicectl --start synoindexd' if you need to re-enable indexing."