#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DIST_DIR="${ROOT_DIR}/dist"
HOST="${HOST:-127.0.0.1}"
PORT="${PORT:-8080}"

if [[ ! -f "${DIST_DIR}/repo/addons.xml" ]]; then
  echo "Missing ${DIST_DIR}/repo/addons.xml" >&2
  echo "Run ./scripts/build_local_kodi_repo.sh first." >&2
  exit 1
fi

echo "Serving local Kodi repo from ${DIST_DIR}"
echo "Repository URL: http://${HOST}:${PORT}/repo/addons.xml"
(cd "${DIST_DIR}" && python3 -m http.server "${PORT}" --bind "${HOST}")
