Torrent management: archive script (archived finished torrent)

From Bitpost wiki
Revision as of 17:22, 7 April 2009 by M (talk | contribs) (New page: <pre>#!/bin/bash # We move the torrent to [archived/backup]. # We move the file(s) to [archived/symlinks/#symlink#/]. # We create a symlink to the file(s). # We wait 10 seconds to be sure...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
#!/bin/bash

# We move the torrent to [archived/backup].
# We move the file(s) to [archived/symlinks/#symlink#/].
# We create a symlink to the file(s).
# We wait 10 seconds to be sure rtorrent has cleaned up.
# We update the torrent with a new hash and move it
# from [archived/backup] to [archived] so rtorrent can seed again.

scriptdir="/home/user/scripts/torrent"

# make sure directories do NOT have trailing slashes
torrentfile=${1%/}
filedir=${2%/}       # top-level file or dir in finished
sym=${3%/}           # new symlink location within [/archived/symlinks]

# check to make sure everything exists
cd ~/download/torrents
if [ "$torrentfile" = "" ] || [ ! -e "$torrentfile" ]; then
    echo "I need a valid torrent file..."
    exit 1
fi
if [ ! -e "finished/$filedir" ] && [ ! -d "finished/$filedir" ]; then
    echo "You need to tell me where the symlink is..."
    exit 2
fi

mv "$torrentfile" archived/backup/ && mv "finished/$filedir" "archived/symlinks/$sym/" && cd archived/symlinks/ && ln -s "$sym/$filedir" "$filedir"
sleep 10
$scriptdir/rtorrent_fast_resume.pl 2>/dev/null <"../backup/$torrentfile" >"../$torrentfile" && rm "../backup/$torrentfile"

exit