From f6e5905ce907ec2cb18bf2f540a881b991497a50 Mon Sep 17 00:00:00 2001 From: Tim Schlagenhaufer Date: Tue, 14 Dec 2021 14:14:14 +0100 Subject: [PATCH] Optimized runtime variables script + improved maintainability and POSIX compliance Signed-off-by: Tim Schlagenhaufer --- frontend/setup-runtime.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend/setup-runtime.sh b/frontend/setup-runtime.sh index 3ee7fb199..404f8f3cf 100644 --- a/frontend/setup-runtime.sh +++ b/frontend/setup-runtime.sh @@ -5,15 +5,30 @@ # # SPDX-License-Identifier: Apache-2.0 +# Keep this shell script POSIX compliant # First argument: Path to env.js which needs to be modified # Second argument: Path to BPA jar file to replace env.js echo "Start setting runtime variables" -# Overwrite frontend runtime variables with environment variables from container -sed -i 's#__SIDEBAR_CLOSE_ON_STARTUP__#'"$SIDEBAR_CLOSE_ON_STARTUP"'#g' "$1" -sed -i 's#__SIDEBAR_HIDE_BURGER_BUTTON__#'"$SIDEBAR_HIDE_BURGER_BUTTON"'#g' "$1" +# Add new runtime variable names in this string delimited by a space character ' ' +definedVariables="SIDEBAR_CLOSE_ON_STARTUP SIDEBAR_HIDE_BURGER_BUTTON" +modifiedVariablesCounter=0 -# Overwrite env.js in given jar file (path) -jar uf "$2" "$1" +for item in $definedVariables ; do # Do not use double-quotes for $definedVariables + eval envvar=\"\$"$item"\" + if [ -n "$envvar" ]; then + echo "Runtime variable $item is set to '$envvar'" + + # Overwrite frontend runtime variables in env.js with environment variables from container + sed -i "s#__${item}__#""$envvar"'#g' "$1" + modifiedVariablesCounter=$((modifiedVariablesCounter+1)) + fi +done + +# Overwrite env.js file in given jar file (path) if at least one runtime variable is set +if [ "$modifiedVariablesCounter" -gt 0 ]; then + echo "Updating env.js file in jar" + jar uf "$2" "$1" +fi echo "Finish setting runtime variables"