summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2011-11-24 20:01:38 +0100
committerFlorian Pritz <bluewind@xinu.at>2011-11-24 20:01:38 +0100
commite6d8dbf54254458337738768a9bdf5e044b22547 (patch)
tree7f0ae264336e7f561954a1a3fccbb24a3e2d22c9
parentfd4599262410cc0165a6c17fb624057a6b82d2b0 (diff)
add new functions: is_url() do_tar_upload()v0.9.1
These will come in handy once -t supports bundling downloaded files (URL as an argument instead of a file). Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--fb.in46
1 files changed, 34 insertions, 12 deletions
diff --git a/fb.in b/fb.in
index ead38ef..2d9df34 100644
--- a/fb.in
+++ b/fb.in
@@ -31,6 +31,28 @@ require_executable() {
fi
}
+is_url() {
+ if echo "$i" | grep -qE "^(f|ht)tp(s)?://.+"; then
+ return 0
+ fi
+ return 1
+}
+
+do_tar_upload() {
+ if [ "$COMPRESS" = "1" ]; then
+ file="$TMPDIR/upload.tar.gz"
+ tar -cf - -- "$@" | gzip -c > "$file" || return 1
+ elif [ "$COMPRESS" = "2" ]; then
+ file="$TMPDIR/upload.tar.xz"
+ tar -cf - -- "$@" | xz -c > "$file" || return 1
+ else
+ file="$TMPDIR/upload.tar"
+ tar -cf "$file" -- "$@" || return 1
+ fi
+ COMPRESS=0
+ do_upload "$file" || return 1
+}
+
do_upload() {
local EXTRA=""
file="$1"
@@ -177,22 +199,22 @@ elif [ $# -eq 0 ]; then
do_upload "$TMPDIR/stdin" || EXITCODE=1
else
if [ "$TAR" ]; then
- if [ "$COMPRESS" = "1" ]; then
- file="$TMPDIR/upload.tar.gz"
- tar -cf - -- "$@" | gzip -c > "$file"
- elif [ "$COMPRESS" = "2" ]; then
- file="$TMPDIR/upload.tar.xz"
- tar -cf - -- "$@" | xz -c > "$file"
+ HAVE_URL=
+ for i in "$@"; do
+ if is_url "$i"; then
+ HAVE_URL=1
+ fi
+ done
+ if [ "$HAVE_URL" ]; then
+ # TODO: support -t when passing URLs as arguments
+ echo "Error: -t is not yet supported when operating on a URL" >&2
+ exit 1
else
- file="$TMPDIR/upload.tar"
- tar -cf "$file" -- "$@"
+ do_tar_upload "$@" || EXITCODE=1
fi
- COMPRESS=0
- do_upload "$file" || EXITCODE=1
- break
else
for i in "$@"; do
- if echo "$i" | grep -qE "^(f|ht)tp(s)?://.+"; then
+ if is_url "$i"; then
cd $TMPDIR
if ! $LIBDIR/fb-helper d "$i" > "`basename "$i"`"; then
EXITCODE=1