# Module — Updates

**Type**: Core (always enabled)

Run `apt update && apt full-upgrade` on the Proxmox host or any LXC container, with real-time streaming output via WebSocket.

## Features

- Target: host, a specific LXC (`lxc:100`), or all LXC containers at once
- Output streamed line-by-line via WebSocket — no polling required
- Full output saved to `update_history` table in SQLite
- Admin-only action

## API Endpoints

| Method | Path | Auth | Description |
|--------|------|------|-------------|
| POST | `/api/updates/run` | JWT+Admin | Start an update job |
| GET | `/api/updates/history` | JWT | List past update jobs (last 50) |

### POST /api/updates/run

```json
{ "target": "host" }
```

```json
{ "target": "lxc:100" }
```

```json
{ "target": "all" }
```

Response:

```json
{ "job_id": "1710000000-ab3f9z12", "message": "Mise à jour démarrée" }
```

## WebSocket Streaming

Connect to `GET /ws/updates/{jobId}?token=<jwt>` to receive output in real time.

Message types published on the channel:

| Type | Payload | Description |
|------|---------|-------------|
| `update_output` | `{ "chunk": "..." }` | Line(s) of apt output |
| `update_done` | `{ "job_id": "..." }` | Job completed successfully |
| `update_error` | `{ "error": "..." }` | Job failed |

## How It Works

Updates run over SSH using the credentials configured during installation:

- **Host**: runs `DEBIAN_FRONTEND=noninteractive apt-get update && apt-get full-upgrade -y` directly
- **LXC**: runs the same command via `pct exec <vmid> -- bash -c '...'`
- **All**: iterates over `pct list` output and updates each container

## Requirements

- SSH access to the Proxmox host with sudo/root privileges
- `pct` available on the host (standard on Proxmox VE)

## License

MIT — see [LICENSE](../../LICENSE)
