280280# 2021-11-10 Detect Solaris and use gnu tools (#701)(miesi)
281281# 2021-11-12 Support acme-dns and fix CNAME issues (#722)(#308)
282282# 2021-12-14 Enhancements for GoDaddy (support more levels of domain names, no longer require GODADDY_BASE, and actual deletion of resource records)
283+ # 2021-12-22 Don't show usage if run with --upgrade (#728)
284+ # 2021-12-23 Don't use +idnout if dig shows a warning (#688)
285+ # 2022-01-06 Support --account-id (#716)(2.46)
283286# ----------------------------------------------------------------------------------------
284287
285288case :$SHELLOPTS : in
288291
289292PROGNAME=${0##*/ }
290293PROGDIR=" $( cd " $( dirname " $0 " ) " || exit ; pwd -P; ) "
291- VERSION=" 2.45 "
294+ VERSION=" 2.46 "
292295
293296# defaults
294297ACCOUNT_KEY_LENGTH=4096
@@ -358,6 +361,7 @@ _QUIET=0
358361_RECREATE_CSR=0
359362_REDIRECT_OUTPUT=" 1>/dev/null 2>&1"
360363_REVOKE=0
364+ _SHOW_ACCOUNT_ID=0
361365_TEST_SKIP_CNAME_CALL=0
362366_TEST_SKIP_SOA_CALL=0
363367_UPGRADE=0
@@ -842,7 +846,7 @@ check_getssl_upgrade() { # check if a more recent release is available
842846 # shellcheck disable=SC2086
843847 status=$( curl ${_NOMETER:- --silent} -w " %{http_code}" --user-agent " $CURL_USERAGENT " " $CODE_LOCATION " --output " $TEMP_UPGRADE_FILE " )
844848 errcode=$?
845- debug errcode=$errcode
849+ debug curl errcode=$errcode
846850
847851 if [[ $errcode -eq 60 ]]; then
848852 error_exit " curl needs updating, your version does not support SNI (multiple SSL domains on a single IP)"
@@ -1274,39 +1278,42 @@ error_exit() { # give error message on error exit
12741278}
12751279
12761280find_dns_utils () {
1277- HAS_NSLOOKUP=false
1278- HAS_DIG_OR_DRILL=" "
1279- DIG_SUPPORTS_NOIDNOUT=false
1280- HAS_HOST=false
1281- if [[ -n " $( command -v nslookup 2> /dev/null) " ]]; then
1282- debug " HAS NSLOOKUP=true"
1283- HAS_NSLOOKUP=true
1284- fi
1285-
1286- if [[ -n " $( command -v drill 2> /dev/null) " ]]; then
1287- HAS_DIG_OR_DRILL=" drill"
1288- elif [[ -n " $( command -v dig 2> /dev/null) " ]] && dig > /dev/null 2>&1 ; then
1289- if dig -r > /dev/null 2>&1 ; then
1290- # use dig -r so ~/.digrc is not used
1291- HAS_DIG_OR_DRILL=" dig -r"
1292- else
1293- HAS_DIG_OR_DRILL=" dig"
1294- fi
1281+ HAS_NSLOOKUP=false
1282+ HAS_DIG_OR_DRILL=" "
1283+ DIG_SUPPORTS_NOIDNOUT=false
1284+ HAS_HOST=false
1285+ if [[ -n " $( command -v nslookup 2> /dev/null) " ]]; then
1286+ debug " HAS NSLOOKUP=true"
1287+ HAS_NSLOOKUP=true
1288+ fi
1289+
1290+ if [[ -n " $( command -v drill 2> /dev/null) " ]]; then
1291+ HAS_DIG_OR_DRILL=" drill"
1292+ elif [[ -n " $( command -v dig 2> /dev/null) " ]] && dig > /dev/null 2>&1 ; then
1293+ if dig -r > /dev/null 2>&1 ; then
1294+ # use dig -r so ~/.digrc is not used
1295+ HAS_DIG_OR_DRILL=" dig -r"
1296+ else
1297+ HAS_DIG_OR_DRILL=" dig"
12951298 fi
1299+ fi
12961300
1297- if [[ -n " $HAS_DIG_OR_DRILL " ]]; then
1298- if $HAS_DIG_OR_DRILL +noidnout > /dev/null 2>&1 ; then
1299- DIG_SUPPORTS_NOIDNOUT=true
1300- fi
1301-
1302- debug " HAS DIG_OR_DRILL=$HAS_DIG_OR_DRILL "
1303- debug " DIG_SUPPORTS_NOIDNOUT=$DIG_SUPPORTS_NOIDNOUT "
1301+ if [[ -n " $HAS_DIG_OR_DRILL " ]]; then
1302+ if dig_output=$( $HAS_DIG_OR_DRILL +noidnout localhost 2>&1 > /dev/null) ; then
1303+ # dig +noidnout on Ubuntu 18 succeeds, but outputs warning message to stderr - issue #688)
1304+ if [[ " $dig_output " != " ;; IDN support not enabled" ]]; then
1305+ DIG_SUPPORTS_NOIDNOUT=true
1306+ fi
13041307 fi
13051308
1306- if [[ -n " $( command -v host 2> /dev/null) " ]]; then
1307- debug " HAS HOST=true"
1308- HAS_HOST=true
1309- fi
1309+ debug " HAS DIG_OR_DRILL=$HAS_DIG_OR_DRILL "
1310+ debug " DIG_SUPPORTS_NOIDNOUT=$DIG_SUPPORTS_NOIDNOUT "
1311+ fi
1312+
1313+ if [[ -n " $( command -v host 2> /dev/null) " ]]; then
1314+ debug " HAS HOST=true"
1315+ HAS_HOST=true
1316+ fi
13101317}
13111318
13121319find_ftp_command () {
@@ -1955,13 +1962,14 @@ help_message() { # print out the help message
19551962 -i, --install Install certificates and reload service
19561963 -q, --quiet Quiet mode (only outputs on error, success of new cert, or getssl was upgraded)
19571964 -Q, --mute Like -q, but also mute notification about successful upgrade
1958- -r, --revoke "cert" "key" [CA_server] Revoke a certificate (the cert and key are required)
1965+ -r, --revoke "cert" "key" [CA_server] Revoke a certificate (the cert and key are required)
19591966 -u, --upgrade Upgrade getssl if a more recent version is available - can be used with or without domain(s)
19601967 -X, --experimental tag Upgrade to experimental releases, specified by tag (e.g. v9.43)
19611968 -U, --nocheck Do not check if a more recent version is available
19621969 -v --version Display current version of $PROGNAME
19631970 -w working_dir "Working directory"
19641971 --preferred-chain "chain" Use an alternate chain for the certificate
1972+ --account-id Display account id and exit
19651973
19661974 _EOF_
19671975}
@@ -2591,7 +2599,7 @@ urlbase64_decode() {
25912599usage () { # echos out the program usage
25922600 echo " Usage: $PROGNAME [-h|--help] [-d|--debug] [-c|--create] [-f|--force] [-a|--all] [-q|--quiet]" \
25932601 " [-Q|--mute] [-u|--upgrade] [-X|--experimental tag] [-U|--nocheck] [-r|--revoke cert key] [-w working_dir]" \
2594- " [--preferred-chain chain] domain"
2602+ " [--preferred-chain chain] [--account-id] domain"
25952603}
25962604
25972605write_domain_template () { # write out a template file for a domain.
@@ -2825,6 +2833,8 @@ while [[ -n ${1+defined} ]]; do
28252833 shift ; WORKING_DIR=" $1 " ;;
28262834 -preferred-chain | --preferred-chain)
28272835 shift ; PREFERRED_CHAIN=" $1 " ;;
2836+ --account-id)
2837+ _SHOW_ACCOUNT_ID=1 ;;
28282838 --source)
28292839 return ;;
28302840 -* )
@@ -2897,9 +2907,13 @@ if [[ $_UPGRADE_CHECK -eq 1 ]]; then
28972907 check_getssl_upgrade
28982908 # if nothing in command line and no revocation and not only config check,
28992909 # then exit after upgrade
2900- if [[ -z " $DOMAIN " ]] && [[ ${_CHECK_ALL} -ne 1 ]] && [[ ${_REVOKE} -ne 1 ]] && [ " ${_ONLY_CHECK_CONFIG} " -ne 1 ]; then
2910+ if [[ -z " $DOMAIN " ]] \
2911+ && [[ ${_CHECK_ALL} -ne 1 ]] \
2912+ && [[ ${_REVOKE} -ne 1 ]] \
2913+ && [ " ${_ONLY_CHECK_CONFIG} " -ne 1 ] \
2914+ && [[ ${_SHOW_ACCOUNT_ID} -ne 1 ]]; then
29012915 # if nothing in command line, print help before exit.
2902- if [[ -z " $DOMAIN " ]] && [[ ${_CHECK_ALL} -ne 1 ]]; then
2916+ if [[ -z " $DOMAIN " ]] && [[ ${_CHECK_ALL} -ne 1 ]] && [[ ${_UPGRADE} -ne 1 ]] ; then
29032917 help_message
29042918 fi
29052919 graceful_exit
@@ -3130,7 +3144,7 @@ if [[ $API -eq 2 ]]; then
31303144fi
31313145
31323146# if check_remote is true then connect and obtain the current certificate (if not forcing renewal)
3133- if [[ " ${CHECK_REMOTE} " == " true" ]] && [[ $_FORCE_RENEW -eq 0 ]]; then
3147+ if [[ " ${CHECK_REMOTE} " == " true" ]] && [[ $_FORCE_RENEW -eq 0 ]] && [[ $_SHOW_ACCOUNT_ID -eq 0 ]] ; then
31343148 real_d=${DOMAIN## \* .}
31353149 debug " getting certificate for $DOMAIN from remote server ($real_d )"
31363150 if [[ " $DUAL_RSA_ECDSA " == " true" ]]; then
@@ -3249,7 +3263,7 @@ if [[ "$DUAL_RSA_ECDSA" == "false" ]] && [[ -s "$DOMAIN_DIR/${DOMAIN}.key" ]]; t
32493263fi
32503264
32513265# if there is an existing certificate file, check details.
3252- if [[ -s " $CERT_FILE " ]]; then
3266+ if [[ -s " $CERT_FILE " ]] && [[ $_SHOW_ACCOUNT_ID -eq 0 ]] ; then
32533267 debug " certificate $CERT_FILE exists"
32543268 enddate=$( openssl x509 -in " $CERT_FILE " -noout -enddate 2> /dev/null| cut -d= -f 2-)
32553269 debug " local cert is valid until $enddate "
@@ -3277,7 +3291,7 @@ if [[ -s "$CERT_FILE" ]]; then
32773291fi
32783292# end of .... if there is an existing certificate file, check details.
32793293
3280- if [[ ! -t 0 ]] && [[ " $PREVENT_NON_INTERACTIVE_RENEWAL " = " true" ]]; then
3294+ if [[ ! -t 0 ]] && [[ " $PREVENT_NON_INTERACTIVE_RENEWAL " = " true" ]] && [[ $_SHOW_ACCOUNT_ID -eq 0 ]] ; then
32813295 errmsg=" $DOMAIN due for renewal,"
32823296 errmsg=" ${errmsg} but not completed due to PREVENT_NON_INTERACTIVE_RENEWAL=true in config"
32833297 error_exit " $errmsg "
@@ -3326,16 +3340,16 @@ info "Registering account"
33263340# send the request to the ACME server.
33273341if [[ $API -eq 1 ]]; then
33283342 if [[ " $ACCOUNT_EMAIL " ]] ; then
3329- regjson=' {"resource": "new-reg", "contact": ["mailto: ' $ACCOUNT_EMAIL ' "], "agreement": "' $AGREEMENT ' "}'
3343+ regjson=' {"resource": "new-reg", "contact": ["mailto: ' $ACCOUNT_EMAIL ' "], "agreement": "' $AGREEMENT ' "}'
33303344 else
3331- regjson=' {"resource": "new-reg", "agreement": "' $AGREEMENT ' "}'
3345+ regjson=' {"resource": "new-reg", "agreement": "' $AGREEMENT ' "}'
33323346 fi
33333347 send_signed_request " $URL_new_reg " " $regjson "
33343348elif [[ $API -eq 2 ]]; then
33353349 if [[ " $ACCOUNT_EMAIL " ]] ; then
3336- regjson=' {"termsOfServiceAgreed": true, "contact": ["mailto: ' $ACCOUNT_EMAIL ' "]}'
3350+ regjson=' {"termsOfServiceAgreed": true, "contact": ["mailto: ' $ACCOUNT_EMAIL ' "]}'
33373351 else
3338- regjson=' {"termsOfServiceAgreed": true}'
3352+ regjson=' {"termsOfServiceAgreed": true}'
33393353 fi
33403354 send_signed_request " $URL_newAccount " " $regjson "
33413355else
@@ -3346,19 +3360,24 @@ fi
33463360if [[ " $code " == " " ]] || [[ " $code " == ' 201' ]] ; then
33473361 info " Registered"
33483362 KID=$( echo " $responseHeaders " | grep -i " ^location" | awk ' {print $2}' | tr -d ' \r\n ' )
3349- debug " KID=_ $KID }_ "
3363+ debug " AccountId= $KID }"
33503364 echo " $response " > " $TEMP_DIR /account.json"
33513365elif [[ " $code " == ' 409' ]] ; then
33523366 KID=$( echo " $responseHeaders " | grep -i " ^location" | awk ' {print $2}' | tr -d ' \r\n ' )
33533367 debug responseHeaders " $responseHeaders "
3354- debug " Already registered KID =$KID "
3368+ debug " Already registered, AccountId =$KID "
33553369elif [[ " $code " == ' 200' ]] ; then
33563370 KID=$( echo " $responseHeaders " | grep -i " ^location" | awk ' {print $2}' | tr -d ' \r\n ' )
33573371 debug responseHeaders " $responseHeaders "
3358- debug " Already registered account, KID =${KID} "
3372+ debug " Already registered account, AccountId =${KID} "
33593373else
33603374 error_exit " Error registering account ...$responseHeaders ... $( json_get " $response " detail) "
33613375fi
3376+
3377+ if [[ ${_SHOW_ACCOUNT_ID} -eq 1 ]]; then
3378+ echo " Account Id is: $KID "
3379+ graceful_exit
3380+ fi
33623381# end of registering account with CA
33633382
33643383# verify each domain
0 commit comments