Refactor issue certs

This commit is contained in:
2020-08-02 00:38:56 -04:00
parent 7348048ddd
commit b8c904bbf3

View File

@@ -5,7 +5,6 @@
# See README.md for more details # See README.md for more details
# #
# Copyright 2020 Bryan Roessler <bryanroessler@gmail.com> # Copyright 2020 Bryan Roessler <bryanroessler@gmail.com>
#
unset SITES_DIR USEREMAIL DOMAIN_FILES DOMAIN_GROUPS DEPLOY_CMD_PREFIX ISSUE_CMD_PREFIX DEBUG GROUP unset SITES_DIR USEREMAIL DOMAIN_FILES DOMAIN_GROUPS DEPLOY_CMD_PREFIX ISSUE_CMD_PREFIX DEBUG GROUP
@@ -156,49 +155,49 @@ load_domains() {
issue_and_deploy_certs() { issue_and_deploy_certs() {
local domain_root domain domain_group local group_root domain_root domain domain_group
local -a issue_cmd=()
local -a deploy_cmd=()
if [[ -v GROUP ]]; then
for domain_group in "${DOMAIN_GROUPS[@]}"; do for domain_group in "${DOMAIN_GROUPS[@]}"; do
unset i local -a issue_cmd=("${ISSUE_CMD_PREFIX[@]}")
local -a deploy_cmd=("${DEPLOY_CMD_PREFIX[@]}")
local i="set"
# Issue certificates
for domain in $domain_group; do # we want to split on whitespace for domain in $domain_group; do # we want to split on whitespace
[[ "$domain" == "" ]] && continue [[ "$domain" == "" ]] && continue
# Get the webroot from the first domain if [[ -v GROUP ]]; then
if [[ ! -v i ]]; then if [[ "$METHOD" == "webroot" && -v i ]]; then
local i="set" group_root=$(get_webroot "$domain")
domain_root=$(get_webroot "$domain") issue_cmd+=("-w" "$group_root")
issue_cmd=("${ISSUE_CMD_PREFIX[@]}" "-w" "$domain_root") unset i
fi fi
# Append domains to issue command that we will call after the loop
issue_cmd+=("-d" "$domain" "-d" "www.$domain") issue_cmd+=("-d" "$domain" "-d" "www.$domain")
done # Issue certificate for single domain
# Issue certificate for entire domain group
echo "Running:" "${issue_cmd[@]}"
if ! "${issue_cmd[@]}"; then
echo "Failed to issue certificate"
fi
# Deploy certificates one by one
for domain in $domain_group; do
deploy_cmd=("${DEPLOY_CMD_PREFIX[@]}" "-w" "$domain_root" "-d" "$domain")
echo "Running:" "${deploy_cmd[@]}"
"${deploy_cmd[@]}"
done
done
else else
for domain_group in "${DOMAIN_GROUPS[@]}"; do local -a issue_cmd=("${ISSUE_CMD_PREFIX[@]}")
# Issue and deploy certificates one by one domain_root=$(get_webroot "$domain")
for domain in $domain_group; do # we want to split on whitespace issue_cmd+=("-d" "$domain" "-d" "www.$domain")
issue_cmd=("${ISSUE_CMD_PREFIX[@]}" "-d" "$domain" "-d" "www.$domain") [[ "$METHOD" == "webroot" ]] && issue_cmd+=("-w" "$domain_root")
[[ "$METHOD" == "webroot" ]] && domain_root=$(get_webroot "$domain") && issue_cmd=("${issue_cmd[@]}" "-w" "$domain_root")
deploy_cmd=("${DEPLOY_CMD_PREFIX[@]}" "-d" "$domain") # I think we only need to deploy to the domain, not subdomains
[[ "$METHOD" == "webroot" ]] && deploy_cmd=("${deploy_cmd[@]}" "-w" "$domain_root")
echo "Running:" "${issue_cmd[@]}" echo "Running:" "${issue_cmd[@]}"
if ! "${issue_cmd[@]}"; then if ! "${issue_cmd[@]}"; then
echo "Failed to issue certificate for $domain" echo "Failed to issue certificate for domain: $domain"
err=1 err=1
fi fi
fi
done
# Issue certificate for group of domains
if [[ -v GROUP ]]; then
echo "Running:" "${issue_cmd[@]}"
if ! "${issue_cmd[@]}"; then
echo "Failed to issue certificate for domain group: $domain_group"
err=1
fi
fi
# Deploy certificates one domain at a time
for domain in $domain_group; do
deploy_cmd=("${DEPLOY_CMD_PREFIX[@]}" "-d" "$domain") # I think we only need to deploy to the domain, not subdomains (e.g. www.)
echo "Running:" "${deploy_cmd[@]}" echo "Running:" "${deploy_cmd[@]}"
if ! "${deploy_cmd[@]}"; then if ! "${deploy_cmd[@]}"; then
echo "Failed to deploy certificate for $domain" echo "Failed to deploy certificate for $domain"
@@ -206,7 +205,6 @@ issue_and_deploy_certs() {
fi fi
done done
done done
fi
} }