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

Commit bed403a

Browse files
authored
Merge pull request #691 from bosch-io/feature/runtime-script
Optimized runtime variables script
2 parents fb1bb7a + f6e5905 commit bed403a

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

frontend/setup-runtime.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,30 @@
55
#
66
# SPDX-License-Identifier: Apache-2.0
77

8+
# Keep this shell script POSIX compliant
89
# First argument: Path to env.js which needs to be modified
910
# Second argument: Path to BPA jar file to replace env.js
1011
echo "Start setting runtime variables"
1112

12-
# Overwrite frontend runtime variables with environment variables from container
13-
sed -i 's#__SIDEBAR_CLOSE_ON_STARTUP__#'"$SIDEBAR_CLOSE_ON_STARTUP"'#g' "$1"
14-
sed -i 's#__SIDEBAR_HIDE_BURGER_BUTTON__#'"$SIDEBAR_HIDE_BURGER_BUTTON"'#g' "$1"
13+
# Add new runtime variable names in this string delimited by a space character ' '
14+
definedVariables="SIDEBAR_CLOSE_ON_STARTUP SIDEBAR_HIDE_BURGER_BUTTON"
15+
modifiedVariablesCounter=0
1516

16-
# Overwrite env.js in given jar file (path)
17-
jar uf "$2" "$1"
17+
for item in $definedVariables ; do # Do not use double-quotes for $definedVariables
18+
eval envvar=\"\$"$item"\"
19+
if [ -n "$envvar" ]; then
20+
echo "Runtime variable $item is set to '$envvar'"
21+
22+
# Overwrite frontend runtime variables in env.js with environment variables from container
23+
sed -i "s#__${item}__#""$envvar"'#g' "$1"
24+
modifiedVariablesCounter=$((modifiedVariablesCounter+1))
25+
fi
26+
done
27+
28+
# Overwrite env.js file in given jar file (path) if at least one runtime variable is set
29+
if [ "$modifiedVariablesCounter" -gt 0 ]; then
30+
echo "Updating env.js file in jar"
31+
jar uf "$2" "$1"
32+
fi
1833

1934
echo "Finish setting runtime variables"

0 commit comments

Comments
 (0)