safetwitch/substitute_environment_variables.sh

34 lines
1.1 KiB
Bash
Raw Normal View History

#!/bin/sh
ROOT_DIR=/app
2023-05-09 00:34:30 +00:00
# Save old variables
# Get old vars
if [ -f .env.old ]; then
export $(echo $(cat .env.old | sed 's/#.*//g'| xargs) | envsubst)
else
export VITE_BACKEND_DOMAIN_PLACEHOLDER=VITE_BACKEND_DOMAIN_PLACEHOLDER
export VITE_INSTANCE_DOMAIN_PLACEHOLDER=VITE_INSTANCE_DOMAIN_PLACEHOLDER
export VITE_HTTPS_PLACEHOLDER=VITE_HTTPS_PLACEHOLDER
fi
echo $VITE_BACKEND_DOMAIN_PLACEHOLDER
# Replace env vars in files served by NGINX
for file in $ROOT_DIR/assets/*.js $ROOT_DIR/index.html;
do
2023-05-09 00:34:30 +00:00
sed -i 's|'${VITE_BACKEND_DOMAIN_PLACEHOLDER}'|'${VITE_BACKEND_DOMAIN}'|g' $file
sed -i 's|'${VITE_INSTANCE_DOMAIN_PLACEHOLDER}'|'${VITE_INSTANCE_DOMAIN}'|g' $file
sed -i 's|'${VITE_HTTPS_PLACEHOLDER}'|'${VITE_HTTPS}'|g' $file
# Your other variables here...
done
2023-05-09 00:34:30 +00:00
echo ${VITE_BACKEND_DOMAIN_PLACEHOLDER}
# Save old variables
2023-05-10 14:12:04 +00:00
echo -e "VITE_BACKEND_DOMAIN_PLACEHOLDER=${VITE_BACKEND_DOMAIN}" > .env.old
echo -e "VITE_INSTANCE_DOMAIN_PLACEHOLDER=${VITE_INSTANCE_DOMAIN}" >> .env.old
echo -e "VITE_HTTPS_PLACEHOLDER=${VITE_HTTPS}" >> .env.old
2023-05-09 00:34:30 +00:00
# Starting NGINX
nginx -g 'daemon off;'