# Run it on macOS

The installer sets the program up as a launchd user agent: a service of your own user, which starts when you log in and is started again whenever it ends. Calls go to https://supply.coronium.ai. `/kit/index.json` lists the state and the limits of the program and of the installer, and [the files section](/guides/device-files.md) says what each means.

## Needs

- A Mac with Apple silicon, Terminal and your own user, never `sudo`.
- `agent.env` from [enrolment](/guides/device-enrol.md), in the folder of the downloads. Without it the installer asks for the three values, the secret without showing it.
- Outbound TCP to the relay, no inbound port, and one device per public address.

No installer shows the agreement here, so the signature and the acceptance stored at enrolment are its record.

## Steps

1. Download, check and install, in a folder of its own. The installer runs only when every check line ends `OK`.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
for f in SHA256SUMS coronium-agent-darwin-arm64 coronium-agent-darwin-install.sh coronium-agent-darwin-uninstall.sh; do curl -fsSLO "$SUPPLY/kit/$f"; done
grep -E '  coronium-agent-darwin-(arm64|install\.sh|uninstall\.sh)$' SHA256SUMS | shasum -a 256 -c && sh coronium-agent-darwin-install.sh
```

Expect: three lines ending `OK`, then `Installed.` The installer checks the files again, moves `agent.env` into `~/Library/Application Support/CoroniumDevice`, readable by you only, and writes `~/Library/LaunchAgents/ai.coronium.device.plist`, which holds no setting. If refused: `checksum_missing` or `checksum_mismatch` (download again), `wrong_architecture` (no program is published for an Intel Mac), `runs_as_root` (run it without `sudo`), `quarantined` (a browser downloaded the program: fetch it with curl as above), `bad_settings_file`, `bad_relay`, `bad_device_id` or `bad_secret` (correct `agent.env`), `service_not_started` (log in to the Mac's desktop as this user). Nothing is signed yet: the digests are as trustworthy as the site they came from. Safe to repeat: yes, and it keeps the settings; an `agent.env` beside the installer is then not used, and the installer says to delete it.

2. Check.

```sh
umask 077
launchctl print gui/$(id -u)/ai.coronium.device | grep state
tail -n 20 "$HOME/Library/Application Support/CoroniumDevice/agent.log"
```

Expect: `state = running` and `connected to the relay`. A problem is one log line with its cause and its fix, and the agent dials again by itself. launchd starts an agent that ended again after a pause, so a refused setting repeats in the log until `agent.env` is right.

The service belongs to your user: it runs while you are logged in. After a restart it is back once you log in, and not before. Nothing trims `agent.log`.

## If it is not connected

```sh
umask 077
launchctl bootstrap gui/$(id -u) "$HOME/Library/LaunchAgents/ai.coronium.device.plist"
launchctl kickstart -k gui/$(id -u)/ai.coronium.device
tail -n 5 "$HOME/Library/Application Support/CoroniumDevice/agent.log"
```

The first line loads the service and fails harmlessly when it is loaded; the second starts it again; 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, run the block of step 1 again in an empty folder, without `agent.env`. The installer checks the new files before it touches anything, keeps the settings that are installed, ends the running service, puts the new program in place and starts it. When a check fails, the installed program stays as it is and keeps running.

## Stop and remove

`launchctl bootout gui/$(id -u)/ai.coronium.device` stops sharing until you log in again. To remove the service, the program, its log and `agent.env` with the secret:

```sh
umask 077
sh "$HOME/Library/Application Support/CoroniumDevice/uninstall.sh"
```

It warns, with the process id, about an agent you started yourself, which it does not stop. Removing it does not withdraw the device; [update, stop, remove and withdraw](/guides/device-lifecycle.md) says how.
