#!/usr/bin/with-contenv bash

# if the OpenVPN folder still exists then wait 10 sec before booting tvheadend
if [[ -d "/etc/services.d/openvp" ]]; then
    echo "[tvheadend] Waiting 15s for OpenVPN to boot before starting tvheadend" | ts '%Y-%m-%d %H:%M:%S' && sleep 15;
    echo "[tvheadend] Public IP: $(curl -s ifconfig.me)" | ts '%Y-%m-%d %H:%M:%S'
fi

IFS=" " read -r -a RUN_ARRAY <<< "$RUN_OPTS"

exec \
        s6-setuidgid abc /usr/bin/tvheadend -C -c /config "${RUN_ARRAY[@]}"
