#!/usr/bin/with-contenv bash
# shellcheck shell=bash

umask ${UMASK}

if [ -f /app/config/config.json ]; then
    AB_PORT=$(jq '.program.webui_port' /app/config/config.json)
elif [ -f /app/config/config_dev.json ]; then
    AB_PORT=$(jq '.program.webui_port' /app/config/config_dev.json)
else
    AB_PORT=7892
fi

exec \
    s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${AB_PORT}" \
    cd /app s6-setuidgid ab python3 main.py