From 3cb292cbb8cfb326046623574e4d99ff12e06e7f Mon Sep 17 00:00:00 2001 From: Lukas Schauer Date: Sun, 6 Dec 2015 16:35:28 +0100 Subject: [PATCH] trying to capture http status codes from curl instead of using "--fail" to be able to capture acme error messages --- letsencrypt.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/letsencrypt.sh b/letsencrypt.sh index ca5a6b1..26d0b33 100755 --- a/letsencrypt.sh +++ b/letsencrypt.sh @@ -51,22 +51,27 @@ hex2bin() { } _request() { - temperr="$(mktemp)" + tempcont="$(mktemp)" + if [[ "${1}" = "head" ]]; then - curl -sSf -I "${2}" 2> "${temperr}" + statuscode="$(curl -s -w "%{http_code}" -o "${tempcont}" "${2}" -I)" elif [[ "${1}" = "get" ]]; then - curl -sSf "${2}" 2> "${temperr}" + statuscode="$(curl -s -w "%{http_code}" -o "${tempcont}" "${2}")" elif [[ "${1}" = "post" ]]; then - curl -sSf "${2}" -d "${3}" 2> "${temperr}" + statuscode="$(curl -s -w "%{http_code}" -o "${tempcont}" "${2}" -d "${3}")" fi - if [[ -s "${temperr}" ]]; then - echo " + ERROR: An error occured while sending ${1}-request to ${2} ($(<"${temperr}"))" >&2 - rm -f "${temperr}" + if [[ ! "${statuscode:0:1}" = "2" ]]; then + echo " + ERROR: An error occured while sending ${1}-request to ${2} (Status ${statuscode})" >&2 + echo >&2 + echo "Details:" >&2 + echo "$(<"${tempcont}"))" >&2 + rm -f "${tempcont}" exit 1 fi - rm -f "${temperr}" + cat "${tempcont}" + rm -f "${tempcont}" } signed_request() { -- 2.47.3