#!/bin/sh
###########################################################################
# script to monitor a specific directory for new .torrent files.
# if found, queue them up in transmission 
# and when done downloading, pause the torrent  
# w 10/20/08 horto
# u 10/29/08 horto - implmented "make transmission stop after seeding 1:1"
###########################################################################
TORRENTDIR=/mnt/HD_a2/torrents
WDLOG=$TORRENTDIR/.torrentwd.log
TRANSMISSION_REMOTE=/ffp/bin/transmission-remote

# check incoming TORRENTDIR
for FILE in $TORRENTDIR/*.torrent; do
  if [ "$FILE" != "$TORRENTDIR/*.torrent" ]; then
      echo [`date`] "$FILE" added to queue. >> $WDLOG
      $TRANSMISSION_REMOTE -a "$FILE"
      rm "$FILE"
      echo [`date`] "$FILE" deleted from directory. >> $WDLOG
      sleep 1
  fi
done

# stop completed downloads
for i in `/ffp/bin/transmission-remote -l | grep Done | grep -v Ratio | awk '{print $1}'"`; do
  echo [`date`] stopping torrent id $i >> $WDLOG
  $TRANSMISSION_REMOTE -t $i -S
done


exit 0

