# Run a community catalog

Source: https://docs.lightair.app/developers/extend/run-a-catalog

> Sign your own list of Lightair packages with lightair-pack, serve it from GitHub Pages or any HTTPS host, and revoke or yank versions when needed.

In short:
- A community catalog is a folder of signed JSON files at an HTTPS address. `lightair-pack catalog init` makes one and its key.
- `catalog add` lists a release, `catalog sign` renews it (at least every 7 days by default), `catalog revoke` switches a package off everywhere.
- People add it in **Window › Packages** with **+ › Catalogs…**, or with a `lightair://catalog?url=…` link.
- Lightair trusts the key it sees when the catalog is added. Keep the key secret and out of the folder you publish.

In the app: Window › Packages › + › Catalogs…

A community, a team or a studio can run its own catalog of Lightair packages. It's a folder of
JSON files signed with the catalog's own key, served over HTTPS: GitHub Pages is enough. Lightair
reads it like its own catalog, and says that its packages aren't checked by Lightair.

## Start from the template

[lightair-checks](https://github.com/Lightair-Project/lightair-checks) has a ready repository in
`template/community-catalog/`: a GitHub Actions workflow that adds releases, signs the catalog and
publishes it with GitHub Pages.

1. Make a public repository from the template.
2. Install `lightair-pack` (see [Publish a package](/developers/extend/publish#install-lightair-pack))
   and make the catalog and its key:

   ```sh
   lightair-pack catalog init catalog --name "My catalog" --key catalog-key.json
   ```

   It prints the key's fingerprint. Put it in the repository's README, so people can compare it
   with what Lightair shows them.
3. Commit the `catalog/` folder. Never commit `catalog-key.json`.
4. Add the key file's contents as the repository secret `CATALOG_KEY` (**Settings › Secrets and
   variables › Actions**), then keep the file somewhere safe, offline.
5. In **Settings › Pages**, set **Source** to **GitHub Actions**.
6. List releases in `packages.txt`, one `owner/repo@tag` per line, and push.

The workflow adds each new release, signs the catalog, commits it and publishes it at
`https://<owner>.github.io/<repository>/`. It runs when `packages.txt` changes and once a day, so
the catalog never runs out of date.

Each release must be an immutable release in a public repository. Authors can make one with
`lightair-pack publish --no-register`.

## Let people add it

In Lightair, the person opens **Window › Packages**, clicks **+**, picks **Catalogs…**, pastes the
catalog's address and clicks **Add**. Lightair reads the catalog's first root and asks:

- the catalog's name and address;
- its key's fingerprint, to compare with the one you publish;
- that packages from it aren't checked by Lightair.

From then on Lightair trusts that key, checks the catalog at launch and every 6 hours, and offers
its packages beside Lightair's. Removing the catalog keeps what was installed from it, without
updates.

Links do the same in one click:

| Link | What it does |
|---|---|
| `lightair://catalog?url=<address>` | Asks to add the catalog. |
| `lightair://install?id=<id>&catalog=<address>` | Asks to add the catalog if it isn't added yet, then opens the install screen. Add `&version=<version>` for one version; the newest otherwise. |

Percent-encode the address inside a link. A link never installs anything by itself.

## The commands

Every `catalog` command takes the catalog's folder and its key, and signs the catalog again when
it changes something.

### init

```sh
lightair-pack catalog init <folder> --name <name> [--key <file>] [--days <n>]
```

Makes the catalog in `<folder>`. When the `--key` file exists it's used; otherwise a new key is
written there (`catalog-key.json` by default), readable only by you. The key must be outside the
catalog's folder, because the folder is published. One key holds every role.

The folder then holds:

| File | What it is |
|---|---|
| `root/1.json` | The catalog's name and keys, signed. Valid for five years. |
| `timestamp.json` | Names the current snapshot. Renewed by every signing. |
| `snapshot.json` | The checksums of the shards and the revoked list. |
| `shards/0.json` … `shards/f.json` | The packages, split by the first hex digit of the SHA-256 of their id. |
| `revoked.json` | Revocations, signed. |
| `.nojekyll` | Lets GitHub Pages serve the folder as it is. |

### add

```sh
lightair-pack catalog add <folder> --key <file> --release owner/repo@tag [--publisher <name>]
lightair-pack catalog add <folder> --key <file> --file pack.airpkg --url https://… [--file … --url …]
                          [--repository <url> --commit <sha>] [--publisher <name>]
```

Lists one version of a package.

- **`--release owner/repo@tag`** downloads the release's `.airpkg` files from a public repository,
  and records the repository and the tag's commit. It notes a release that isn't immutable. The
  publisher is the repository's owner unless `--publisher` says otherwise.
- **`--file` with `--url`** adds files you have, each with the address people download it from.
  The publisher is `--publisher`, else the manifest's `author`.

Each file goes through the static checks, and a failing package isn't added unless you give
`--force` (it's then listed without a passed check). A file named `<anything>-<platform>.airpkg`
is that platform's. Every file of a version must have the same id, version, permissions and
Lightair range. A version is never added twice, and a package listed by one publisher can't be
added by another.

### sign

```sh
lightair-pack catalog sign <folder> --key <file> [--days <n>]
```

Writes a new snapshot and timestamp. The timestamp is valid for `--days`, 7 by default. Sign
again before it expires: Lightair refuses an expired timestamp and says the catalog is out of
date, while what's installed keeps working.

### revoke

```sh
lightair-pack catalog revoke <folder> --key <file> --id <id> [--versions "<1.4.2"] --reason "Uploads saved passwords."
lightair-pack catalog revoke <folder> --key <file> --sha256 <checksum> --reason "…"
lightair-pack catalog revoke <folder> --key <file> --publisher <name> --reason "…"
```

Adds an entry to the revoked list, matched by a file's checksum (its archive or content SHA-256),
by id and a version range (every version without `--versions`), or by publisher. Every Lightair
that added your catalog switches matching packages off when it next checks, and tells the person
why. A community catalog's revocations apply only to packages installed from it.

### yank

```sh
lightair-pack catalog yank <folder> --key <file> --id <id> --version <version> [--undo]
```

Stops offering a version: it's no longer the latest or an update. Copies already installed keep
working. `--undo` offers it again. To switch a version off where it's installed, revoke it.

## Keys

A key file holds an Ed25519 key. Lightair shows the key's fingerprint when the catalog is added
and trusts only signatures from that catalog's keys after that. If the keys change without a
signed handover, Lightair stops taking updates from the catalog and asks the person to remove it
and add it again. If the root expires with no successor, Lightair stops taking updates from it
too.

A handover is a new root, `root/<n+1>.json`. Lightair fetches the next root until there's none;
each must be signed by the previous root's root keys and by its own, and be the next version.
`lightair-pack keys` makes keys and roots:

| Command | What it makes |
|---|---|
| `keys online --out <file>` | A plain key file, readable only by you. |
| `keys root [--out root-key.json]` | A key file encrypted with a passphrase of 12 characters or more, asked for or read from `LIGHTAIR_ROOT_PASSPHRASE`. Commands that take a key file ask for its passphrase. |
| `keys sign-root --version <n> --root <key> … --catalog <key> … --timestamp <key> … --sign-with <key file> … --out root/<n>.json` | A root naming the keys for each role, signed with each `--sign-with`. `--previous root/<n-1>.json` checks it follows the current root, and it refuses to write one that doesn't. `--name` sets the catalog's name, `--root-threshold` how many root keys must sign the next root, `--expires-days` how long it lasts (1,825 days by default). |

The `catalog` commands sign with one key, so a key you pass to them must hold both the catalog and
the timestamp role. Key commands never overwrite an existing file.

## Related

- [Publish a package](/developers/extend/publish)
- [Packages](/developers/extend/packages)
- [Install packages](/desktop/chat-and-widgets/packages)
