forked from energywebfoundation/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.sh
executable file
·46 lines (37 loc) · 900 Bytes
/
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
#!/bin/bash
REQUIRED_VARIABLES=(
MODE
WEB3
BACKEND_URL
BACKEND_PORT
BLOCKCHAIN_EXPLORER_URL
REGISTRATION_MESSAGE_TO_SIGN
)
# Recreate config file
rm -rf ./env-config.js
touch ./env-config.js
# Add assignment
echo "{" >> ./env-config.js
envToRead=.env
rootEnvFile=../../.env
if [ ! -e "$envToRead" ]; then
envToRead=$rootEnvFile
fi
pos=$(( ${#REQUIRED_VARIABLES[*]} - 1 ))
last=${REQUIRED_VARIABLES[$pos]}
for i in "${REQUIRED_VARIABLES[@]}"
do
varname="$i"
value=$(printf '%s\n' "${!varname}")
if [ -z "$value" ]; then
if test -f $rootEnvFile; then
value=$(grep -e '^'$varname'=.*' $rootEnvFile | cut -d '=' -f2 | xargs)
fi
fi
if [[ $i == $last ]]; then
echo " \"$varname\": \"$value\"" >> ./env-config.js
else
echo " \"$varname\": \"$value\"," >> ./env-config.js
fi
done
echo "}" >> ./env-config.js