24 lines
648 B
Bash
24 lines
648 B
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
config=/run/secrets/homeassistant.env
|
|
if [ ! -r "$config" ]; then
|
|
echo "Home Assistant secret file is missing" >&2
|
|
exit 1
|
|
fi
|
|
set -a
|
|
. "$config"
|
|
set +a
|
|
: "${HASS_URL:?HASS_URL is required}"
|
|
: "${HASS_TOKEN:?HASS_TOKEN is required}"
|
|
|
|
upstream=${HASS_URL%/}
|
|
escaped_token=$(printf '%s' "$HASS_TOKEN" | sed 's/[&/]/\\&/g')
|
|
escaped_upstream=$(printf '%s' "$upstream" | sed 's/[&/]/\\&/g')
|
|
sed -e "s/__HASS_TOKEN__/$escaped_token/g" \
|
|
-e "s/__HASS_UPSTREAM__/$escaped_upstream/g" \
|
|
/etc/nginx/templates/homeassistant.conf.template \
|
|
> /tmp/nginx.conf
|
|
unset HASS_TOKEN
|
|
exec nginx -c /tmp/nginx.conf -g 'daemon off;'
|