#!/bin/sh

# Constants
screen_name='autoseed-screen'
bt_command='bittorrent-curses --minport 2200 --maxport 2230'

# Check arguments, we only want a filename of the .torrent-file list.
if [ "$#" -ne 2 ]
then
	echo 'usage: autoseed.sh <filename-of-torrent-list> <ip>'
	exit 2
fi

working_dir=`pwd`
torrent_list=$1

echo 'Working dir is: ' $working_dir
echo "Reading torrent files from file '$1'"

echo "Creating screen session '$screen_name'..."
# Create a detached screen session by the name of $screen_name.
screen -d -m -O -S $screen_name

# For each .torrent-file, create a new screen window and execute $bt_command
# plus arguments (filename).
cat $torrent_list | \
while read line
do
	echo "Launching torrent: $line"

	# Connect to the screen session and create a new window for this torrent.
	screen -r $screen_name -X screen $bt_command --ip $2 $line
done

