From 4054b066ab69e403c3933ca28d32dd9bf91723f8 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 2 Sep 2013 16:02:39 +0200 Subject: Use bash arrays to allow spaces in apikey file path This also fixes a bug in the shell uploader which used single quotes around the argument to --data-urlencode which sadly doesn't work at all. Signed-off-by: Florian Pritz --- fb.in | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/fb.in b/fb.in index ccc6236..f3e36c2 100644 --- a/fb.in +++ b/fb.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash #---------------------------------------------------- # Author: Florian "Bluewind" Pritz # Contributor: Moritz Wilhelmy @@ -52,7 +52,7 @@ clipboard="" exitcode=0 debug= useragent="fb-client/shell-$version" -default_curlopts="-# -L -A $useragent --speed-time 30 --speed-limit 1 --connect-timeout 10" +default_curlopts=(-# -L -A "$useragent" --speed-time 30 --speed-limit 1 --connect-timeout 10) base64_encode() { if type base64 2>&1 >/dev/null; then @@ -73,40 +73,40 @@ request_helper() { # if available use the external helper, else fall back to calling curl if [ -x "$libdir/fb-helper" ]; then - helperopts="" + helperopts=() if [ "$debug" ]; then - helperopts="$helperopts -D" + helperopts+=(-D) fi if [ -e "$apikey_file" ]; then - helperopts="$helperopts -a $apikey_file" + helperopts+=(-a $apikey_file) fi if [ "$mode" = "d" ]; then - $libdir/fb-helper $helperopts -u "$url" + $libdir/fb-helper "${helperopts[@]}" -u "$url" fi if [ "$mode" = "u" ]; then - $libdir/fb-helper $helperopts -u "$url" -f "$file" + $libdir/fb-helper "${helperopts[@]}" -u "$url" -f "$file" fi else - curlopts="$default_curlopts" + curlopts=(${default_curlopts[@]}) require_executable curl if [ -e "$apikey_file" ]; then - curlopts="$curlopts --data-urlencode 'apikey@$apikey_file'" + curlopts+=("--data-urlencode" "apikey@${apikey_file}") else - curlopts="$curlopts -n" + curlopts+=("-n") fi if [ "$debug" ]; then - curlopts="$curlopts -v" + curlopts+=("-v") fi if [ "$mode" = "d" ]; then - curlopts="$curlopts -s" + curlopts+=("-s") fi if [ "$mode" = "u" ]; then @@ -117,12 +117,12 @@ request_helper() { return 1 fi base64fn="`base64_encode "$basefilename"`" - curl $curlopts -F "file=@-" -F "filename=$base64fn" "$url" < "$file" -o /dev/stdout + curl "${curlopts[@]}" -F "file=@-" -F "filename=$base64fn" "$url" < "$file" -o /dev/stdout else - curl $curlopts -F "file=@$file" "$url" -o /dev/stdout + curl "${curlopts[@]}" -F "file=@$file" "$url" -o /dev/stdout fi else - curl $curlopts "$url" + curl "${curlopts[@]}" "$url" fi fi } @@ -249,12 +249,12 @@ create_apikey() { stty echo printf "\n" - curlopts="$default_curlopts" + curlopts=(${default_curlopts[@]}) if [ "$debug" ]; then - curlopts="$curlopts -v" + curlopts+=(-v) fi - curl $curlopts -w "%{http_code}\n" -s -F "username=<$tmpdir/username" -F "password=<$tmpdir/password" -F "comment=fb-client $USER@$HOST" "$pastebin/user/create_apikey" > "$tmpdir/api-result" + curl "${curlopts[@]}" -w "%{http_code}\n" -s -F "username=<$tmpdir/username" -F "password=<$tmpdir/password" -F "comment=fb-client $USER@$HOST" "$pastebin/user/create_apikey" > "$tmpdir/api-result" rm "$tmpdir/username" "$tmpdir/password" -- cgit v1.2.3-24-g4f1b