#!/command/with-contenv bash

set -o errexit
set -o nounset
set -o pipefail
shopt -s inherit_errexit

ROMM_LOG_TAG="nginx"
# shellcheck source=SCRIPTDIR/../../scripts/lib.sh
source /etc/s6-overlay/scripts/lib.sh

record_process_group

info_log "Starting nginx"

: "${ROMM_BASE_URL:=http://0.0.0.0:${ROMM_PORT:-8080}}"
info_log "🚀 RomM is now available at ${ROMM_BASE_URL}"

if [[ ${EUID} -ne 0 ]]; then
	exec nginx -g 'daemon off;'
fi

# if container runs as root, drop permissions
exec nginx -g 'daemon off; user romm;'
