summaryrefslogtreecommitdiffstats
path: root/dev-shell
diff options
context:
space:
mode:
Diffstat (limited to 'dev-shell')
-rwxr-xr-xdev-shell38
1 files changed, 30 insertions, 8 deletions
diff --git a/dev-shell b/dev-shell
index 9e64500..eaacde9 100755
--- a/dev-shell
+++ b/dev-shell
@@ -3,16 +3,33 @@
# Copyright (c) 2012-2013 Kaarle Ritvanen
# See LICENSE file for license details
+function parse_var {
+ echo "$2" | sed "s/^$1: \\(.\\+\\)"$'\r'"\$/\\1/;ta;d;:a;q"
+}
+
function _acf_req {
local url=$ACF_URL$1
shift
- curl -s \
+
+ local resp
+ resp=$(curl -s -w $'\n\nStatus: %{response_code}\r\n' \
${ACF_AUTH_TOKEN:+-H "X-ACF-Auth-Token: $ACF_AUTH_TOKEN"} \
${ACF_TXN_ID:+-H "X-ACF-Transaction-ID: $ACF_TXN_ID"} \
- "$@" $url
+ "$@" $url)
local code=$?
- echo
- return $code
+
+ if [ $code -gt 0 ]; then
+ echo "Request failed, code $code" >&2
+ return 1
+ fi
+
+ echo "$resp"
+
+ local status=$(parse_var Status "$resp")
+ [ "${status:0:1}" = 2 ] && return
+
+ echo "Request failed" >&2
+ return 1
}
function _acf_start_req {
@@ -22,10 +39,15 @@ function _acf_start_req {
shift 3
local current=${!var}
- eval "export $var=\$(_acf_req \"\$url\" \"\$@\" \
- -D /proc/self/fd/1 -o /proc/self/fd/3 | \
- sed 's/^$hdr: \\(.\\+\\)'\$'\\r''\$/\\1/;ta;d;:a;q')"
- [ "${!var}" ] || exit
+ eval $var=
+ local status=
+
+ local resp
+ resp=$(_acf_req "$url" "$@" -D /proc/self/fd/1 -o /proc/self/fd/3)
+ [ $? -eq 0 ] || return
+
+ local id=$(parse_var $hdr "$resp")
+ eval export $var=$id
bash --rcfile "$ACF_QD_CLI" && _acf_req $url -X DELETE