-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathentrypoint.sh
executable file
·58 lines (49 loc) · 1.94 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# generate a object in the format npm build does with the environment variables
get_react_environment_vars() {
ALL_ENV=$(env | sed -e 's/=.*//g')
NEW_OBJ='Object({NODE_ENV:"production"';
for var in $ALL_ENV
do
# we just want environment variables related to react
if [[ $var == 'NODE_ENV' || $var == 'PUBLIC_URL' || $var == REACT_APP* ]]
then
if [[ NEW_OBJ != 'Object({NODE_ENV:"production"' ]]
then
NEW_OBJ+=','
fi
NEW_OBJ+="$var:\"`printenv $var`\""
fi
done
# NEW_OBJ+='})';
}
get_react_environment_vars
# escape / cause it messes up replace
NEW_OBJ=${NEW_OBJ//"/"/"\/"}
MAIN_JS=$(find /usr/share/nginx/html/static/js/main.*js)
# check if there is an original file and start from that as replace assumes to find the original form of environment variables
ORG_MAIN_JS=$(find /usr/share/nginx/html/static/js/main.*js.original)
if [[ ! -z $ORG_MAIN_JS ]]
then
echo "Getting the original js file"
cp "$MAIN_JS".original "$MAIN_JS"
fi
# make a copy of the mainjs so we can always go back to original
cp "$MAIN_JS" "$MAIN_JS".original
OLD_OBJ="Object({NODE_ENV:\"production\",PUBLIC_URL:\"\""
sed -i -e "s/$OLD_OBJ/$NEW_OBJ/g" "$MAIN_JS"
echo "Replaced main.js file environment $OLD_OBJ with $NEW_OBJ"
MAIN_JS=$(find /usr/share/nginx/html/static/js/2.*js)
# check if there is an original file and start from that as replace assumes to find the original form of environment variables
ORG_MAIN_JS=$(find /usr/share/nginx/html/static/js/2.*js.original)
if [[ ! -z $ORG_MAIN_JS ]]
then
echo "Getting the original js file"
cp "$MAIN_JS".original "$MAIN_JS"
fi
# make a copy of the mainjs so we can always go back to original
cp "$MAIN_JS" "$MAIN_JS".original
OLD_OBJ="Object({NODE_ENV:\"production\",PUBLIC_URL:\"\""
sed -i -e "s/$OLD_OBJ/$NEW_OBJ/g" "$MAIN_JS"
echo "Replaced 2.js file environment $OLD_OBJ with $NEW_OBJ"
exec "$@"