-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
executable file
·76 lines (64 loc) · 2.73 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/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/templatebuilder/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/templatebuilder/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/templatebuilder/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/templatebuilder/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"
#replace html file's references
INDEX_HTML=$(find /usr/share/nginx/html/templatebuilder/index.html)
# check if there is an original file and start from that as replace assumes to find the original form of environment variables
ORG_INDEX_HTML=$(find /usr/share/nginx/html/templatebuilder/index.html)
if [[ ! -z $ORG_INDEX_HTML ]]
then
echo "Getting the original html file"
cp "$INDEX_HTML".original "$INDEX_HTML"
fi
cp "$INDEX_HTML" "$INDEX_HTML".original
sed -i -e "s/manifest.json/templatebuilder\/manifest.json/g" "$INDEX_HTML"
sed -i -e "s/favicon/templatebuilder\/favicon/g" "$INDEX_HTML"
sed -i -e "s/logo/templatebuilder\/logo/g" "$INDEX_HTML"
sed -i -e "s/static/templatebuilder\/static/g" "$INDEX_HTML"
echo "Replaced index.html"
exec "$@"