forked from open-hand/choerodon-front-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.sh
executable file
·66 lines (53 loc) · 2.08 KB
/
env.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
#!/bin/bash
set -x
set -e
# Recreate config file
absolute_path=$(cd `dirname $0`; pwd)
env_config=${absolute_path}/env-config.js
rm -rf ${env_config}
touch ${env_config}
# Add assignment
echo "window._env_ = {" >> ${env_config}
# Read each line in .env file
# Each line represents key=value pairs
while read -r line || [[ -n "$line" ]];
do
# Split env variables by character `=`
if printf '%s\n' "$line" | grep -q -e '='; then
varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
fi
# Read value of current variable if exists as Environment variable
value=$(printf '%s\n' "${!varname}")
# Otherwise use value from .env file
[[ -z $value ]] && value=${varvalue}
# Append configuration property to JS file
echo " $varname: \"$value\"," >> ${env_config}
done < ${absolute_path}/.env
if [ -f "${absolute_path}/.default.env" ]; then
while read -r line || [[ -n "$line" ]];
do
# Split env variables by character `=`
if printf '%s\n' "$line" | grep -q -e '='; then
varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
fi
# Read value of current variable if exists as Environment variable
value=$(printf '%s\n' "${!varname}")
# Otherwise use value from .env file
[[ -z $value ]] && value=${varvalue}
# Append configuration property to JS file
echo " $varname: \"$value\"," >> ${env_config}
done < ${absolute_path}/.default.env
fi
echo "}" >> ${env_config}
sed -e "s/\//\\\/g" ${env_config}
LINE=`echo $(cat ${env_config}) | sed 's#\/#\\\/#g'`
mv ${absolute_path}/index.html ${absolute_path}/index.html.bak
sed -e "s/window\.\_env\_.*\}\;/${LINE}/g" ${absolute_path}/index.html.bak > ${absolute_path}/index.html
if [ -a ${absolute_path}/registerOrganization.html ]; then
mv ${absolute_path}/registerOrganization.html ${absolute_path}/registerOrganization.html.bak
sed -e "s/window\.\_env\_.*\}\;/${LINE}/g" ${absolute_path}/registerOrganization.html.bak > ${absolute_path}/registerOrganization.html
fi
cat ${env_config}
exec "$@"