From 09f1dfec0c1f10ccf9fded264f6e93003179278d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20B=C3=BChner?= Date: Wed, 7 Feb 2024 14:49:03 +0100 Subject: [PATCH] refactor: use function to avoid duplicate code --- startup.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/startup.sh b/startup.sh index 79f951b..182e9c0 100755 --- a/startup.sh +++ b/startup.sh @@ -1,6 +1,20 @@ -#!/bin/sh +#!/bin/bash echo "Welcome to GeoServer $GEOSERVER_VERSION" +# function that can be used to copy a custom config file to the catalina conf dir +function copy_custom_config() { + CONFIG_FILE=$1 + # Use a custom "${CONFIG_FILE}" if the user mounted one into the container + if [ -d "${CONFIG_OVERRIDES_DIR}" ] && [ -f "${CONFIG_OVERRIDES_DIR}/${CONFIG_FILE}" ]; then + echo "Installing configuration override for ${CONFIG_FILE} with substituted environment variables" + envsubst < "${CONFIG_OVERRIDES_DIR}"/"${CONFIG_FILE}" > "${CATALINA_HOME}/conf/${CONFIG_FILE}" + else + # Otherwise use the default + echo "Installing default ${CONFIG_FILE} with substituted environment variables" + envsubst < "${CONFIG_DIR}"/"${CONFIG_FILE}" > "${CATALINA_HOME}/conf/${CONFIG_FILE}" + fi +} + ## Skip demo data if [ "${SKIP_DEMO_DATA}" = "true" ]; then unset GEOSERVER_REQUIRE_FILE @@ -101,25 +115,11 @@ if [ "${POSTGRES_JNDI_ENABLED}" = "true" ]; then fi # Use a custom "context.xml" if the user mounted one into the container - if [ -d "${CONFIG_OVERRIDES_DIR}" ] && [ -f "${CONFIG_OVERRIDES_DIR}/context.xml" ]; then - echo "Installing configuration override for context.xml with substituted environment variables" - envsubst < "${CONFIG_OVERRIDES_DIR}"/context.xml > "${CATALINA_HOME}/conf/context.xml" - else - # Otherwise use the default - echo "Installing default context.xml with substituted environment variables" - envsubst < "${CONFIG_DIR}"/context.xml > "${CATALINA_HOME}/conf/context.xml" - fi + copy_custom_config context.xml fi # Use a custom "server.xml" if the user mounted one into the container -if [ -d "${CONFIG_OVERRIDES_DIR}" ] && [ -f "${CONFIG_OVERRIDES_DIR}/server.xml" ]; then - echo "Installing configuration override for server.xml with substituted environment variables" - envsubst < "${CONFIG_OVERRIDES_DIR}"/server.xml > "${CATALINA_HOME}/conf/server.xml" -else - # Otherwise use the default - echo "Installing default server.xml with substituted environment variables" - envsubst < "${CONFIG_DIR}"/server.xml > "${CATALINA_HOME}/conf/server.xml" -fi +copy_custom_config server.xml # start the tomcat # CIS - Tomcat Benchmark recommendations: