Add per-domain DNS/webroot handling

This commit is contained in:
Alex Thomassen 2022-12-27 21:25:52 +01:00
parent 792de2f8a5
commit 70ee986d93
Signed by: Alex
GPG Key ID: 10BD786B5F6FF5DE
1 changed files with 32 additions and 15 deletions

View File

@ -48,6 +48,7 @@ OIFS=$IFS
IFS=' ' IFS=' '
echo "${ECHO_PREFIX} Space-separated list of domains to generate a certificate for?" 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 read DOMAIN_LIST
DOMAINS=($DOMAIN_LIST) DOMAINS=($DOMAIN_LIST)
@ -56,25 +57,41 @@ DOMAIN_PARAMS=""
ACME_PARAMS="" ACME_PARAMS=""
for (( i = 0; i < ${#DOMAINS[@]}; i++ )); do 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 done
echo "${ECHO_PREFIX} DNS? [y/N]" # DNS handler is now specified as part of the domain list.
read IS_DNS # echo "${ECHO_PREFIX} DNS? [y/N]"
# read IS_DNS
IS_DNS=${IS_DNS,,} # IS_DNS=${IS_DNS,,}
if [[ $IS_DNS == *"y"* ]]; then # if [[ $IS_DNS == *"y"* ]]; then
echo "${ECHO_PREFIX} DNS provider? For example: Cloudflare = dns_cf." # 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" # 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 # read DNS_PROVIDER
ACME_PARAMS+="--dns ${DNS_PROVIDER}" # ACME_PARAMS+="--dns ${DNS_PROVIDER}"
else # else
echo "${ECHO_PREFIX} Webroot? For example: /var/www/html" # echo "${ECHO_PREFIX} Webroot? For example: /var/www/html"
read WEBROOT_DIR # read WEBROOT_DIR
ACME_PARAMS+="-w ${WEBROOT_DIR}" # ACME_PARAMS+="-w ${WEBROOT_DIR}"
fi # fi
# Make sure we point to the right CA. # Make sure we point to the right CA.
if [[ $BUYPASS -eq 1 ]]; then if [[ $BUYPASS -eq 1 ]]; then
@ -89,7 +106,7 @@ echo "${ECHO_PREFIX} Reload command? For example: nginx -s reload"
read RELOADCMD read RELOADCMD
echo "${ECHO_PREFIX} Requesting certificate using the chosen methods:" 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" SSL_PATH="$BASE/$FOLDERNAME"
if [[ "$?" == "0" ]]; then if [[ "$?" == "0" ]]; then