-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.sh
executable file
·56 lines (46 loc) · 1.75 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
#!/bin/bash
# Author: Jan Lauber
# Description: This script is used to copy the environment variables to the .env file in the docker container and then run the nginx webserver.
#
# Environment variables:
# - REACT_APP_API_ADDRESS: The IP address with port of the log4j-collector api e.g. -> 10.0.0.10:8080.
# Recreate config file
rm -rf ./env-config.js
touch ./env-config.js
# Add assignment
echo "window._env_ = {" >> ./env-config.js
# Read each line in .env file
# Each line represents key=value pairs
# Check if .env file exists
if [ -f .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.js
done < .env
fi
if [ -z "$REACT_APP_CLIENT_ID" ]; then
echo " REACT_APP_CLIENT_ID: \"<token>\"," >> ./env-config.js
else
echo " REACT_APP_CLIENT_ID: \"$REACT_APP_CLIENT_ID\"," >> ./env-config.js
fi
if [ -z "$REACT_APP_REDIRECT_URI" ]; then
echo " REACT_APP_REDIRECT_URI: \"http://localhost:8080\"," >> ./env-config.js
else
echo " REACT_APP_REDIRECT_URI: \"$REACT_APP_REDIRECT_URI\"," >> ./env-config.js
fi
if [ -z "$REACT_APP_API_OAUTH_URI" ]; then
echo " REACT_APP_API_OAUTH_URI: \"http://localhost:8080\"," >> ./env-config.js
else
echo " REACT_APP_API_OAUTH_URI: \"$REACT_APP_API_OAUTH_URI\"," >> ./env-config.js
fi
echo "}" >> ./env-config.js