#!/bin/sh # # Wrapper script for BitTorrent downloads # # Download directory DLDIR=~/share/bittorrent/download # Default mode MODE=s IP=217.215.6.225 BTHEXE=btdownloadheadless.py BTCEXE=btdownloadcurses.py EXTRA_BTOPTS="--max_upload_rate 20" SCREEN=screen EXTRA_SCOPTS= XTERM=rxvt EXTRA_XTOPTS="-name network" [ $# -eq 0 ] && { echo "usage: btdl file|url [h|s|x]" >&2; exit 1; } if [ $# -gt 1 ]; then case "$2" in h) MODE=h;; s) MODE=s;; x) MODE=x;; *) echo "btdl: Invalid mode \`$2'" >&2; exit 1;; esac fi case "$1" in http://*) topt="--url \"$1\"" ;; *) [ -e "$1" ] || { echo "btdl: File \`$1' doesn't exist" >&2; exit 1; } dir=$(dirname "$1"); [ "$dir" = "." ] && dir=$(pwd) tail=$(basename "$1") if [ "$dir" != "$DLDIR" ]; then info=$(btshowmetainfo.py "$1") || exit 1 file=$(echo "$info" | awk ' /^directory name\.*:/ { sub(/^directory name\.*: /, ""); print; exit } /^file name\.*:/ { sub(/^file name\.*: /, ""); print; exit }') || exit 1 [ -f "$dir/$file" -o -d "$dir/$file" ] && ln -s "$dir/$file" $DLDIR ln -s "$dir/$tail" $DLDIR fi topt="--responsefile \"$tail\"" ;; esac case $MODE in h) cmd="$BTHEXE $topt --ip $IP $EXTRA_BTOPTS >/dev/null 2>&1 &" ;; s) cmd="$SCREEN -t \"BitTorrent [$1]\" $EXTRA_SCOPTS \ $BTCEXE $topt --ip $IP $EXTRA_BTOPTS" ;; x) cmd="$XTERM -T \"BitTorrent [$1]\" $EXTRA_XTOPTS \ -e $BTCEXE $topt --ip $IP $EXTRA_BTOPTS &" ;; esac cd $DLDIR eval $cmd .