#!/bin/bash
set -u

source "$(dirname "$0")"/custom/paths.sh

PATH="${PATH}":/usr/lib/lwr/setman
if [ ! -f "${HTTP_CFG_FILE}" ]; then
    setman-log error "Dynamic config was not found!"
    exit 1
fi

jq -e '
  (.http | type == "object" and has("authenticationEnabled")) and
  (.https | type == "object" and has("authenticationEnabled"))
' "${HTTP_CFG_FILE}" > /dev/null

if [ $? -ne 0 ]; then
    setman-log error "Dynamic config is not valid!"
    exit 1
fi

/usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf
