From 70ee986d931a189f9d0a21b4e288ce444cf48e3d Mon Sep 17 00:00:00 2001 From: Alex Thomassen Date: Tue, 27 Dec 2022 21:25:52 +0100 Subject: [PATCH] Add per-domain DNS/webroot handling --- generate-acme.sh | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/generate-acme.sh b/generate-acme.sh index 36f6d22..89ebaca 100644 --- a/generate-acme.sh +++ b/generate-acme.sh @@ -48,6 +48,7 @@ OIFS=$IFS IFS=' ' echo "${ECHO_PREFIX} Space-separated list of domains to generate a certificate for?" +echo "${ECHO_PREFIX} You can specify a DNS provider or webroot for each domain. For example: some.example.com:/var/www/html other.example.com:dns_cf" read DOMAIN_LIST DOMAINS=($DOMAIN_LIST) @@ -56,25 +57,41 @@ DOMAIN_PARAMS="" ACME_PARAMS="" for (( i = 0; i < ${#DOMAINS[@]}; i++ )); do - DOMAIN_PARAMS+=" -d ${DOMAINS[$i]}" + DOMAIN="${DOMAINS[$i]}"; + DOMAIN_NAME="$(echo $DOMAIN | cut -d ':' -f 1)"; + PROVIDER_NAME="$(echo $DOMAIN | cut -d ':' -f 2)"; + + PROVIDER_TYPE="--dns"; + if [[ -z "${PROVIDER_NAME}" ]]; then + PROVIDER_NAME="dns_cf"; + fi + + # Starts with a slash, we assume it's a path & webroot. + if [[ "${PROVIDER_NAME}" =~ "^/"* ]]; then + PROVIDER_TYPE="-w"; + fi + + DOMAIN_PARAMS+=" -d ${DOMAIN_NAME}"; + ACME_PARAMS+=" -d ${DOMAIN_NAME} ${PROVIDER_TYPE} ${PROVIDER_NAME}"; done -echo "${ECHO_PREFIX} DNS? [y/N]" -read IS_DNS +# DNS handler is now specified as part of the domain list. +# echo "${ECHO_PREFIX} DNS? [y/N]" +# read IS_DNS -IS_DNS=${IS_DNS,,} -if [[ $IS_DNS == *"y"* ]]; then - echo "${ECHO_PREFIX} DNS provider? For example: Cloudflare = dns_cf." - echo "${ECHO_PREFIX} Provider also assumes the proper environment variables are set. Read: https://github.com/Neilpang/acme.sh/tree/master/dnsapi#how-to-use-dns-api" - read DNS_PROVIDER +# IS_DNS=${IS_DNS,,} +# if [[ $IS_DNS == *"y"* ]]; then +# echo "${ECHO_PREFIX} DNS provider? For example: Cloudflare = dns_cf." +# echo "${ECHO_PREFIX} Provider also assumes the proper environment variables are set. Read: https://github.com/Neilpang/acme.sh/tree/master/dnsapi#how-to-use-dns-api" +# read DNS_PROVIDER - ACME_PARAMS+="--dns ${DNS_PROVIDER}" -else - echo "${ECHO_PREFIX} Webroot? For example: /var/www/html" - read WEBROOT_DIR +# ACME_PARAMS+="--dns ${DNS_PROVIDER}" +# else +# echo "${ECHO_PREFIX} Webroot? For example: /var/www/html" +# read WEBROOT_DIR - ACME_PARAMS+="-w ${WEBROOT_DIR}" -fi +# ACME_PARAMS+="-w ${WEBROOT_DIR}" +# fi # Make sure we point to the right CA. if [[ $BUYPASS -eq 1 ]]; then @@ -89,7 +106,7 @@ echo "${ECHO_PREFIX} Reload command? For example: nginx -s reload" read RELOADCMD echo "${ECHO_PREFIX} Requesting certificate using the chosen methods:" -eval "${ACME} ${DOMAIN_PARAMS} ${ACME_PARAMS} --issue" +eval "${ACME} ${ACME_PARAMS} --issue" SSL_PATH="$BASE/$FOLDERNAME" if [[ "$?" == "0" ]]; then