Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #691 from bosch-io/feature/runtime-script
Browse files Browse the repository at this point in the history
Optimized runtime variables script
  • Loading branch information
schlagtim authored Dec 14, 2021
2 parents fb1bb7a + f6e5905 commit bed403a
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions frontend/setup-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit bed403a

Please sign in to comment.