Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lego.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ set -e -f -u

# Env configuration
#
# DOMAIN_NAME Main domain name we're obtaining a wildcard certificate for.
# DOMAIN_NAME Main domain name(s) we're obtaining a wildcard certificate for. Can be either a single domain name
# or a comma separated list. For a comma separated list, do not include spaces between values and
# only use the base (no wildcard) domain, ie: "dns.example.com,dns.differentexample.com"
#
# DNS_PROVIDER DNS provider lego uses to prove that you're in control of
# the domain. The current version supports "godaddy" and "cloudflare".
# EMAIL Your email address.
Expand Down Expand Up @@ -312,8 +315,8 @@ run_lego_duckdns() {
}

run_lego() {
domainName="${DOMAIN_NAME}"
wildcardDomainName="*.${DOMAIN_NAME}"
domainName="${DOMAIN_STRING}"
wildcardDomainName="${WILDCARD_STRING}"
email="${EMAIL}"

case ${DNS_PROVIDER} in
Expand Down Expand Up @@ -345,7 +348,7 @@ get_abs_filename() {
}

copy_certificate() {
certFileName="${DOMAIN_NAME}"
certFileName="${DOMAIN_ARRAY[0]}"
cp -f "./.lego/certificates/_.${certFileName}.key" "./${certFileName}.key"
cp -f "./.lego/certificates/_.${certFileName}.crt" "./${certFileName}.crt"

Expand All @@ -354,6 +357,15 @@ copy_certificate() {
log "$(get_abs_filename ${certFileName}.key)"
}

parse_domain_names() {
IFS="," read -ra DOMAIN_ARRAY <<< "$DOMAIN_NAME"
WILDCARD_ARRAY=( "${DOMAIN_ARRAY[@]/#/*.}" )
printf -v DOMAIN_STRING '%s,' "${DOMAIN_ARRAY[@]}"
printf -v WILDCARD_STRING '%s,' "${WILDCARD_ARRAY[@]}"
DOMAIN_STRING="${DOMAIN_STRING%,}"
WILDCARD_STRING="${WILDCARD_STRING%,}"
}

# Entrypoint

# Set default values of configuration variables.
Expand All @@ -370,6 +382,8 @@ set_os

set_cpu

parse_domain_names

download_lego

run_lego
Expand Down