Alerts Printer — Linux daemon
=============================

Headless build. Runs next to the printer and serves its settings UI over HTTP;
open that from any browser on the network to pair with Twitch and configure it.

Requirements
  Node.js 20+
  Chromium          (sudo apt install chromium-browser) — renders the receipts
  CUPS              (sudo apt install cups cups-client) — for a USB printer

Install
  sudo ./install.sh
  sudo nano /etc/alertsprinter.env      # the Twitch client id — that is all
  sudo systemctl start alertsprinter
  sudo journalctl -u alertsprinter -f   # prints the URL to open

Run without installing
  ALERTSPRINTER_TWITCH_CLIENT_ID=... ./alertsprinter

Reaching it from another machine
  Set ALERTSPRINTER_BIND=0.0.0.0. When it is not bound to loopback the UI
  requires a token, which is included in the URL logged at startup.

Updating
  The dashboard's Advanced screen has an "Update and restart" button, and the
  daemon also checks once at startup. The daemon cannot update itself — systemd
  runs it read-only and unprivileged — so it writes
  /var/lib/alertsprinter/update.request and a root oneshot does the work:

    alertsprinter-update.path      watches for that file
    alertsprinter-update.service   downloads, verifies sha256, swaps, restarts
    /usr/local/sbin/alertsprinter-update   the script itself

  If the new version does not answer /api/ping within 90 seconds the previous
  install is put back automatically. Watch it with:

    sudo journalctl -u alertsprinter-update -f

  The automatic path replaces the application only. It leaves the systemd units
  and the update script alone, because a script cannot safely overwrite itself
  while running — so a release whose notes mention a unit change needs
  `sudo ./install.sh` from the new tarball, once.

Where things live
  /opt/alertsprinter           the application
  /opt/alertsprinter.previous  the last version, kept until the new one is healthy
  /var/lib/alertsprinter       Twitch tokens and cached settings, owner-only
  /etc/alertsprinter.env       build configuration
