#!/bin/bash # Base directories SOURCE_DIR="/mnt/zpool0_nfs/cios_www" DEST_DIR="/mnt/zpool1_nfs/upload/torrent" TRACKER_URL="udp://tracker.dhitechnical.com:6969/announce" # Create destination directory if it doesn't exist mkdir -p "$DEST_DIR" # Loop through each directory in the source directory for dir in "$SOURCE_DIR"/*; do if [ -d "$dir" ]; then folder_name=$(basename "$dir") torrent_file="${folder_name}.torrent" torrent_path="${SOURCE_DIR}/${torrent_file}" magnet_file="${folder_name}.magnet" magnet_path="${SOURCE_DIR}/${magnet_file}" echo "Creating torrent for: $folder_name" # Create torrent with 8 MB pieces mktorrent -a "$TRACKER_URL" -l 23 -o "$torrent_path" "$dir" # Extract info hash info_hash=$(transmission-show -i "$torrent_path" | awk -F': ' '/Hash:/ {print $2}') # Build magnet link magnet_link="magnet:?xt=urn:btih:${info_hash}&dn=${folder_name}&tr=${TRACKER_URL}" # Save magnet link to file echo "$magnet_link" > "$magnet_path" # Move both torrent and magnet files mv "$torrent_path" "$DEST_DIR" mv "$magnet_path" "$DEST_DIR" echo "Moved $torrent_file and $magnet_file to $DEST_DIR" fi done echo "All torrents and magnet links created and moved successfully."