From 65a42f61e9573677f819f05f065275eef716e662 Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Fri, 10 Jul 2020 10:21:30 +0200 Subject: [PATCH] Make 'TARGET' configurable This commit makes the TARGET of the self container redirect configurable. --- distillery/.env.sample | 6 ++++++ distillery/lib/10_config.sh | 21 +++++++++++++++++++ .../resources/templates/docker-env/self | 2 +- distillery/system_install.sh | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/distillery/.env.sample b/distillery/.env.sample index d8428ad..cff7479 100644 --- a/distillery/.env.sample +++ b/distillery/.env.sample @@ -7,11 +7,17 @@ DEPLOY_ROOT=/var/www/deploy # This setting configures the default domain-name to create subdomains of. DEFAULT_DOMAIN=localhost.kwarc.info +# By default, the default domain redirects to the distillery repository. +# If you want to change this, set an alternate domain name here. +SELF_REDIRECT= + # The system can support setting up certificate(s) automatically. # It can be enabled by setting an email for certbot certificates. # This email address can be configured here. CERTBOT_EMAIL= + + # Each Drupal instance requires a corresponding system user, database users and databases. # These are also set by the appropriate domain name. # To differentiate them from other users of the system, these names can be prefixed. diff --git a/distillery/lib/10_config.sh b/distillery/lib/10_config.sh index 55a11be..4cd02bd 100644 --- a/distillery/lib/10_config.sh +++ b/distillery/lib/10_config.sh @@ -76,6 +76,15 @@ function is_valid_email() { fi } +# 'is_valid_https_url' checks if a value is a valid url that starts with https +function is_valid_https_url() { + if [[ "$1" =~ ^https:// ]]; then + return 0; + else + return 1; + fi +} + # The 'DEPLOY_ROOT' variable must be an absolute path. if ! is_valid_abspath "$DEPLOY_ROOT"; then log_error "Variable 'DEPLOY_ROOT' is missing or not a valid path. "; @@ -150,6 +159,18 @@ if ! is_valid_number "$PASSWORD_LENGTH"; then exit 1; fi +# The 'CERTBOT_EMAIL' variable should either be empty or a valid email +if [ -n "$SELF_REDIRECT" ]; then + if ! is_valid_https_url "$SELF_REDIRECT"; then + log_error "Variable 'SELF_REDIRECT' is not a valid url. "; + log_info "It should start with https://" + log_info "Please verify that it is set correctly in '.env' or remove it completly. "; + exit 1; + fi; +else + SELF_REDIRECT="https://gitlab.cs.fau.de/AGFD/wisski-distillery" +fi + # paths to composer things DEPLOY_WEB_DIR="$DEPLOY_ROOT/core/web" DEPLOY_SELF_DIR="$DEPLOY_ROOT/core/self" diff --git a/distillery/resources/templates/docker-env/self b/distillery/resources/templates/docker-env/self index 9c188b5..69b4449 100644 --- a/distillery/resources/templates/docker-env/self +++ b/distillery/resources/templates/docker-env/self @@ -3,4 +3,4 @@ VIRTUAL_HOST=${VIRTUAL_HOST} LETSENCRYPT_HOST=${LETSENCRYPT_HOST} LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL} -TARGET=https://gitlab.cs.fau.de/AGFD/wisski-distillery \ No newline at end of file +TARGET=${TARGET} diff --git a/distillery/system_install.sh b/distillery/system_install.sh index 63a50b1..46cd020 100755 --- a/distillery/system_install.sh +++ b/distillery/system_install.sh @@ -76,6 +76,7 @@ load_template "docker-env/self" \ "VIRTUAL_HOST" "${DEFAULT_DOMAIN}" \ "LETSENCRYPT_HOST" "${LETSENCRYPT_HOST}" \ "LETSENCRYPT_EMAIL" "${LETSENCRYPT_EMAIL}" \ + "TARGET" "${SELF_REDIRECT}" \ > "$DEPLOY_SELF_DIR/.env"