From f43a8c4f9bbc748ded3b0772fe2831267597debc Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 25 Jan 2012 18:04:56 +0100 Subject: fall back to openssl if base64 executable is not available Signed-off-by: Florian Pritz --- fb.in | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fb.in b/fb.in index 561a2df..e2b1b90 100644 --- a/fb.in +++ b/fb.in @@ -31,6 +31,18 @@ case "`uname -s`" in Minix) STAT='stat -size';; esac +base64_encode() { + if type base64 2>&1 >/dev/null; then + echo $1 | base64 + elif type openssl 2>&1 >/dev/null; then + echo $1 | openssl enc -base64 + else + echo "Warning: can't find base64 nor openssl executable" >&2 + echo " filename of uploaded file will be set to stdin" >&2 + echo "stdin" + fi +} + request_helper() { mode=$1 url=$2 @@ -50,7 +62,7 @@ request_helper() { if [ "$mode" = "u" ]; then basefilename=`basename -- "$file"` if [ `$STAT -- "$file"` -eq "0" ] || echo "$basefilename" | grep -F -q ","; then - base64fn=`echo "$basefilename" | base64 -w0 ` + base64fn="`base64_encode "$basefilename"`" curl $CURLOPTS -F "file=@-" -F "filename=$base64fn" "$url" < "$file" -o /dev/stdout else curl $CURLOPTS -F "file=@$file" "$url" -o /dev/stdout -- cgit v1.2.3-24-g4f1b