#!/usr/bin/env bash # Install and enable the radar headless daemon (systemd system service), plus a # passwordless sudoers rule that lets the service user stop/start it (start.sh # stops the daemon before launching the interactive GUI). # # Run once as root, from anywhere inside the project: # sudo bash deploy/install-daemon.sh # # Re-running is safe: it overwrites the unit/sudoers with current paths. set -euo pipefail if [[ "${EUID}" -ne 0 ]]; then echo "Must run as root: sudo bash $0" >&2 exit 1 fi PROJECT_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" SERVICE_USER="${SUDO_USER:-root}" START_SH="${PROJECT_ROOT}/start.sh" SERVICE_NAME="radar.service" UNIT_PATH="/etc/systemd/system/${SERVICE_NAME}" SUDOERS_PATH="/etc/sudoers.d/radar" SYSTEMCTL="$(command -v systemctl)" if [[ -z "${SYSTEMCTL}" ]]; then echo "systemctl not found; this installer requires systemd." >&2 exit 1 fi if [[ ! -x "${START_SH}" ]]; then echo "start.sh not found or not executable: ${START_SH}" >&2 exit 1 fi if [[ "${SERVICE_USER}" == "root" ]]; then echo "Run via sudo from your normal login user (got SUDO_USER=root)." >&2 echo "Example: sudo bash deploy/install-daemon.sh" >&2 exit 1 fi echo "[install] project_root = ${PROJECT_ROOT}" echo "[install] service_user = ${SERVICE_USER}" # --- systemd unit ----------------------------------------------------------- # No network-online dependency: the appliance runs offline and the radar is on # USB/loopback. Restart=on-failure self-heals crashes but leaves an intentional # `systemctl stop` (done by start.sh for GUI handover) deactivated. cat > "${UNIT_PATH}" < "${TMP_SUDO}" <