From e6d8dbf54254458337738768a9bdf5e044b22547 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 24 Nov 2011 20:01:38 +0100 Subject: add new functions: is_url() do_tar_upload() These will come in handy once -t supports bundling downloaded files (URL as an argument instead of a file). Signed-off-by: Florian Pritz --- fb.in | 46 ++++++++++++++++++++++++++++++++++------------ 1 file 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 -- cgit v1.2.3-24-g4f1b