# Installing poorBird on the thin client Written for: whoever sets up the server host — assumes comfort with systemd and `psql`, but not with this project. Target is an x86 Linux box on the same LAN as the camera (SPEC §0). Native packages and systemd units, no containers. Commands below assume Debian or Ubuntu; adjust the package manager otherwise. --- ## 1. Packages and user ```bash sudo apt update sudo apt install -y postgresql python3-venv python3-pip git caddy sudo useradd --system --home-dir /opt/poorbird --shell /usr/sbin/nologin poorbird sudo mkdir -p /opt/poorbird /etc/poorbird /srv/poorbird/{images,thumbs,web} /var/lib/poorbird sudo chown -R poorbird:poorbird /srv/poorbird /var/lib/poorbird /opt/poorbird ``` `images/` and `thumbs/` must stay siblings under `/srv/poorbird`: that is the directory the Caddyfile's `file_server` serves, and the auth-checked image handoff needs both sides to agree on it. `poorbird check` verifies the layout, because getting it wrong produces 404s from Caddy and nothing in the app's log. `web/` is where the built UI goes (step 7). ## 2. Database Loopback TCP with `scram-sha-256`, deliberately not a Unix socket — see `TODO.md` Phase 1.2. ```bash sudo -u postgres psql <<'SQL' CREATE ROLE poorbird LOGIN PASSWORD 'PUT_A_REAL_PASSWORD_HERE'; CREATE DATABASE poorbird OWNER poorbird; SQL ``` Confirm `pg_hba.conf` has a `host all all 127.0.0.1/32 scram-sha-256` line before any `trust` line, then `sudo systemctl reload postgresql`. Verify the path the app will actually use, not the socket: ```bash psql "postgresql://poorbird:PUT_A_REAL_PASSWORD_HERE@127.0.0.1:5432/poorbird" -c 'SELECT 1' ``` ## 3. Application ```bash sudo -u poorbird git clone /opt/poorbird/src sudo ln -sfn /opt/poorbird/src/server /opt/poorbird/app sudo -u poorbird python3 -m venv /opt/poorbird/venv sudo -u poorbird /opt/poorbird/venv/bin/pip install -e /opt/poorbird/app ``` ## 4. Configuration ```bash sudo cp /opt/poorbird/app/deploy/poorbird.env.example /etc/poorbird/poorbird.env sudo chown root:poorbird /etc/poorbird/poorbird.env sudo chmod 0640 /etc/poorbird/poorbird.env sudo -e /etc/poorbird/poorbird.env # set the DB password and the enroll secret ``` Generate the enroll secret with `openssl rand -hex 32`. > **Before you ever rotate `POORBIRD_ENROLL_SECRET`:** it is compiled into the > firmware image as the last-resort recovery path for a camera that cannot be > reached over USB once mounted. Rotating it here without also shipping new > firmware removes that escape hatch (`firmware/API.md`). Check the machine before starting anything: ```bash sudo -u poorbird env $(sudo cat /etc/poorbird/poorbird.env | grep -v '^#' | xargs) \ /opt/poorbird/venv/bin/poorbird check ``` ## 5. Services ```bash sudo cp /opt/poorbird/app/deploy/poorbird-*.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable --now poorbird-api poorbird-worker systemctl status poorbird-api poorbird-worker journalctl -u poorbird-api -f ``` The API unit runs `poorbird migrate` in `ExecStartPre`. The worker unit deliberately does not, so two units never race to apply the same revision. Smoke test: ```bash curl -s localhost:8090/api/v1/health | python3 -m json.tool ``` ## 6. Reverse proxy ```bash sudo cp /opt/poorbird/app/deploy/Caddyfile /etc/caddy/Caddyfile sudo -e /etc/caddy/Caddyfile # set your hostname and DNS provider sudo systemctl reload caddy ``` Ports, so nothing collides: | Port | Who | |---|---| | `127.0.0.1:8090` | uvicorn — never exposed | | `:8080` | plain HTTP for the camera (SPEC C2) | | `:443` | TLS for humans | DNS-01 needs a Caddy build with your provider's plugin: `caddy add-package github.com/caddy-dns/cloudflare`. For a first test, replace the human-facing site block with `http://:8081` and drop the `tls` block. > **If you do that, you cannot sign in until you also set > `POORBIRD_SESSION_COOKIE_SECURE=false`.** The session cookie is `Secure` by > default, and a browser silently discards a `Secure` cookie over plain HTTP: > the login returns 200, and you are never signed in, with nothing in any log > to explain it. Set it back to `true` the moment TLS is on. ## 7. The WebUI The UI is built on your dev machine and copied here as static files. Nothing in `web/` runs on the server (SPEC §6) — Caddy serves it, and there is no Node on this host. On the dev machine: ```bash cd web npm ci npm run build # typechecks, then writes dist/ ``` Then copy it over, and let Caddy read it: ```bash rsync -a --delete dist/ youruser@poorbird-host:/tmp/poorbird-web/ # on the host: sudo rsync -a --delete /tmp/poorbird-web/ /srv/poorbird/web/ sudo chown -R poorbird:poorbird /srv/poorbird/web ``` `--delete` matters on an upgrade: Vite writes content-hashed filenames, so without it every old bundle stays behind forever. Re-run this after any UI change. There is no build step on the server, so `git pull` alone never updates the UI. ## 8. Your first account **There is no sign-up page, and a fresh install has no accounts** — so without this step the login screen has nothing you can type into it. ```bash sudo -u poorbird env $(sudo cat /etc/poorbird/poorbird.env | grep -v '^#' | xargs) \ /opt/poorbird/venv/bin/poorbird user add yourname --role admin ``` It prompts for the password, then prints an `otpauth://` URI once. **Scan it into your authenticator app before pressing on** — it is not shown again, and TOTP is required on every login for an account that has a secret. `--no-totp` skips the second factor and warns that it is doing so. There is currently no command to add or remove TOTP later, and none to delete a user, so this choice sticks for that account. Roles are `viewer`, `editor` and `admin` (SPEC §3.1); Devices and System need `admin`. Devices are not users and never appear here. ## 9. Network Give the server a **DHCP reservation or a static IP, then hardcode that address in the firmware** — simpler and more reliable than mDNS (SPEC §9). The camera has no way to be told a new address once it is mounted and cannot reach the endpoint. --- ## Upgrading ```bash sudo -u poorbird git -C /opt/poorbird/src pull sudo -u poorbird /opt/poorbird/venv/bin/pip install -e /opt/poorbird/app sudo systemctl restart poorbird-api poorbird-worker ``` `ExecStartPre` applies migrations on restart. **The UI is not part of that.** It is built on the dev machine, so a `git pull` here leaves the old bundle in `/srv/poorbird/web` and you get a new API with an old gallery. Repeat step 7 whenever `web/` changed. > Restarting mid-OTA-rollout matters: a device on a trial image marks that > image valid **only after a heartbeat the endpoint accepted**. Returning 5xx > to a trial device rolls it back — correct behaviour, but know it before you > restart the API during a rollout (`firmware/API.md`). ## Backups Not built yet — TODO Phase 5, and blocked on open question 9 (whether the NAS offers SFTP, or only SMB/NFS), which decides between restic and a mounted path. Until then **this machine is not backed up.** Do not let real captures accumulate here before that is done.