# Build and install

Requires Linux with systemd for `install`. macOS can use `serve` in a terminal.
Build from `connector/` with the already-installed Bun dependencies:

```sh
bash packaging/build.sh --target linux-x64
./packaging/dist/unbound-connector-linux-x64 version
./packaging/dist/unbound-connector-linux-x64 install --user --dry-run
```

The default build targets Linux x64/arm64 and, when supported by the installed
Bun types, macOS x64/arm64. Cross builds may need Bun's target runtime download.
Native builds use the installed runtime. Outputs and `SHA256SUMS` are in
`packaging/dist/`. The checksum manifest includes only the targets from that build. Native x64 builds inherit the installed Bun's
CPU requirements; cross-built x64 uses the baseline CPU target.

Install the signed Linux x64/arm64 release from the official site:

```sh
curl -fsSL https://unboundchat.net/connector/install.sh | sh -s -- --user
```

Requires curl, OpenSSL with Ed25519 `pkeyutl -rawin` support (use 3.x),
POSIX awk, and sha256sum or shasum.
The installer verifies the Ed25519 signature on the versioned manifest **before**
reading a checksum, checks its version, then checks the binary hash and size.
It refuses unsigned, wrong-key, wrong-version or changed files. See
[SIGNING.md](../packaging/SIGNING.md) for release and key-rotation steps.
The release owner must stage, sign, upload and deploy before the URL is live.
Source stays private until the open-source launch.

To preview without downloading, writing files or starting a service:

```sh
curl -fsSL https://unboundchat.net/connector/install.sh | sh -s -- --user --dry-run
```

`--version X.Y.Z` selects an exact release signed by the installer's pinned key.
An installed connector requires `--allow-downgrade` as well to select an older
version; an unsigned latest pointer can never authorize a downgrade.
For a system service, run the reviewed script as root without `--user`. It
installs to `/usr/local/bin`. A user install uses `~/.local/bin` (add that to
PATH). The checked binary replaces the old one only after all checks pass.

`install` writes new files. Without app pairing or configured E2E routing, it
leaves the service disabled and stopped, including across login or reboot, and
prints: “Installed. Now tap Pair this device in the app.” `status` and `doctor`
report “not paired yet”. Run the app's command with `--pair CODE` to finish:
it configures hosted routing, enables the service and starts pairing. An install
with existing E2E routing starts the service normally. It preserves existing config
except that an explicit `--engine openclaw` persists the selected engine and
Gateway URL alongside the other loaded settings. On an existing installation, plain `install` and the shell installer use the
verified update transaction below and keep the existing unit and settings.
A new `--pair` code against a paired server is refused before binary replacement.
To change a unit, stop the service,
review and remove its old unit file, then run install again. User services need
an active systemd user session. To keep one running after logout, an admin can
run `loginctl enable-linger <user>`.

| Mode | Config | Data | Unit |
| --- | --- | --- | --- |
| User (default) | `~/.config/unbound-connector/config.json` | `~/.local/share/unbound-connector` | `~/.config/systemd/user/unbound-connector.service` |
| System (`--system`) | `/etc/unbound-connector/config.json` | `/var/lib/unbound-connector` | `/etc/systemd/system/unbound-connector.service` |

System installs create the `unbound-connector` account without a login shell.
The service gets a read-only filesystem and home, a private temp directory,
no privilege gain, and write access only to its data directory.


## Hermes or OpenClaw with the app's command

The app's setup command stays the same:

```sh
curl -fsSL https://unboundchat.net/connector/install.sh | sh -s -- --version X.Y.Z --user --pair CODE
```

The installer detects Hermes through `hermes` on PATH, and OpenClaw through
`openclaw` on PATH or its config file. Exactly one selects that engine. If both
are found it stops and asks for `--engine hermes` or `--engine openclaw`.
If neither is found it keeps the existing Hermes install path; doctor then
explains that Hermes is missing. Explicit `--engine` overrides detection.

OpenClaw **2026.10.5** requires Node **`>=24.16 <25` or `>=26.1`**.
Check `node --version` on the Gateway host before installing or starting OpenClaw.

OpenClaw options:

- `--engine openclaw` selects an OpenClaw Gateway.
- `--openclaw-url ws://127.0.0.1:PORT` overrides the Gateway URL. Only loopback
  `127.0.0.1` and `::1` addresses are allowed, with no URL credentials, query or fragment.
- `--openclaw-token-file PATH` reads a token privately. Its contents never
  appear in command arguments, installer output or the connector config.

