Added {r,}btadd.
authorfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Sun, 12 Aug 2007 01:36:54 +0000 (01:36 +0000)
committerfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Sun, 12 Aug 2007 01:36:54 +0000 (01:36 +0000)
git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@1095 959494ce-11ee-0310-bf91-de5d638817bd

btadd [new file with mode: 0755]
rbtadd [new file with mode: 0755]

diff --git a/btadd b/btadd
new file mode 100755 (executable)
index 0000000..4776e3b
--- /dev/null
+++ b/btadd
@@ -0,0 +1,38 @@
+#!/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
diff --git a/rbtadd b/rbtadd
new file mode 100755 (executable)
index 0000000..3dad05a
--- /dev/null
+++ b/rbtadd
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+if [ $# -lt 1 ]; then
+    echo "usage: btadd URL..." >&2
+    exit 1
+fi
+
+for file in "$@"; do
+    if [ -r "$file" ]; then
+       rsc pc17 btadd -o - <"$file" && rm -f "$file"
+    elif [[ "$file" == http*://* ]]; then
+       rsc pc17 btadd -o "$file"
+    else
+       echo "rbtadd: $file: unreadable" >&2
+    fi
+done