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,57 +155,56 @@ 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 local -a issue_cmd=("${ISSUE_CMD_PREFIX[@]}")
unset i local -a deploy_cmd=("${DEPLOY_CMD_PREFIX[@]}")
for domain in $domain_group; do # we want to split on whitespace local i="set"
[[ "$domain" == "" ]] && continue # Issue certificates
# Get the webroot from the first domain for domain in $domain_group; do # we want to split on whitespace
if [[ ! -v i ]]; then [[ "$domain" == "" ]] && continue
local i="set" if [[ -v GROUP ]]; then
domain_root=$(get_webroot "$domain") if [[ "$METHOD" == "webroot" && -v i ]]; then
issue_cmd=("${ISSUE_CMD_PREFIX[@]}" "-w" "$domain_root") group_root=$(get_webroot "$domain")
issue_cmd+=("-w" "$group_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
else
# Issue certificate for entire domain group local -a issue_cmd=("${ISSUE_CMD_PREFIX[@]}")
echo "Running:" "${issue_cmd[@]}" domain_root=$(get_webroot "$domain")
if ! "${issue_cmd[@]}"; then issue_cmd+=("-d" "$domain" "-d" "www.$domain")
echo "Failed to issue certificate" [[ "$METHOD" == "webroot" ]] && issue_cmd+=("-w" "$domain_root")
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
for domain_group in "${DOMAIN_GROUPS[@]}"; do
# Issue and deploy certificates one by one
for domain in $domain_group; do # we want to split on whitespace
issue_cmd=("${ISSUE_CMD_PREFIX[@]}" "-d" "$domain" "-d" "www.$domain")
[[ "$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
echo "Running:" "${deploy_cmd[@]}" fi
if ! "${deploy_cmd[@]}"; then
echo "Failed to deploy certificate for $domain"
err=1
fi
done
done done
fi
# 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[@]}"
if ! "${deploy_cmd[@]}"; then
echo "Failed to deploy certificate for $domain"
err=1
fi
done
done
} }