OpenClaw config discovery uses `OPENCLAW_CONFIG_PATH`, otherwise
`OPENCLAW_STATE_DIR/openclaw.json`, otherwise `~/.openclaw/openclaw.json`.
The verified connector binary parses JSON5 (including JSON) after download;
no Node, jq or Python runtime is needed on the host. `gateway.port` selects
`ws://127.0.0.1:PORT`; the fallback port is 18789. Invalid config/ports stop
installation with a sanitized error. Missing or unreadable config uses defaults.
Shell `--dry-run` reports the selection and intended discovery, without reading
secrets or downloading the binary. The binary's `install --dry-run --engine
openclaw` additionally resolves and validates config and token-file inputs.

Token-file auth takes precedence over `gateway.auth.token` or, with
`gateway.auth.mode:"password"`, `gateway.auth.password`. The connector writes
`openclaw.env` beside its config, atomically with mode 0600. The systemd unit
loads it with `EnvironmentFile=`. The system manager reads a system install's
root-owned file; no Gateway secret belongs in `config.json`. If auth is absent,
installation continues. Add `UNBOUND_OPENCLAW_TOKEN` or
`UNBOUND_OPENCLAW_PASSWORD` to that private file and restart the service.
`doctor` reports auth presence and TCP reachability without exposing values;
`status` reports the live protocol state, auth presence and whether the current
handshake establishes reachability. Disconnected status means reachability is
unknown; doctor can probe it separately.

With OpenClaw, pairing creates an OpenClaw binding under the app-reserved ID.
It never enrolls or starts Hermes. E2E pairing completion does not wait for
Gateway device approval. The installer prints:

> If OpenClaw asks to approve this connector, run: openclaw devices list, then openclaw devices approve <requestId>. The app shows the exact command too.

Device approval remains an owner action; the installer does not approve any
pending device automatically. `doctor` retains this guidance for
`pairing_pending`. The app's exact request-ID command is delivered separately.


## Update an installed connector

Run as the user who installed the user service:

```sh
unbound-connector update
unbound-connector update --version 0.2.20
# An intentional downgrade requires both options:
unbound-connector update --version 0.2.19 --allow-downgrade
```

For a system installation, run as root with `--system` (for example,
`sudo unbound-connector update --system`). The system service still runs as
`unbound-connector`; status and doctor probes run as that account. An ordinary
service account cannot replace the root-owned system executable.
`--config PATH` selects the installed configuration. Keep its settings unchanged
while updating. Only the installer's standard executable and unit paths are
supported; customized units and drop-ins require owner review instead of an
automatic restart.

The default reads `https://unboundchat.net/connector/latest.json`, then downloads
that version's `manifest.json`, `manifest.json.sig` and Linux x64/arm64 binary.
It verifies the raw Ed25519 manifest signature before reading checksums, enforces
the requested version and canonical manifest format, then verifies binary size
and SHA-256. There is no unsigned fallback or remotely fetched trust key.
The public trust anchor is the installer's pinned PEM, preserved beside the
executable as `unbound-connector.release-public.pem`. Keep that public file when
moving or backing up the executable. A differing installer pin fails closed;
key rotation needs explicit release-owner review.

Installations from before this updater have no saved pin and their old `update`
command only prints advice. Re-run the **trusted current installer** once:

```sh
curl -fsSL https://unboundchat.net/connector/install.sh | sh -s -- --user
```

It authenticates a candidate using its pinned key and invokes the candidate's
updater while the old executable remains installed. It does not need `--pair`
or a new pairing code. Both hosted and self-hosted routing keep their existing
config, database, wrapping keys, bindings and devices. Explicit engine options
are refused for an update; change settings separately.

Before replacement, the updater checks ownership, systemd's loaded unit, live
status, the current doctor's result, and the candidate's version and doctor.
A stopped or unhealthy installation must be repaired first. The candidate is
written to an exclusive temporary file **in the executable directory**, fsynced,
and renamed atomically. A hard link preserves the previous executable until the
new service passes live version, binding/device retention and doctor checks.
Normal success uses one service restart. A failed restart or health check
restores the prior executable atomically, restarts it and checks recovery;
the update still exits nonzero. The updater never restores older pairing data.
A binary rollback cannot undo an incompatible database migration performed by a
new release; release owners must preserve backward data compatibility.

Each stage emits content-free JSON codes (`connector_update_*`) with an operation
ID and elapsed time, alongside human guidance. Exit 0 means the new service
passed health checks; 1 means setup/preflight refusal;
2 means invalid arguments/config. Stage failures use 10 (download), 11
(verification), 12 (prepare/replace), 13 (restart), 14 (health), 15 (rollback),
16 (commit/cleanup) and 17 (version/downgrade refusal). Timeouts have a separate `*_timed_out` event
and never claim confirmed success. Doctor WARNs do not fail an update; FAILs do.

An interrupted updater leaves `.update-lock` and possibly `.update-previous`
beside the executable. Do not delete recovery material or start another update
until you have confirmed no updater is running and inspected the service journal.
If recovery fails, the CLI reports `connector_update_rollback_failed`; the old
binary is either already restored at the executable path or retained as
`unbound-connector.update-previous`. Repair the service before retrying. No
automatic recovery from process death or power loss is claimed.

## Uninstall

Stop and disable the service before removing its executable or public pin:

```sh
systemctl --user disable --now unbound-connector.service
rm ~/.config/systemd/user/unbound-connector.service
systemctl --user daemon-reload
rm ~/.local/bin/unbound-connector ~/.local/bin/unbound-connector.release-public.pem
```

For a system installation, use root, omit `--user`, remove
`/etc/systemd/system/unbound-connector.service`, and remove the binary and pin
from `/usr/local/bin/`. These steps keep config and data, including pairing.
Deleting the config/data paths in the table above is a separate destructive
reset and loses the installation's pairing authority; updating never requires it.
