#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -euo pipefail

# ==============================================================================
# Home Assistant Add-on: NetBird Server
# Runs the NetBird Dashboard
# ==============================================================================

ENV_FILE="/config/netbird/dashboard/env"
if [[ -f "$ENV_FILE" ]]; then
  set -a
  # shellcheck disable=SC1090
  . "$ENV_FILE"
  set +a
else
  bashio::log.error "Missing dashboard env file at ${ENV_FILE}."
  bashio::exit.nok
fi

bashio::log.info "Preparing NetBird Dashboard assets..."
/usr/local/bin/init_react_envs.sh

bashio::log.info "Starting NetBird Dashboard..."
exec nginx -g "daemon off;"
