Torrent Mover v7.2 Torrent Mover is a Bash script designed to automate the processing of completed torrents in Transmission. It moves or copies downloaded files from a Transmission‑reported download location to designated destination directories on your system. This enhanced version includes robust locking, advanced error handling, parallel processing, configurable path mapping, and improved archive extraction while ensuring file integrity. Features Automatic Torrent Processing: Monitors Transmission for completed torrents and processes them based on configurable seeding criteria. Configurable Path Mapping: Uses Transmission’s reported download path (e.g. /downloads) and maps it to your local file system (e.g. /mnt/dsnas2) via configurable settings. Robust Locking: Employs flock to ensure that only one instance of the script runs at a time, preventing conflicts. Advanced Error Handling & Logging: A global error handler traps unexpected errors and logs detailed messages. Logs are output to a specified log file (and optionally to syslog) and support DEBUG mode. Parallel File Operations: Utilizes GNU Parallel for moving, copying, and generating file checksums, making file operations efficient and multi-threaded. Archive Extraction with Directory Preservation: When an archive (RAR, ZIP, 7z) is encountered in the source, it is extracted into a subdirectory (named after the archive, minus its extension) within the destination. Archives remain in the source until Transmission removes them based on seeding ratio/time limits. Directory Deduplication: Prevents re‑processing the same source directory if multiple torrents reference it, ensuring that files aren’t processed repeatedly. Optional Integrity Verification: If enabled, the script re‑calculates and compares file checksums after file transfer to verify integrity. Requirements Bash Transmission-remote (for interfacing with Transmission) GNU Parallel unrar, unzip, 7z (for archive extraction) bc (for numerical comparisons) Installation Download the Script: Save the script (e.g., torrent-mover.sh) to your desired location (e.g., /usr/local/bin/). Make It Executable: chmod +x /usr/local/bin/torrent-mover.sh Create/Edit the Configuration File: The script expects a configuration file at /etc/torrent/mover.conf. See the Configuration section for details. Configuration Create or modify the configuration file /etc/torrent/mover.conf with variables similar to the following: # Transmission settings TRANSMISSION_IP="192.168.1.100" # Replace with your Transmission server's IP TRANSMISSION_PORT="9091" # Replace with your Transmission server's port TRANSMISSION_USER="your_username" # Transmission username (if set) TRANSMISSION_PASSWORD="your_password" # Transmission password (if set) # Path mapping settings TRANSMISSION_PATH_PREFIX="/downloads" LOCAL_PATH_PREFIX="/mnt/dsnas2" # Destination directories DIR_GAMES_DST="/mnt/dsnas1/Games" DIR_APPS_DST="/mnt/dsnas1/Apps" DIR_MOVIES_DST="/mnt/dsnas1/Movies" DIR_BOOKS_DST="/mnt/dsnas1/Books" DEFAULT_DST="/mnt/dsnas1/Other" # Additional storage directories (comma-separated list) STORAGE_DIRS="/mnt/dsnas/Movies" # Performance settings PARALLEL_THREADS="32" PARALLEL_PROCESSING=1 # Operation mode: "move" or "copy" COPY_MODE="copy" # File tracking & integrity PROCESSED_LOG="/var/log/torrent_processed.log" CHECKSUM_DB="/var/lib/torrent/checksums.db" # Logging settings LOG_FILE="/var/log/torrent_mover.log" LOG_LEVEL="INFO" # Change to "DEBUG" for more verbose logging USE_SYSLOG="false" # Set to "true" to log to syslog as well # Optional integrity verification after file transfer ("true" to enable) CHECK_TRANSFER_INTEGRITY="true" Usage Run the script with various command-line options: Dry-run mode (simulate operations): /usr/local/bin/torrent-mover.sh --dry-run Interactive mode (prompt for confirmation): /usr/local/bin/torrent-mover.sh --interactive Cache warmup mode (pre-calculate checksums): /usr/local/bin/torrent-mover.sh --cache-warmup Debug mode (verbose logging): /usr/local/bin/torrent-mover.sh --debug You can combine these options as needed. For example: /usr/local/bin/torrent-mover.sh --dry-run --debug How It Works Locking: The script uses flock on a lock file to ensure that only one instance runs at a time. Path Translation: The Transmission-reported download path is translated into the actual local path using the mapping provided in the configuration. Torrent Processing: The script uses transmission-remote to list and retrieve torrent information. It processes torrents that are 100% complete (based on percent done) and checks if they’ve already been processed. File Verification & Deduplication: Before copying files, the script compares file checksums between the source and destination. It skips processing if an exact match is found and avoids re‑processing directories already handled for previous torrents. Archive Extraction: Archives in the source are extracted into dedicated subdirectories at the destination. The original archive file is kept until Transmission’s seeding criteria are met (and Transmission subsequently removes the torrent). Seeding Criteria: The script checks seeding ratio and seeding time values. When the criteria are met, it instructs Transmission (via transmission-remote) to remove the torrent. Integrity Check (Optional): If enabled, the script verifies file integrity by comparing md5 checksums of the source and destination files after transfer. License This script is provided as-is. Use at your own risk. Contributions and improvements are welcome!