47 lines
1.3 KiB
Bash
Executable File
47 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
render_locations() {
|
|
surface="$1"
|
|
SHOP_SURFACE="$surface"
|
|
export SHOP_SURFACE BACKEND_PORT
|
|
envsubst '${SHOP_SURFACE} ${BACKEND_PORT}' \
|
|
< /etc/nginx/templates/snippets/nullcart-locations.conf.template \
|
|
> "/etc/nginx/snippets/nullcart-locations-${surface}.conf"
|
|
}
|
|
|
|
render_server() {
|
|
template_path="$1"
|
|
output_path="$2"
|
|
surface="$3"
|
|
SHOP_SURFACE="$surface"
|
|
export SHOP_SURFACE CLEARNET_DOMAIN BACKEND_PORT
|
|
|
|
if [ "$surface" = "clearnet" ]; then
|
|
if [ -n "${ONION_HOSTNAME:-}" ]; then
|
|
export ONION_LOCATION_HEADER="add_header Onion-Location \"http://${ONION_HOSTNAME}\$request_uri\";"
|
|
else
|
|
export ONION_LOCATION_HEADER=""
|
|
fi
|
|
|
|
envsubst '${CLEARNET_DOMAIN} ${BACKEND_PORT} ${SHOP_SURFACE} ${ONION_LOCATION_HEADER}' \
|
|
< "$template_path" \
|
|
> "$output_path"
|
|
|
|
return
|
|
fi
|
|
|
|
envsubst '${CLEARNET_DOMAIN} ${BACKEND_PORT} ${SHOP_SURFACE}' \
|
|
< "$template_path" \
|
|
> "$output_path"
|
|
}
|
|
|
|
mkdir -p /etc/nginx/snippets
|
|
|
|
render_locations clearnet
|
|
render_locations onion
|
|
render_server /etc/nginx/templates/conf.d/clearnet.conf.template /etc/nginx/conf.d/clearnet.conf clearnet
|
|
render_server /etc/nginx/templates/conf.d/onion.conf.template /etc/nginx/conf.d/onion.conf onion
|
|
|
|
exec nginx -g 'daemon off;'
|