#!/bin/sh # Wrapper script for btdownloadcurses, which has dumb commandline processing # # Copyright 2003, Steven Mueller # This script is released into the public domain. # # Last modified: September 14, 2003 18:45 Sunday -0700 # Configuration options ----------------------------------------------- # The path to your bittorrent client of choice (gui, curses, or headless) BTPROG="$HOME/src/python/bt/btdownloadcurses" # Default upload limit. Set to "" or comment out to disable. UPRATE="3" # End configurable options -------------------------------------------- set -e showhelp () { cat << ENDUSAGE Usage: $0 [-r uploadratelimit] [-o saveasfile] [ -f responsefile | -u url | file | url ] ... Launch $BTPROG in a more concise way. If one of -f or -u are not specified, then the filename or url of the torrent is taken from the commandline. Any remaining arguments are passed on to the bittorrent client as-is. Options: -f file local torrent file (--responsefile) -u url remote torrent file url (--url) -o file use this file or directory for output (--saveas) -r # set maximum upload rate in kiB/s -h show this usage information ENDUSAGE } errexit () { echo "$0: Error: $1" echo showhelp exit 2 } # Parse options, allowing for wacky spaces in bad places and naughty characters eval set -- "`getopt -s bash -- f:u:o:r:h "$@"`" if test $? != 0 ; then showhelp exit 2 fi # Process options for i; do case "$i" in -f) [ -n "$TORRENT" ] && errexit "Only one of -f or -u can be specified." TTYPE="--responsefile" TORRENT="$2"; shift 2 ;; -u) [ -n "$TORRENT" ] && errexit "Only one of -f or -u can be specified." TTYPE="--url" TORRENT="$2"; shift 2 ;; -o) SAVEAS="$2"; shift 2 ;; -r) UPRATE="$2"; shift 2 ;; -h) showhelp; exit 0;; --) shift; break;; esac done # Process arguments if [ -z "$TORRENT" ]; then [ $# -lt 1 ] && errexit "No torrent file or url specified." TORRENT="$1"; shift if [ -r "$TORRENT" -a ! -d "$TORRENT" ]; then echo "Processing $TORRENT as a responsefile." TTYPE="--responsefile" else echo "Processing $TORRENT as an url." TTYPE="--url" fi fi if [ -n "$SAVEAS" ]; then # handle spaces and funky characters properly set -- --saveas "$SAVEAS" "$@" fi if [ -n "$UPRATE" ]; then UPARG="--max_upload_rate $UPRATE" fi set -x exec "$BTPROG" $UPARG "$TTYPE" "$TORRENT" "$@"