From 4b8883b47afb80a04bcd2758641176d3d736578e Mon Sep 17 00:00:00 2001 From: Brian Bennett Date: Wed, 9 Mar 2016 05:58:24 +0000 Subject: [PATCH] Use of 'grep -o' doesn't work on SunOS (fixes #164) --- letsencrypt.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/letsencrypt.sh b/letsencrypt.sh index c7e654c..5d09f9e 100755 --- a/letsencrypt.sh +++ b/letsencrypt.sh @@ -25,7 +25,7 @@ check_dependencies() { # just execute some dummy and/or version commands to see if required tools exist and are actually usable openssl version > /dev/null 2>&1 || _exiterr "This script requires an openssl binary." _sed "" < /dev/null > /dev/null 2>&1 || _exiterr "This script requires sed with support for extended (modern) regular expressions." - grep -V > /dev/null 2>&1 || _exiterr "This script requires grep." + command -v grep > /dev/null 2>&1 || _exiterr "This script requires grep." mktemp -u -t XXXXXX > /dev/null 2>&1 || _exiterr "This script requires mktemp." # curl returns with an error code in some ancient versions so we have to catch that @@ -160,7 +160,7 @@ init_system() { openssl rsa -in "${PRIVATE_KEY}" -check 2>/dev/null > /dev/null || _exiterr "Private key is not valid, can not continue." # Get public components from private key and calculate thumbprint - pubExponent64="$(openssl rsa -in "${PRIVATE_KEY}" -noout -text | grep publicExponent | grep -oE "0x[a-f0-9]+" | cut -d'x' -f2 | hex2bin | urlbase64)" + pubExponent64="$(printf '%x' $(openssl rsa -in "${PRIVATE_KEY}" -noout -text | awk '/publicExponent/ {print $2}') | hex2bin | urlbase64)" pubMod64="$(openssl rsa -in "${PRIVATE_KEY}" -noout -modulus | cut -d'=' -f2 | hex2bin | urlbase64)" thumbprint="$(printf '{"e":"%s","kty":"RSA","n":"%s"}' "${pubExponent64}" "${pubMod64}" | openssl dgst -sha256 -binary | urlbase64)" @@ -211,7 +211,8 @@ hex2bin() { # Get string value from json dictionary get_json_string_value() { - grep -Eo '"'"${1}"'":[[:space:]]*"[^"]*"' | cut -d'"' -f4 + local filter=$(printf 's/.*"%s": *"\([^"]*\)".*/\\1/p' "$1") + sed -n "$filter" } # OpenSSL writes to stderr/stdout even when there are no errors. So just @@ -363,7 +364,7 @@ sign_csr() { echo " + Requesting challenge for ${altname}..." response="$(signed_request "${CA_NEW_AUTHZ}" '{"resource": "new-authz", "identifier": {"type": "dns", "value": "'"${altname}"'"}}')" - challenges="$(printf '%s\n' "${response}" | grep -Eo '"challenges":[^\[]*\[[^]]*]')" + challenges="$(printf '%s\n' "${response}" | sed -n 's/.*\("challenges":[^\[]*\[[^]]*]\).*/\1/p')" repl=$'\n''{' # fix syntax highlighting in Vim challenge="$(printf "%s" "${challenges//\{/${repl}}" | grep \""${CHALLENGETYPE}"\")" challenge_token="$(printf '%s' "${challenge}" | get_json_string_value token | _sed 's/[^A-Za-z0-9_\-]/_/g')" -- 2.47.2