From 0984ef2b1fca1d6695cb15f643208b48d37bb60d Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <the@jeffreyfreeman.me>
Date: Mon, 30 May 2022 17:36:13 +0300
Subject: [PATCH] Added a more descriptive error on LB_DOMAIN

---
 .../99-swarm-proxy-letsencrypt-entry.sh             | 10 ++++++++--
 swarm-proxy-letsencrypt/app/functions.sh            | 13 +++++++++----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/swarm-proxy-letsencrypt/99-swarm-proxy-letsencrypt-entry.sh b/swarm-proxy-letsencrypt/99-swarm-proxy-letsencrypt-entry.sh
index 5599395..792f59a 100755
--- a/swarm-proxy-letsencrypt/99-swarm-proxy-letsencrypt-entry.sh
+++ b/swarm-proxy-letsencrypt/99-swarm-proxy-letsencrypt-entry.sh
@@ -148,6 +148,12 @@ if [[ "${ACME_CA_URI:-}" =~ $acmev1_r ]]; then
     echo "Please use one of Let's Encrypt ACME v2 endpoints instead."
     exit 1
 fi
+
+if [[ -z "${LB_DOMAIN:-}" ]]; then
+    echo "Error: LB_DOMAIN env variable not set. Caught in entry script."
+    exit 1
+fi
+
 check_docker_socket
 check_writable_directory '/etc/nginx/certs'
 check_writable_directory '/etc/nginx/vhost.d'
@@ -182,9 +188,9 @@ cat > "/usr/share/nginx/html/.well-known/acme-challenge/active.html" << EOF
 EOF
 
 
-cat > "/etc/nginx/conf.d/lb.qoto.org-activate.conf" << EOF
+cat > "/etc/nginx/conf.d/${LB_DOMAIN}-activate.conf" << EOF
 server {
-    server_name lb.qoto.org;
+    server_name ${LB_DOMAIN};
     listen 80;
 
     include /etc/nginx/vhost.d/default*;
diff --git a/swarm-proxy-letsencrypt/app/functions.sh b/swarm-proxy-letsencrypt/app/functions.sh
index 858d753..9c519b6 100644
--- a/swarm-proxy-letsencrypt/app/functions.sh
+++ b/swarm-proxy-letsencrypt/app/functions.sh
@@ -8,15 +8,20 @@ function lc {
 DEBUG="$(lc "$DEBUG")"
 
 [[ -z "${VHOST_DIR:-}" ]] && \
- declare -r VHOST_DIR=/etc/nginx/vhost.d
+   declare -r VHOST_DIR=/etc/nginx/vhost.d
 [[ -z "${START_HEADER:-}" ]] && \
- declare -r START_HEADER='## Start of configuration add by letsencrypt container'
+   declare -r START_HEADER='## Start of configuration add by letsencrypt container'
 [[ -z "${END_HEADER:-}" ]] && \
- declare -r END_HEADER='## End of configuration add by letsencrypt container'
+   declare -r END_HEADER='## End of configuration add by letsencrypt container'
+if [[ -z "${LB_DOMAIN:-}" ]]; then
+   echo "Error: LB_DOMAIN env variable not set. Caught in functions script."
+   exit 1
+fi
+
 
 function check_nginx_proxy_container_run {
     # TODO make the load balancer address configurable.
-    if curl --head --silent --fail http://lb.qoto.org/.well-known/acme-challenge/active.html > /dev/null;
+    if curl --head --silent --fail http://${LB_DOMAIN}/.well-known/acme-challenge/active.html > /dev/null;
     then
         return 0
     else
-- 
GitLab