From 41488c9750b7675dcb544a36e2efb9b00aad6209 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 11 Dec 2011 13:41:52 +0100 Subject: add bash version of fb-helper.c Using the bash helper can be forced by running "make LIBCURL=". Signed-off-by: Florian Pritz --- Makefile | 8 ++++++++ fb-helper.sh.in | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 fb-helper.sh.in diff --git a/Makefile b/Makefile index 07857fc..8f1fbd9 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,16 @@ fb: fb.in sed 's|@VERSION@|$(VERSION)|; s|@LIBDIR@|$(LIBDIR)|' $< > $@ chmod 755 $@ +ifdef LIBCURL fb-helper: fb-helper.c $(CC) $(CFLAGS) $(LIBCURL) -DVERSION=\"$(VERSION)\" -o $@ $< +else +fb-helper: fb-helper.sh.in + @echo "libcurl not found. using shell helper..." + @[ -n "$(VERSION)" ] || (echo "Error: version detection failed"; exit 1) + sed 's|@VERSION@|$(VERSION)|; s|@LIBDIR@|$(LIBDIR)|' $< > $@ + chmod 755 $@ +endif fb.1: fb.pod pod2man -c "" $< $@ diff --git a/fb-helper.sh.in b/fb-helper.sh.in new file mode 100644 index 0000000..3a4e3b2 --- /dev/null +++ b/fb-helper.sh.in @@ -0,0 +1,20 @@ +#!/bin/sh + +mode=$1 +url=$2 +file=$3 + +USERAGENT="fb-client/shell-@VERSION@" +CURLOPTS="-n -L -A $USERAGENT" + +if [ "$mode" = "u" ]; then + basefilename=`basename -- "$file"` + if [ `stat -c %s -- "$file"` -eq "0" ] || echo "$basefilename" | grep -F -q ","; then + basefilename=`echo "$basefilename" | tr -d ,` + curl $CURLOPTS -F "file=@-;filename=$basefilename" "$url" < "$file" -o /dev/stdout + else + curl $CURLOPTS -F "file=@$file" "$url" -o /dev/stdout + fi +else + curl $CURLOPTS "$url" +fi -- cgit v1.2.3-24-g4f1b