#!/bin/bash
# Launch local documentation via a Python HTTP server

DOC_DIR="/usr/share/epc670-tofhat-utils/html"
PORT=8670
PID_FILE="/tmp/epc670-docs-server.pid"

# Start the server only if it is not already running
if [ -f "${PID_FILE}" ] && kill -0 "$(cat "${PID_FILE}")" 2>/dev/null; then
    : # Server already running – reuse it
else
    python3 -m http.server "${PORT}" --directory "${DOC_DIR}" \
        >/dev/null 2>&1 &
    echo $! > "${PID_FILE}"
    sleep 0.5
fi

xdg-open "http://localhost:${PORT}"
