From 066262ce9600b7052a71c502811c99013fdb3a83 Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Mon, 1 Nov 2021 14:57:37 +0100 Subject: [PATCH] Add SELF_EXTRA_DOMAINS --- distillery/.env.sample | 4 ++++ distillery/lib/10_config.sh | 30 +++++++++++++++++++++++++++++- distillery/system_install.sh | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/distillery/.env.sample b/distillery/.env.sample index d1f689b..271bcc8 100644 --- a/distillery/.env.sample +++ b/distillery/.env.sample @@ -11,6 +11,10 @@ DEFAULT_DOMAIN=localhost.kwarc.info # If you want to change this, set an alternate domain name here. SELF_REDIRECT= +# By default, only the 'self' domain above is caught. +# To catch additional domains, add them here (comma seperated) +SELF_EXTRA_DOMAINS= + # You can override individual URLS in the homepage. # Do this by adding URLs (without trailing '/'s) into a JSON file SELF_OVERRIDES_FILE=/distillery/overrides.json diff --git a/distillery/lib/10_config.sh b/distillery/lib/10_config.sh index b7fe39b..08b2d92 100644 --- a/distillery/lib/10_config.sh +++ b/distillery/lib/10_config.sh @@ -58,6 +58,20 @@ function is_valid_domain() { fi; } +# 'is_valid_domains' is like is_valid_domain, but comma seperated. +function is_valid_domains() { + if [ -z "$1" ]; then + return 1; + fi + IFS=',' read -ra domains <<< "$1" + for domain in $domains; do + if ! is_valid_domain "$domain"; then + return 0; + fi + done + return 1; +} + # 'is_valid_number' checks if a value is a valid number. function is_valid_number() { if [[ "$1" =~ ^[1-9][0-9]*$ ]]; then @@ -152,6 +166,20 @@ if ! is_valid_domain "$DEFAULT_DOMAIN"; then exit 1; fi +# The 'SELF_EXTRA_DOMAINS' variable must be a valid domain. +if ! is_valid_domain "$SELF_EXTRA_DOMAINS"; then + log_error "Variable 'SELF_EXTRA_DOMAINS' does not contain comma-separated domains. "; + log_info "Please verify that it is set correctly in '.env'. "; + exit 1; +fi + +# set SELF_DOMAIN_SPEC to full list of domains +SELF_DOMAIN_SPEC="$DEFAULT_DOMAIN" +if [ -n "$SELF_EXTRA_DOMAINS" ]; then + SELF_DOMAIN_SPEC="$DEFAULT_DOMAIN,$SELF_EXTRA_DOMAINS" +fi + + # The 'CERTBOT_EMAIL' variable should either be empty or a valid email if [ -n "$CERTBOT_EMAIL" ]; then if ! is_valid_email "$CERTBOT_EMAIL"; then @@ -175,7 +203,7 @@ if ! is_valid_number "$MAX_BACKUP_AGE"; then exit 1; fi -# The 'CERTBOT_EMAIL' variable should either be empty or a valid email +# The 'SELF_REDIRECT' variable should either be empty or a valid redirect uri if [ -n "$SELF_REDIRECT" ]; then if ! is_valid_https_url "$SELF_REDIRECT"; then log_error "Variable 'SELF_REDIRECT' is not a valid url. "; diff --git a/distillery/system_install.sh b/distillery/system_install.sh index 42ca611..197ca8a 100755 --- a/distillery/system_install.sh +++ b/distillery/system_install.sh @@ -79,7 +79,7 @@ fi; log_info " => Writing 'self' configuration file" load_template "docker-env/self" \ - "VIRTUAL_HOST" "${DEFAULT_DOMAIN}" \ + "VIRTUAL_HOST" "${SELF_DOMAIN_SPEC}" \ "LETSENCRYPT_HOST" "${LETSENCRYPT_HOST}" \ "LETSENCRYPT_EMAIL" "${LETSENCRYPT_EMAIL}" \ "TARGET" "${SELF_REDIRECT}" \