280
280
# 2021-11-10 Detect Solaris and use gnu tools (#701)(miesi)
281
281
# 2021-11-12 Support acme-dns and fix CNAME issues (#722)(#308)
282
282
# 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)
283
286
# ----------------------------------------------------------------------------------------
284
287
285
288
case :$SHELLOPTS : in
288
291
289
292
PROGNAME=${0##*/ }
290
293
PROGDIR=" $( cd " $( dirname " $0 " ) " || exit ; pwd -P; ) "
291
- VERSION=" 2.45 "
294
+ VERSION=" 2.46 "
292
295
293
296
# defaults
294
297
ACCOUNT_KEY_LENGTH=4096
@@ -358,6 +361,7 @@ _QUIET=0
358
361
_RECREATE_CSR=0
359
362
_REDIRECT_OUTPUT=" 1>/dev/null 2>&1"
360
363
_REVOKE=0
364
+ _SHOW_ACCOUNT_ID=0
361
365
_TEST_SKIP_CNAME_CALL=0
362
366
_TEST_SKIP_SOA_CALL=0
363
367
_UPGRADE=0
@@ -842,7 +846,7 @@ check_getssl_upgrade() { # check if a more recent release is available
842
846
# shellcheck disable=SC2086
843
847
status=$( curl ${_NOMETER:- --silent} -w " %{http_code}" --user-agent " $CURL_USERAGENT " " $CODE_LOCATION " --output " $TEMP_UPGRADE_FILE " )
844
848
errcode=$?
845
- debug errcode=$errcode
849
+ debug curl errcode=$errcode
846
850
847
851
if [[ $errcode -eq 60 ]]; then
848
852
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
1274
1278
}
1275
1279
1276
1280
find_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"
1295
1298
fi
1299
+ fi
1296
1300
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
1304
1307
fi
1305
1308
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
1310
1317
}
1311
1318
1312
1319
find_ftp_command () {
@@ -1955,13 +1962,14 @@ help_message() { # print out the help message
1955
1962
-i, --install Install certificates and reload service
1956
1963
-q, --quiet Quiet mode (only outputs on error, success of new cert, or getssl was upgraded)
1957
1964
-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)
1959
1966
-u, --upgrade Upgrade getssl if a more recent version is available - can be used with or without domain(s)
1960
1967
-X, --experimental tag Upgrade to experimental releases, specified by tag (e.g. v9.43)
1961
1968
-U, --nocheck Do not check if a more recent version is available
1962
1969
-v --version Display current version of $PROGNAME
1963
1970
-w working_dir "Working directory"
1964
1971
--preferred-chain "chain" Use an alternate chain for the certificate
1972
+ --account-id Display account id and exit
1965
1973
1966
1974
_EOF_
1967
1975
}
@@ -2591,7 +2599,7 @@ urlbase64_decode() {
2591
2599
usage () { # echos out the program usage
2592
2600
echo " Usage: $PROGNAME [-h|--help] [-d|--debug] [-c|--create] [-f|--force] [-a|--all] [-q|--quiet]" \
2593
2601
" [-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"
2595
2603
}
2596
2604
2597
2605
write_domain_template () { # write out a template file for a domain.
@@ -2825,6 +2833,8 @@ while [[ -n ${1+defined} ]]; do
2825
2833
shift ; WORKING_DIR=" $1 " ;;
2826
2834
-preferred-chain | --preferred-chain)
2827
2835
shift ; PREFERRED_CHAIN=" $1 " ;;
2836
+ --account-id)
2837
+ _SHOW_ACCOUNT_ID=1 ;;
2828
2838
--source)
2829
2839
return ;;
2830
2840
-* )
@@ -2897,9 +2907,13 @@ if [[ $_UPGRADE_CHECK -eq 1 ]]; then
2897
2907
check_getssl_upgrade
2898
2908
# if nothing in command line and no revocation and not only config check,
2899
2909
# 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
2901
2915
# 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
2903
2917
help_message
2904
2918
fi
2905
2919
graceful_exit
@@ -3130,7 +3144,7 @@ if [[ $API -eq 2 ]]; then
3130
3144
fi
3131
3145
3132
3146
# 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
3134
3148
real_d=${DOMAIN## \* .}
3135
3149
debug " getting certificate for $DOMAIN from remote server ($real_d )"
3136
3150
if [[ " $DUAL_RSA_ECDSA " == " true" ]]; then
@@ -3249,7 +3263,7 @@ if [[ "$DUAL_RSA_ECDSA" == "false" ]] && [[ -s "$DOMAIN_DIR/${DOMAIN}.key" ]]; t
3249
3263
fi
3250
3264
3251
3265
# 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
3253
3267
debug " certificate $CERT_FILE exists"
3254
3268
enddate=$( openssl x509 -in " $CERT_FILE " -noout -enddate 2> /dev/null| cut -d= -f 2-)
3255
3269
debug " local cert is valid until $enddate "
@@ -3277,7 +3291,7 @@ if [[ -s "$CERT_FILE" ]]; then
3277
3291
fi
3278
3292
# end of .... if there is an existing certificate file, check details.
3279
3293
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
3281
3295
errmsg=" $DOMAIN due for renewal,"
3282
3296
errmsg=" ${errmsg} but not completed due to PREVENT_NON_INTERACTIVE_RENEWAL=true in config"
3283
3297
error_exit " $errmsg "
@@ -3326,16 +3340,16 @@ info "Registering account"
3326
3340
# send the request to the ACME server.
3327
3341
if [[ $API -eq 1 ]]; then
3328
3342
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 ' "}'
3330
3344
else
3331
- regjson=' {"resource": "new-reg", "agreement": "' $AGREEMENT ' "}'
3345
+ regjson=' {"resource": "new-reg", "agreement": "' $AGREEMENT ' "}'
3332
3346
fi
3333
3347
send_signed_request " $URL_new_reg " " $regjson "
3334
3348
elif [[ $API -eq 2 ]]; then
3335
3349
if [[ " $ACCOUNT_EMAIL " ]] ; then
3336
- regjson=' {"termsOfServiceAgreed": true, "contact": ["mailto: ' $ACCOUNT_EMAIL ' "]}'
3350
+ regjson=' {"termsOfServiceAgreed": true, "contact": ["mailto: ' $ACCOUNT_EMAIL ' "]}'
3337
3351
else
3338
- regjson=' {"termsOfServiceAgreed": true}'
3352
+ regjson=' {"termsOfServiceAgreed": true}'
3339
3353
fi
3340
3354
send_signed_request " $URL_newAccount " " $regjson "
3341
3355
else
@@ -3346,19 +3360,24 @@ fi
3346
3360
if [[ " $code " == " " ]] || [[ " $code " == ' 201' ]] ; then
3347
3361
info " Registered"
3348
3362
KID=$( echo " $responseHeaders " | grep -i " ^location" | awk ' {print $2}' | tr -d ' \r\n ' )
3349
- debug " KID=_ $KID }_ "
3363
+ debug " AccountId= $KID }"
3350
3364
echo " $response " > " $TEMP_DIR /account.json"
3351
3365
elif [[ " $code " == ' 409' ]] ; then
3352
3366
KID=$( echo " $responseHeaders " | grep -i " ^location" | awk ' {print $2}' | tr -d ' \r\n ' )
3353
3367
debug responseHeaders " $responseHeaders "
3354
- debug " Already registered KID =$KID "
3368
+ debug " Already registered, AccountId =$KID "
3355
3369
elif [[ " $code " == ' 200' ]] ; then
3356
3370
KID=$( echo " $responseHeaders " | grep -i " ^location" | awk ' {print $2}' | tr -d ' \r\n ' )
3357
3371
debug responseHeaders " $responseHeaders "
3358
- debug " Already registered account, KID =${KID} "
3372
+ debug " Already registered account, AccountId =${KID} "
3359
3373
else
3360
3374
error_exit " Error registering account ...$responseHeaders ... $( json_get " $response " detail) "
3361
3375
fi
3376
+
3377
+ if [[ ${_SHOW_ACCOUNT_ID} -eq 1 ]]; then
3378
+ echo " Account Id is: $KID "
3379
+ graceful_exit
3380
+ fi
3362
3381
# end of registering account with CA
3363
3382
3364
3383
# verify each domain
0 commit comments