diff options
author | Florian Pritz <bluewind@server-speed.net> | 2012-01-25 18:04:56 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@server-speed.net> | 2012-01-25 18:04:56 +0100 |
commit | f43a8c4f9bbc748ded3b0772fe2831267597debc (patch) | |
tree | 3b0990e18f6bfe216d68b84c7d6d069cdf8be6b8 | |
parent | 71c549b64d15c2a7b3736f21f65cf6ca4dbb7ee0 (diff) |
fall back to openssl if base64 executable is not available
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
-rw-r--r-- | fb.in | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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 |