From b3ddc9a373ac7d66bc019b9d38319348006f5160 Mon Sep 17 00:00:00 2001 From: paulmataruso Date: Wed, 23 Apr 2025 17:55:10 +0000 Subject: [PATCH] Add make_torrent_static.sh --- make_torrent_static.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 make_torrent_static.sh diff --git a/make_torrent_static.sh b/make_torrent_static.sh new file mode 100644 index 0000000..b8ad09b --- /dev/null +++ b/make_torrent_static.sh @@ -0,0 +1,42 @@ +#!/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." \ No newline at end of file