2022-06-13 14:39:17 +00:00
|
|
|
#!/bin/bash
|
2023-03-23 09:50:23 +00:00
|
|
|
set -e
|
2022-06-13 14:39:17 +00:00
|
|
|
|
|
|
|
# Recreate config file
|
2023-03-23 09:50:23 +00:00
|
|
|
env_file=/usr/share/nginx/html/assets/env-config.js
|
|
|
|
mkdir -p $(dirname $env_file)
|
|
|
|
rm -rf $env_file || echo "no file to delete"
|
|
|
|
touch $env_file
|
2022-06-13 14:39:17 +00:00
|
|
|
|
|
|
|
# Add assignment
|
2023-03-23 09:50:23 +00:00
|
|
|
echo "window._env_ = {" >> $env_file
|
2022-06-13 14:39:17 +00:00
|
|
|
|
|
|
|
# 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 if non-empty
|
|
|
|
if [ ! -z "$varname" ]; then
|
2023-03-23 09:50:23 +00:00
|
|
|
echo " $varname: \"$value\"," >> $env_file
|
2022-06-13 14:39:17 +00:00
|
|
|
fi
|
2023-03-23 09:50:23 +00:00
|
|
|
done < /usr/share/nginx/html/.env
|
2022-06-13 14:39:17 +00:00
|
|
|
|
2023-03-23 09:50:23 +00:00
|
|
|
echo "}" >> $env_file
|
|
|
|
|
|
|
|
# start serving
|
|
|
|
nginx -g 'daemon off;'
|