From 0a0c397312c25438243c073e384debe0b5629193 Mon Sep 17 00:00:00 2001
From: Quazgar <quazgar@posteo.de>
Date: Wed, 29 Apr 2020 09:15:25 +0000
Subject: [PATCH] Enhanced makefile

---
 build.properties.d/00_default.properties     |  7 +++++++
 build.properties.files/footer_element_2.html |  7 +++++++
 makefile                                     | 10 +++++++---
 3 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 build.properties.files/footer_element_2.html

diff --git a/build.properties.d/00_default.properties b/build.properties.d/00_default.properties
index 0ce20ba2..046375fa 100644
--- a/build.properties.d/00_default.properties
+++ b/build.properties.d/00_default.properties
@@ -60,7 +60,14 @@ BUILD_FOOTER_DATA_POLICY_HREF=https://indiscale.com/?page_id=156
 # Custom footer elements can be placed here (will be placed inside a <div>
 # element).
 BUILD_FOOTER_CUSTOM_ELEMENT_ONE=
+# BUILD_FOOTER_CUSTOM_ELEMENT_ONE='<p>Some content <img
+# src="/webinterface/${BUILD_NUMBER}/pics/some_image.png"/>'
+
+# Files from the `build.properties.files` directory can also be included here
+# These files will also have a second step of variable substitution with
+# ${BUILD_NUMBER}.
 BUILD_FOOTER_CUSTOM_ELEMENT_TWO=
+# BUILD_FOOTER_CUSTOM_ELEMENT_TWO=$(cat footer_element_2.html)
 BUILD_CUSTOM_IMPRINT='<p> Put an imprint note here </p>'
 
 
diff --git a/build.properties.files/footer_element_2.html b/build.properties.files/footer_element_2.html
new file mode 100644
index 00000000..f0444d42
--- /dev/null
+++ b/build.properties.files/footer_element_2.html
@@ -0,0 +1,7 @@
+<h1>Put your template content files into this directory</h1>
+
+<p>
+  Files in this directory can be substituted into the variables defined in
+  build.properties.d.  In a second step, parameter substitution takes place with
+  BUILD_NUMBER, if the word is preceded by a dollar sign: ${BUILD_NUMBER}
+</p>
diff --git a/makefile b/makefile
index 712cd2e7..d9091f32 100644
--- a/makefile
+++ b/makefile
@@ -66,16 +66,20 @@ merge_xsl:
 
 build_properties:
 	@set -a -e ; \
-	for f in $$(ls build.properties.d/) ; do source "build.properties.d/$$f" ; done ; \
+	pushd build.properties.files ; \
+	for f in ../build.properties.d/* ; do source "$$f" ; done ; \
+	popd ; \
 	BUILD_NUMBER=$(BUILD_NUMBER) ; \
 	PROPS=$$(printenv | grep -e "^BUILD_") ; \
 	echo "SET BUILD PROPERTIES:" ; \
 	for p in $$PROPS ; do echo "  $$p" ; done; \
-	VARS=$$(printenv | grep -e "^BUILD_" | sed 's/=.*$$/}/' | sed 's/^/$${/') ; \
+	VARS=$$(printenv | grep -e "^BUILD_" | grep -v "^BUILD_NUMBER=" | \
+	        sed -E 's/(BUILD_[^=]+)=.*/$${\1}/') ; \
 	for f in $$(find $(PUBLIC_DIR) -type f) ; do \
 		echo "BUILD FILE: $$f" ; \
 		mv "$$f" "$${f}.tmp" ; \
-		envsubst "$$VARS" < "$${f}.tmp" > "$$f" ; \
+		envsubst "$$VARS" < "$${f}.tmp" | \
+		  envsubst "\$${BUILD_NUMBER}" > "$$f" ; \
 		rm "$${f}.tmp" ; \
 	done
 	@echo $(BUILD_NUMBER) > $(PUBLIC_DIR)/.build_number
-- 
GitLab