summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@server-speed.net>2012-01-25 18:04:56 +0100
committerFlorian Pritz <bluewind@server-speed.net>2012-01-25 18:04:56 +0100
commitf43a8c4f9bbc748ded3b0772fe2831267597debc (patch)
tree3b0990e18f6bfe216d68b84c7d6d069cdf8be6b8
parent71c549b64d15c2a7b3736f21f65cf6ca4dbb7ee0 (diff)
fall back to openssl if base64 executable is not available
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
-rw-r--r--fb.in14
1 files changed, 13 insertions, 1 deletions
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