From 6a7da5c15e79d70d3f866bd0d3467103eb6e84d1 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 3 Jun 2011 22:54:47 +0200 Subject: move -d and -g code If these switches are present and there are no arguments the program should exit and not try to upload stdin. Signed-off-by: Florian Pritz --- fb.in | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/fb.in b/fb.in index b899d5d..40f4258 100644 --- a/fb.in +++ b/fb.in @@ -154,7 +154,21 @@ shift `expr $OPTIND - 1` TMPDIR="`mktemp -d "/tmp/fb.XXXXXX"`" trap "rm -rf '${TMPDIR}'" EXIT TERM -if [ $# -eq 0 ]; then +if [ "$DELETE" ] || [ "$GET" ]; then + [ $# -eq 0 ] && exit 1; + for i in "$@"; do + i=$(id_from_arg "$i") + if [ "$DELETE" ]; then + if ! curl -n -L -A $USERAGENT "$PASTEBIN/file/delete/$i"; then + EXITCODE=1 + fi + elif [ "$GET" ]; then + if ! curl -s -o - -A $USERAGENT "$PASTEBIN/$i"; then + EXITCODE=1 + fi + fi + done +elif [ $# -eq 0 ]; then read_stdin "$TMPDIR/stdin" do_upload "$TMPDIR/stdin" else @@ -165,17 +179,7 @@ else break else for i in "$@"; do - if [ "$DELETE" ]; then - i=$(id_from_arg "$i") - if ! curl -n -L -A $USERAGENT "$PASTEBIN/file/delete/$i"; then - EXITCODE=1 - fi - elif [ "$GET" ]; then - i=$(id_from_arg "$i") - if ! curl -s -o - -A $USERAGENT "$PASTEBIN/$i"; then - EXITCODE=1 - fi - elif echo "$i" | grep -qE "^(f|ht)tp(s)?://.+"; then + if echo "$i" | grep -qE "^(f|ht)tp(s)?://.+"; then cd $TMPDIR if ! curl -# -A $USERAGENT -O "$i"; then EXITCODE=1 -- cgit v1.2.3-24-g4f1b