|
| 1 | +# BUP Packaging Guide for BoredOS |
| 2 | + |
| 3 | +This guide explains how to package applications and libraries into BoredOS Package (`.bup`) files for distribution via the BoredOS Package Manager (`bpm`). |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## What is a `.bup` File? |
| 8 | + |
| 9 | +A `.bup` file is a **TAR archive compressed with LZ4** (`.tar.lz4`) containing a metadata manifest, payload directories, and optional installation hook scripts. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Package Directory Structure |
| 14 | + |
| 15 | +To build a `.bup` file, you must first organize your files inside a package root directory (e.g., `pkg_staging/`). The structure inside this directory must follow this layout: |
| 16 | + |
| 17 | +```text |
| 18 | +pkg_staging/ |
| 19 | +├── MANIFEST.toml # [Mandatory] Package metadata and install paths |
| 20 | +├── bin/ # [Optional] Executable binaries (e.g. .elf files) |
| 21 | +├── config/ # [Optional] Configuration files |
| 22 | +├── assets/ # [Optional] Shared assets (images, themes, data, etc.) |
| 23 | +└── scripts/ # [Optional] Hook scripts executed during install/remove |
| 24 | + ├── install.bsh # [Optional] Post-install script |
| 25 | + └── remove.bsh # [Optional] Pre-remove / post-update script |
| 26 | +``` |
| 27 | + |
| 28 | +> [!WARNING] |
| 29 | +> Only include directories and files that your package actually uses. Do not leave empty directories. |
| 30 | +
|
| 31 | +--- |
| 32 | + |
| 33 | +## 1. The Manifest File (`MANIFEST.toml`) |
| 34 | + |
| 35 | +The `MANIFEST.toml` file must reside at the root of the package. It defines the package name, version, and the target directories where each payload folder should be copied. |
| 36 | + |
| 37 | +### Format and Constraints |
| 38 | +* **Syntax**: Standard TOML format. |
| 39 | +* **Strings**: Values **must** be enclosed in double quotes (`"..."`). Single quotes or unquoted values are not supported by the parser. |
| 40 | +* **Sections**: The `[install]` section header must be present exactly as `[install]` for installation paths. |
| 41 | + |
| 42 | +### Structure Example |
| 43 | +```toml |
| 44 | +name = "my-app" |
| 45 | +version = "1.0.0" |
| 46 | + |
| 47 | +[install] |
| 48 | +bin = "/usr/bin" |
| 49 | +config = "/Library/conf" |
| 50 | +assets = "/usr/share/my-app" |
| 51 | +``` |
| 52 | + |
| 53 | +### Destination Resolution |
| 54 | +When `bpm` installs a package, it maps the contents of your staging directories to destinations specified in the `[install]` block of `MANIFEST.toml`: |
| 55 | + |
| 56 | +| Source Folder | Destination Option | Default Destination | Notes | |
| 57 | +| :--- | :--- | :--- | :--- | |
| 58 | +| `bin/` | `bin` | `/usr/bin` | Target directory for binaries and executables. | |
| 59 | +| `config/` | `config` | `/Library/conf` | Target directory for configuration files. | |
| 60 | +| `assets/` | `assets` | *No Default* | **Required** if `assets/` folder is present. If `assets` is omitted from `[install]`, the `assets/` folder will **not** be installed. | |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## 2. Directory Mappings |
| 65 | + |
| 66 | +* **`bin/`**: Any files in `bin/` will be copied into the destination path defined by `bin` in `MANIFEST.toml`. Files beginning with `._` (macOS metadata files) are automatically ignored. |
| 67 | +* **`config/`**: Any files in `config/` will be copied into the destination path defined by `config` in `MANIFEST.toml`. |
| 68 | +* **`assets/`**: Any files in `assets/` will be copied into the destination path defined by `assets` in `MANIFEST.toml`. **Important**: Ensure `assets` is explicitly set in `MANIFEST.toml`. |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## 3. Hook Scripts (`scripts/`) |
| 73 | + |
| 74 | +`bpm` supports optional installation lifecycle hooks. These hooks must be written in Bored Shell script format (`.bsh`) and placed inside the `scripts/` directory: |
| 75 | + |
| 76 | +* **`install.bsh`**: Executed via `/bin/bsh` **immediately after** files are copied to the system. Used for setting up permissions, initial data, or starting services. |
| 77 | +* **`remove.bsh`**: Executed via `/bin/bsh` **immediately before** package files are deleted. Used to stop services, clean up logs, or remove custom directories. |
| 78 | + |
| 79 | +### Script Execution During Upgrades |
| 80 | +When upgrading a package (via `bpm upgrade`), `bpm` will: |
| 81 | +1. Locate the currently installed package's `remove.bsh` script (cached in `/var/lib/bpm/packages/<pkgname>/remove.bsh`). |
| 82 | +2. Execute it. |
| 83 | +3. Perform the package removal (`cmd_remove`). |
| 84 | +4. Install the new package version (`cmd_install`), which copies new files and executes the new `install.bsh` script. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## 4. Creating the `.bup` Archive |
| 89 | + |
| 90 | +Once your staging directory is ready, compress it from the staging directory using `tar` with LZ4 compression. |
| 91 | + |
| 92 | +### CLI Command Example |
| 93 | + |
| 94 | +If your files are located in `build/package/`: |
| 95 | +```bash |
| 96 | +# Define files/directories to include. Ensure they exist. |
| 97 | +tar --lz4 -C build/package -cf build/my-app-1.0.0.bup MANIFEST.toml bin config assets scripts |
| 98 | +``` |
| 99 | + |
| 100 | +Ensure that the archive lists `MANIFEST.toml` and other directories at its top-level root, rather than inside a nested subdirectory. |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## 5. Integrating with Repository Index (`index.toml`) |
| 105 | + |
| 106 | +To publish your `.bup` package to a repository, it must be registered in the repository's `index.toml`. |
| 107 | + |
| 108 | +A repository index entry contains the package metadata, binary location, and SHA256 checksum for verification: |
| 109 | + |
| 110 | +```toml |
| 111 | +[package.my-app] |
| 112 | +name = "my-app" |
| 113 | +version = "1.0.0" |
| 114 | +description = "A short description of my-app" |
| 115 | +author = "Your Name" |
| 116 | +license = "XXX" |
| 117 | +url = "https://your-domain.com/packages/my-app-1.0.0.bup" |
| 118 | +sha256 = "64_character_hexadecimal_sha256_checksum" |
| 119 | +``` |
| 120 | + |
| 121 | +When a user runs `bpm install my-app`, `bpm`: |
| 122 | +1. Fetches the repository index. |
| 123 | +2. Resolves `my-app` to the entry. |
| 124 | +3. Downloads the `.bup` archive from the `url`. |
| 125 | +4. Computes the SHA256 of the downloaded file and verifies it against the `sha256` value before extraction. |
| 126 | + |
| 127 | +To publish your `.bup` to the bur (Bored User Repository), open up a PR to: https://github.com/boredos/bur |
0 commit comments