Revert "Replaced rsc with a bash version without remote dependencies."
[utils.git] / btadd
... / ...
CommitLineData
1#!/bin/sh
2
3if [ $# -lt 1 ]; then
4 echo "usage: btadd [-d DIR] URL..." >&2
5 exit 1
6fi
7
8dir="$HOME/bt"
9rv=0
10while [ "$#" -gt 0 ]; do
11 arg="$1"
12 shift
13 if [ "$arg" = -d ]; then
14 dir="$1"
15 shift
16 elif [ "$arg" = -o ]; then
17 dir="$HOME/bt/$(date "+%y%m%d-%H%M%S")"
18 mkdir "$dir"
19 else
20 tfile="$(mktemp /tmp/torrentXXXXXX)"
21 if [ "$arg" = - ]; then
22 cat >"$tfile"
23 else
24 if ! wget -qO "$tfile" "$arg"; then
25 echo "btadd: could not fetch $arg" >&2
26 rv=1
27 rm "$tfile"
28 continue
29 fi
30 fi
31 if ! btcli add -d "$dir" "$tfile"; then
32 rv=1
33 fi
34 rm "$tfile"
35 fi
36done
37
38exit $rv