Skip to content

Instantly share code, notes, and snippets.

@bulljit
Created January 23, 2011 02:31
Show Gist options
  • Save bulljit/791750 to your computer and use it in GitHub Desktop.
Save bulljit/791750 to your computer and use it in GitHub Desktop.
Transmission-Daemon Script: OnComplete unrar files and delete torrent
#!/bin/sh
DEST_DIR="/some/other/dir"
function linker() { # create simlink to downloaded files, rather than copy to final directory
if [ ! -d "$DEST_DIR/$1" ]; then mkdir "$DEST_DIR/$1"; fi
cd "$1"
for F in *; do
if [ -d "$F" ]; then linker "$1/$F"; fi
ln -s "$TR_TORRENT_DIR/$1/$F" "$DEST_DIR/$1"
done
}
cd $TR_TORRENT_DIR
if [ -d "$TR_TORRENT_NAME" ]
then
if ls "$TR_TORRENT_NAME"/*.rar > /dev/null 2>&1
then
find "$TR_TORRENT_NAME" -iname "*.rar" | while read file
do
unrar x -inul "$file"
done
transmission-remote -n name:password -t$TR_TORRENT_ID --remove-and-delete &
echo "Unrarred $TR_TORRENT_NAME" >> /var/log/posttorrent.log
else # for multifile torrents that aren't rar'd
# cp -r "$TR_TORRENT_NAME" "$DEST_DIR"
linker "$TR_TORRENT_NAME"
fi
else # for single file torrents
# cp "$TR_TORRENT_NAME" "$DEST_DIR"
ln -s "$TR_TORRENT_NAME" "$DEST_DIR"
fi
@bulljit
Copy link
Author

bulljit commented Jan 23, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment