diff --git a/README.md b/README.md index 8335be9..733c00f 100644 --- a/README.md +++ b/README.md @@ -1,136 +1,243 @@ -
- 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, improved archive extraction, - and optional file integrity verification. -
-/downloads
) and maps it to your local file system (e.g. /mnt/dsnas2
) via configurable settings.flock
to ensure that only one instance of the script runs at a time.torrent-mover.sh
) to your desired location (e.g., /usr/local/bin/
).chmod +x /usr/local/bin/torrent-mover.sh-
/etc/torrent/mover.conf
. See the configuration section below.Edit or create /etc/torrent/mover.conf
with the following content:
-# 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) +# Torrent Mover v8.0 -# Path mapping settings -TRANSMISSION_PATH_PREFIX="/downloads" -LOCAL_PATH_PREFIX="/mnt/dsnas2" +## Description -# 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" +**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 a modular architecture, dedicated security user, robust locking, advanced error handling with retry capabilities, +parallel processing, configurable path mapping, improved archive extraction, and optional file integrity verification. -# Additional storage directories (comma-separated list) -STORAGE_DIRS="/mnt/dsnas/Movies" +The system seamlessly organizes content into appropriate directories using smart pattern matching and customizable category detection, helping you maintain a well-structured media library with minimal manual intervention. -# Performance settings -PARALLEL_THREADS="32" -PARALLEL_PROCESSING=1 +## Features -# Operation mode: "move" or "copy" -COPY_MODE="copy" +### Core 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 and maps it to your local file system via configurable settings. +- **Archive Extraction:** Extracts archives (RAR, ZIP, 7z) into subdirectories at the destination—preserving internal structure—while retaining the archive in the source until seeding criteria are met. +- **Directory Deduplication:** Prevents re‑processing the same source directory if multiple torrents reference it. +### Advanced Content Organization +- **Smart Content Categorization:** Uses both pattern matching and directory name detection to properly categorize content. +- **Regex Pattern Matching:** Define custom regex patterns to precisely organize content into subcategories (documentaries, anime, etc.). +- **Multi-Library Support:** Manage content across multiple storage locations with different organization schemes. + +### Enhanced Security & Reliability +- **Dedicated Non-Root User:** Uses a dedicated service user with minimal permissions for enhanced security. +- **Error Recovery:** Includes retry mechanisms with configurable attempts and delay for network operations. +- **Data Integrity Protection:** Optionally verifies file integrity by comparing MD5 checksums after transfer. +- **Robust Locking:** Employs `flock` to ensure that only one instance of the script runs at a time. + +### Performance & Engineering +- **Modular Architecture:** Code is organized into separate modules for better maintainability and extensibility. +- **Parallel File Operations:** Utilizes GNU Parallel for moving, copying, and generating checksums, enabling efficient multi-threaded processing. +- **Advanced Error Handling & Logging:** Global error handler and detailed logging (with DEBUG mode support). Optionally, logs to syslog. + +## Requirements + +- Bash +- transmission-remote +- GNU Parallel +- unrar, unzip, 7z +- bc + +## Installation + +1. Run the installation script as root: + ``` + sudo ./install.sh + ``` + +2. The script will: + - Install all necessary dependencies + - Create a dedicated non-root user for security + - Set up the configuration file in `/etc/torrent/mover.conf` + - Install systemd service and timer + - Configure file permissions and log rotation + +3. Enable the service to run every 15 minutes: + ``` + sudo systemctl enable --now torrent-mover.timer + ``` + +## Configuration + +Edit the configuration file at `/etc/torrent/mover.conf` to customize the behavior of Torrent Mover: + +### Connection Configuration +```bash +# Transmission connection settings +TRANSMISSION_IP="192.168.1.100" # IP address of your Transmission server +TRANSMISSION_PORT="9091" # RPC port for Transmission +TRANSMISSION_USER="your_username" # Username for authentication (if enabled) +TRANSMISSION_PASSWORD="your_password" # Password for authentication (if enabled) + +# Path mapping configuration +TRANSMISSION_PATH_PREFIX="/downloads" # Path prefix reported by Transmission +LOCAL_PATH_PREFIX="/mnt/dsnas2" # Corresponding local path prefix +``` + +### Content Organization +```bash +# Primary content destination directories +DIR_GAMES_DST="/mnt/dsnas1/Games" # Games destination +DIR_APPS_DST="/mnt/dsnas1/Apps" # Applications destination +DIR_MOVIES_DST="/mnt/dsnas1/Movies" # Movies destination +DIR_BOOKS_DST="/mnt/dsnas1/Books" # Books/eBooks destination +DIR_TV_DST="/mnt/dsnas1/TV" # TV series destination +DIR_MUSIC_DST="/mnt/dsnas1/Music" # Music destination +DEFAULT_DST="/mnt/dsnas1/Other" # Default for unrecognized content + +# Additional storage libraries (comma-separated) +STORAGE_DIRS="/mnt/dsnas/Movies,/mnt/external/Movies" # Additional movie libraries +STORAGE_TV_DIRS="/mnt/dsnas/TV,/mnt/external/TV" # Additional TV libraries + +# Custom pattern matching for advanced categorization +# Format: "regex_pattern=destination_path;another_pattern=another_path" +CUSTOM_PATTERNS=".*documentary.*=${DIR_MOVIES_DST}/Documentary; + .*anime.*=${DIR_TV_DST}/Anime; + .*linux.*=${DIR_APPS_DST}/Linux; + .*tutorial.*=${DIR_BOOKS_DST}/Tutorials" +``` + +### Security & Performance +```bash +# Security settings - dedicated non-root user +TORRENT_USER="torrent-mover" # Dedicated service user +TORRENT_GROUP="torrent-mover" # User's primary group + +# Error recovery configuration +MAX_RETRY_ATTEMPTS="3" # Maximum retry attempts for failed operations +RETRY_WAIT_TIME="15" # Seconds to wait between retry attempts + +# Performance tuning +PARALLEL_THREADS="32" # Number of parallel threads (match CPU cores) +PARALLEL_PROCESSING=1 # Enable (1) or disable (0) parallel processing + +# Operation mode +COPY_MODE="copy" # "copy" to preserve or "move" to relocate files +``` + +### Logging & Integrity +```bash # File tracking & integrity -PROCESSED_LOG="/var/log/torrent_processed.log" -CHECKSUM_DB="/var/lib/torrent/checksums.db" +PROCESSED_LOG="/var/log/torrent_processed.log" # Tracks processed torrents +CHECKSUM_DB="/var/lib/torrent/checksums.db" # Stores file checksums -# Logging settings -LOG_FILE="/var/log/torrent_mover.log" -LOG_LEVEL="INFO" # Set to "DEBUG" for more verbose logging -USE_SYSLOG="false" # Set to "true" to log messages to syslog +# Logging configuration +LOG_FILE="/var/log/torrent_mover.log" # Main log file location +LOG_LEVEL="INFO" # Logging level: "INFO" or "DEBUG" +USE_SYSLOG="false" # Also log to system syslog: "true" or "false" -# Optional integrity verification after transfer ("true" to enable) -CHECK_TRANSFER_INTEGRITY="true" --
Run the script using the following options:
-/usr/local/bin/torrent-mover.sh --dry-run-
/usr/local/bin/torrent-mover.sh --interactive-
/usr/local/bin/torrent-mover.sh --cache-warmup-
/usr/local/bin/torrent-mover.sh --debug-
You can combine options as needed. For example:
-/usr/local/bin/torrent-mover.sh --dry-run --debug-
flock
to ensure only one instance runs at a time./downloads
) to the local file system path (e.g., /mnt/dsnas2
) using the configured mapping.transmission-remote
and processes torrents that are 100% complete. It skips torrents already processed or those with duplicate source directories.- This script is provided as-is without any warranty. Use it at your own risk. Contributions and improvements are welcome. -
-