#!/bin/sh if [ $# -lt 1 ]; then echo "usage: btadd [-d DIR] URL..." >&2 exit 1 fi dir="$HOME/bt" rv=0 while [ "$#" -gt 0 ]; do arg="$1" shift if [ "$arg" = -d ]; then dir="$1" shift elif [ "$arg" = -o ]; then dir="$HOME/bt/$(date "+%y%m%d-%H%M%S")" mkdir "$dir" else tfile="$(mktemp /tmp/torrentXXXXXX)" if [ "$arg" = - ]; then cat >"$tfile" else if ! wget -qO "$tfile" "$arg"; then echo "btadd: could not fetch $arg" >&2 rv=1 rm "$tfile" continue fi fi if ! btcli add -d "$dir" "$tfile"; then rv=1 fi rm "$tfile" fi done exit $rv