# Run it with the Linux kit

The kit installs the agent as a systemd service, after checking every file and showing the partner agreement. Calls go to https://supply.coronium.ai. The kit carries these same steps in its `README.md`.

<!-- facts:begin part.linux-kit -->
## Needs

- Linux on x86-64 or ARM64, root through `sudo`, and `curl` and `sha256sum`.
- The system's certificate roots, which minimal and container images leave out: `sudo apt-get install -y ca-certificates` on Debian and Ubuntu, `sudo apk add ca-certificates` on Alpine, `sudo dnf install -y ca-certificates` on Fedora and RHEL.
- Outbound TCP to the relay. No inbound port.
- From the device's enrolment at https://supply.coronium.ai/farmer or through the API: the relay `host:port`, the device id, the device secret, and the agreement digest shown for the device, which is the `sha256` of the text the account signed.
- The kit digest: the line for `coronium-agent-linux-<arch>/SHA256SUMS` in https://supply.coronium.ai/kit/SHA256SUMS, which the farmer portal also shows.
- A person at the device's terminal: the installer shows the partner agreement and asks them to type it. An agent hands this step to its person, or runs the program alone instead.

## Steps

1. Download and check the kit as your normal user, before anything runs as root. Every block works in one folder, `~/coronium` unless `CORONIUM_DIR` names another. `ARCH` is `amd64` when `uname -m` prints `x86_64`, and `arm64` for `aarch64`.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
mkdir -p "${CORONIUM_DIR:-$HOME/coronium}"
cd "${CORONIUM_DIR:-$HOME/coronium}" || exit
ARCH=amd64
curl -fsSLO "$SUPPLY/kit/SHA256SUMS"
curl -fsSLO "$SUPPLY/kit/coronium-agent-linux-$ARCH.tar.gz"
grep " coronium-agent-linux-$ARCH.tar.gz\$" SHA256SUMS | sha256sum -c
tar -xzf "coronium-agent-linux-$ARCH.tar.gz"
grep " coronium-agent-linux-$ARCH/SHA256SUMS\$" SHA256SUMS | sha256sum -c
(cd "coronium-agent-linux-$ARCH" && sha256sum -c SHA256SUMS)
```

Expect: every line ends `OK`. If one does not, stop and write to the contact in `PARTNER-AGREEMENT.md`. Nothing is signed yet: the digests are only as trustworthy as the site they came from. Safe to repeat: yes.

2. Install, from the kit's folder. Without systemd, add `--no-systemd`: the installer then prints one command that runs the agent in the foreground as the user `nobody`, and nothing starts it after a reboot.

```sh
umask 077
cd "${CORONIUM_DIR:-$HOME/coronium}" || exit
cd coronium-agent-linux-*/ && sudo ./install.sh
```

Expect: `Installed.` and the consent record, which holds no secret. The settings go to `/etc/coronium-agent/agent.env`, readable by root only. If refused: `no_certificate_roots` (install the roots above), `kit_digest_mismatch` (download the kit again), `agreement_not_accepted` (the kit's agreement is not the text the account signed: sign the text in force, then enrol), `consent_not_given`, `bad_relay`, `bad_device_id` or `bad_secret` (run it again with the right value), `no_systemd` (add `--no-systemd`), `wrong_architecture`, `checksum_mismatch` or `consent_draft` (get a new kit). Safe to repeat: yes, and it keeps the settings.

3. Check.

```sh
umask 077
cd "${CORONIUM_DIR:-$HOME/coronium}" || exit
systemctl is-active coronium-agent
journalctl -u coronium-agent -n 20 --no-pager
```

Expect: `active` and `connected to the relay`. A problem is one log line with its cause and its fix, and the agent dials again by itself. If its settings are refused five times in five minutes the service stops: fix the cause, then `sudo systemctl restart coronium-agent`.

## Stop and remove

Stop, remove, withdraw: https://supply.coronium.ai/guides/device-lifecycle.md.
<!-- facts:end part.linux-kit -->

## If it is not connected

```sh
umask 077
cd "${CORONIUM_DIR:-$HOME/coronium}" || exit
sudo systemctl enable --now coronium-agent
sudo systemctl restart coronium-agent
journalctl -u coronium-agent -n 5 --no-pager
```

The first line starts a service that was stopped or disabled; the second starts one that gave up after refused settings; the third shows why it is not connected, if it is not.

## Update

`/kit/index.json` names the published `version`, and publishing a newer agent does not stop one that is running. To update, download and check the new kit as in step 1 and run its installer as in step 2. It checks every file of the kit again and asks for the two digests and your agreement before it replaces the program, keeps `/etc/coronium-agent/agent.env`, and starts the service again. Then check as in step 3. When a check fails, nothing is replaced.
