Skip to content

Commit d486830

Browse files
committed
misc fixes
1 parent a13301a commit d486830

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

src/scripts/run_certbot.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ info "Starting certificate renewal process"
88

99
# If we have a config file we parse it and let definitions within take
1010
# precedence over any environment variables.
11-
config_file="${NGINX_CERTBOT_CONFIG_FILE:-/etc/nginx-certbot/config.yml}"
12-
if [ -f "${config_file}" ]; then
13-
certbot_authenticator="$(shyaml get-value certbot.authenticator '' < "${config_file}")"
14-
certbot_elliptic_curve="$(shyaml get-value certbot.elliptic-curve '' < "${config_file}")"
15-
certbot_email="$(shyaml get-value certbot.email '' < "${config_file}")"
16-
certbot_key_type="$(shyaml get-value certbot.key-type '' < "${config_file}")"
17-
certbot_rsa_key_size="$(shyaml get-value certbot.rsa-key-size '' < "${config_file}")"
18-
certbot_staging="$(shyaml get-value certbot.staging '' < "${config_file}")"
19-
certbot_production_url="$(shyaml get-value certbot.production_url '' < "${config_file}")"
20-
certbot_staging_url="$(shyaml get-value certbot.staging_url '' < "${config_file}")"
11+
if [ -f "${CONFIG_FILE}" ]; then
12+
certbot_authenticator="$(shyaml get-value certbot.authenticator '' < "${CONFIG_FILE}")"
13+
certbot_elliptic_curve="$(shyaml get-value certbot.elliptic-curve '' < "${CONFIG_FILE}")"
14+
certbot_email="$(shyaml get-value certbot.email '' < "${CONFIG_FILE}")"
15+
certbot_key_type="$(shyaml get-value certbot.key-type '' < "${CONFIG_FILE}")"
16+
certbot_rsa_key_size="$(shyaml get-value certbot.rsa-key-size '' < "${CONFIG_FILE}")"
17+
certbot_staging="$(shyaml get-value certbot.staging '' < "${CONFIG_FILE}")"
18+
certbot_production_url="$(shyaml get-value certbot.production_url '' < "${CONFIG_FILE}")"
19+
certbot_staging_url="$(shyaml get-value certbot.staging_url '' < "${CONFIG_FILE}")"
2120
fi
2221

2322
# Environment variable fallbacks
@@ -135,19 +134,19 @@ get_certificate() {
135134
# If we have a config file we request certificates based on the specifications
136135
# within that file otherwise we parse the nginx config files to automatically
137136
# discover certificate names, key types, authenticators, and domains.
138-
if [ -f "${config_file}" ]; then
139-
debug "Using config file '${config_file}' for certificate specifications"
137+
if [ -f "${CONFIG_FILE}" ]; then
138+
debug "Using config file '${CONFIG_FILE}' for certificate specifications"
140139
# Loop over the certificates array and request the certificates
141140
while read -r -d '' cert; do
142141
debug "Parsing certificate specification"
143142

144-
# cert-name (required)
145-
cert_name="$(shyaml get-value cert-name '' <<<"${cert}")"
143+
# name (required)
144+
cert_name="$(shyaml get-value name '' <<<"${cert}")"
146145
if [ -z "${cert_name}" ]; then
147-
error "'cert-name' is missing; ignoring this certificate specification"
146+
error "'name' is missing; ignoring this certificate specification"
148147
continue
149148
fi
150-
debug "Certificate cert-name is: ${cert_name}"
149+
debug "Certificate name is: ${cert_name}"
151150

152151
# domains (required)
153152
domains=()
@@ -190,7 +189,7 @@ if [ -f "${config_file}" ]; then
190189
if ! get_certificate "${cert_name}" "${domain_request}" "${key_type}" "${authenticator}" "${rsa_key_size}" "${elliptic_curve}" "${credentials}"; then
191190
error "Certbot failed for '${cert_name}'. Check the logs for details."
192191
fi
193-
done < <(shyaml -y get-values-0 certificates '' < ${config_file})
192+
done < <(shyaml -y get-values-0 certificates '' < "${CONFIG_FILE}")
194193
else
195194
debug "Using automatic discovery of nginx conf file for certificate specifications"
196195
# This will return an associative array that looks something like this:

src/scripts/start_nginx_certbot.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,39 @@ trap "clean_exit" EXIT
2121
# Source "util.sh" so we can have our nice tools.
2222
. "$(cd "$(dirname "$0")"; pwd)/util.sh"
2323

24+
# Configuration file
25+
if [ -n "${NGINX_CERTBOT_CONFIG_FILE}" ] && [ ! -f "${NGINX_CERTBOT_CONFIG_FILE}" ]; then
26+
# If the variable is set but the file doesn't exist we error out since this
27+
# is most likely a user error.
28+
error "NGINX_CERTBOT_CONFIG_FILE is configured but '${NGINX_CERTBOT_CONFIG_FILE}' does not exist, exiting"
29+
exit 1
30+
fi
31+
export CONFIG_FILE="${NGINX_CERTBOT_CONFIG_FILE:-/etc/nginx-certbot/config.yml}"
32+
33+
# If the config file exist we extract configuration from it and override any corresponding environment variables:
34+
# - nginx-certbot.debug overrides DEBUG
35+
# - nginx-certbot.dhparam-size overrides DHPARAM_SIZE
36+
# - nginx-certbot.renewal-interval overrides RENEWAL_INTERVAL
37+
if [ -f "${CONFIG_FILE}" ]; then
38+
debug "Configuration file '${CONFIG_FILE}' exist."
39+
YAML_DEBUG=$(shyaml get-value nginx-certbot.debug '' < "${CONFIG_FILE}")
40+
if [ "${YAML_DEBUG}" == "True" ] || [ "${YAML_DEBUG}" == "1" ]; then
41+
export DEBUG=1
42+
elif [ "${YAML_DEBUG}" == "False" ] || [ "${YAML_DEBUG}" == "0" ]; then
43+
export DEBUG=0
44+
fi
45+
YAML_DHPARAM_SIZE=$(shyaml get-value nginx-certbot.dhparam-size '' < "${CONFIG_FILE}")
46+
if [ -n "${YAML_DHPARAM_SIZE}" ]; then
47+
export DHPARAM_SIZE=${YAML_DHPARAM_SIZE}
48+
fi
49+
YAML_RENEWAL_INTERVAL=$(shyaml get-value nginx-certbot.renewal-interval '' < "${CONFIG_FILE}")
50+
if [ -n "${YAML_RENEWAL_INTERVAL}" ]; then
51+
export RENEWAL_INTERVAL=${YAML_RENEWAL_INTERVAL}
52+
fi
53+
else
54+
debug "Configuration file '${CONFIG_FILE}' doesn't exist. Falling back to environment variables and default values."
55+
fi
56+
2457
# If the environment variable `DEBUG=1` is set, then this message is printed.
2558
debug "Debug messages are enabled"
2659

0 commit comments

Comments
 (0)