diff --git a/CHANGELOG.md b/CHANGELOG.md index 5994cbd..2f07636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ All notable changes to libbui are recorded here. The format follows ### Added +- Prebuilt binaries on each release for Linux (x86_64, ARM64, RISC-V; static), + macOS (Apple silicon, Intel) and Windows, with `SHA256SUMS` and build + provenance, and an install script at + `https://libbui.vinnymac.dev/install.sh` that checks the download before it + installs to `~/.local/bin`. - The terminal interface: shelf, search, holds, downloads, title details, help, command palette, themes (including high contrast and mono), ASCII mode, reduced motion and a Fluent message catalog. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index afb89cc..8890710 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,6 +56,24 @@ point it at a server you run. - Commit messages are conventional and lowercase, such as `feat(search): add a language filter` or `fix(core): keep partial files`. +## Releasing + +Releases are cut from Tangled and published on the GitHub mirror. + +1. Set `version = "X.Y.Z"` in the root `Cargo.toml` and rename + `## [Unreleased]` in `CHANGELOG.md` to `## [X.Y.Z]`. That section becomes + the release notes. +2. Commit, then tag and push: `git tag vX.Y.Z && git push origin vX.Y.Z`. +3. The Tangled `mirror` workflow pushes the tag to GitHub, where + `.github/workflows/release.yml` builds the six binaries, writes + `SHA256SUMS`, attests build provenance and publishes the release. Tangled's + `release` workflow builds and smoke-tests the Linux binaries as a second + check. + +To try the release build without publishing, run the `release` workflow by +hand from the Actions tab. A tag with a hyphen, such as `v0.2.0-rc.1`, is +published as a prerelease, which `install.sh` skips unless asked for by name. + ## Translations Copy `crates/libbui/locales/en-US` to a folder named for your language (for diff --git a/README.md b/README.md index e7038eb..eefef1a 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,50 @@ Optionally, each book is filed with a `cover.jpg` and a Calibre-compatible ## Install +On Linux and macOS, the install script fetches the build for your computer, +checks it against the release's `SHA256SUMS` and puts `libbui` in +`~/.local/bin`. It never uses sudo. [Read it](web/public/install.sh) first if +you like. + +```sh +curl -fsSL https://libbui.vinnymac.dev/install.sh | sh +``` + +`LIBBUI_VERSION=v0.1.0` installs a particular release and +`LIBBUI_INSTALL_DIR=DIR` puts it somewhere else. + +### Download a release + +Every [release](https://github.com/vinnymac/libbui/releases) carries +ready-to-run binaries. The Linux ones are static, so they run on any +distribution. + +| System | File | +| ---------------------- | -------------------------------------------- | +| Linux x86_64 | `libbui-x86_64-unknown-linux-musl.tar.gz` | +| Linux ARM64 | `libbui-aarch64-unknown-linux-musl.tar.gz` | +| Linux RISC-V 64 | `libbui-riscv64gc-unknown-linux-musl.tar.gz` | +| macOS (Apple silicon) | `libbui-aarch64-apple-darwin.tar.gz` | +| macOS (Intel) | `libbui-x86_64-apple-darwin.tar.gz` | +| Windows x86_64 | `libbui-x86_64-pc-windows-msvc.zip` | + +Check the download against `SHA256SUMS` and unpack it: + +```sh +sha256sum --check --ignore-missing SHA256SUMS # macOS: shasum -a 256 --check --ignore-missing SHA256SUMS +tar -xzf libbui-x86_64-unknown-linux-musl.tar.gz +mv libbui-x86_64-unknown-linux-musl/libbui ~/.local/bin/ +``` + +Each release also has a signed build provenance attestation, which the +[GitHub CLI](https://cli.github.com) can check: + +```sh +gh attestation verify libbui-x86_64-unknown-linux-musl.tar.gz --repo vinnymac/libbui +``` + +### Build with Cargo + libbui needs Rust 1.90 or newer. It uses rustls, so there is no OpenSSL or other system library to install. @@ -101,6 +145,7 @@ scripts/riscv64.sh # builds, checks it is static, runs it under qemu-riscv64 i ``` CI builds the same binary on every push and keeps it as a workflow artifact. +Tagged releases publish it alongside the other platforms. ### Try it in a browser diff --git a/web/index.html b/web/index.html index 824cf6c..7d93b78 100644 --- a/web/index.html +++ b/web/index.html @@ -158,11 +158,35 @@
  1. -

    Install with Cargo

    -

    Needs Rust 1.90 or newer. No system libraries required.

    +

    Install libbui

    +

    + On Linux and macOS, this fetches the build made for your computer, checks it against + the release checksums and puts libbui in ~/.local/bin. It + never asks for your password, and you can read the script + first. +

    -
    cargo install --locked --git https://tangled.sh/@vinnymac.dev/libbui libbui
    - +
    curl -fsSL https://libbui.vinnymac.dev/install.sh | sh
    + +
    +
    +
    +

    Download it yourself

    +

    + Each release + has a ready-to-run libbui for Linux (x86_64, ARM64 and RISC-V), macOS (Apple + silicon and Intel) and Windows, plus a SHA256SUMS file to check it + against. Unpack it and put libbui anywhere on your PATH. +

    +
    +
    +

    Build it with Cargo

    +

    Needs Rust 1.90 or newer. No system libraries required.

    +
    +
    cargo install --locked --git https://tangled.sh/@vinnymac.dev/libbui libbui
    + +
    +
  2. diff --git a/web/public/install.sh b/web/public/install.sh new file mode 100644 index 0000000..b707d25 --- /dev/null +++ b/web/public/install.sh @@ -0,0 +1,167 @@ +#!/bin/sh +# Installs libbui from its GitHub release into ~/.local/bin. +# +# curl -fsSL https://libbui.vinnymac.dev/install.sh | sh +# +# It works out your system, downloads the matching archive over HTTPS, +# checks it against the release's SHA256SUMS and copies `libbui` into place. +# It never asks for sudo and touches nothing outside the install folder. +# +# Settings, all optional: +# LIBBUI_VERSION=v0.1.0 a release tag (default: the latest release) +# LIBBUI_INSTALL_DIR=DIR where libbui goes (default: ~/.local/bin) +# LIBBUI_REPO=owner/name the GitHub repository that holds the releases +# +# The checksum catches a broken or cut-off download. To check who built the +# archive, verify its provenance with the GitHub CLI: +# gh attestation verify libbui-.tar.gz --repo vinnymac/libbui +# +# Everything is inside main(), which runs on the last line, so a download +# that stops halfway through this script runs nothing. +set -eu + +say() { + printf 'libbui: %s\n' "$*" +} + +die() { + printf 'libbui: %s\n' "$*" >&2 + exit 1 +} + +usage() { + cat <<'EOF' +Installs libbui from its GitHub release into ~/.local/bin. + + curl -fsSL https://libbui.vinnymac.dev/install.sh | sh + +Settings, all optional: + LIBBUI_VERSION=v0.1.0 a release tag (default: the latest release) + LIBBUI_INSTALL_DIR=DIR where libbui goes (default: ~/.local/bin) + LIBBUI_REPO=owner/name the GitHub repository that holds the releases +EOF +} + +# Prints the Rust target name of the release built for this machine. +detect_target() { + os=$(uname -s) + arch=$(uname -m) + case "$os" in + Linux) + case "$arch" in + x86_64 | amd64) echo x86_64-unknown-linux-musl ;; + aarch64 | arm64) echo aarch64-unknown-linux-musl ;; + riscv64) echo riscv64gc-unknown-linux-musl ;; + *) die "there is no Linux release for $arch yet. Install with Cargo instead: https://libbui.vinnymac.dev/#install" ;; + esac + ;; + Darwin) + # A shell under Rosetta reports x86_64 on Apple silicon; take the native build. + if [ "$arch" = x86_64 ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = 1 ]; then + arch=arm64 + fi + case "$arch" in + arm64 | aarch64) echo aarch64-apple-darwin ;; + x86_64) echo x86_64-apple-darwin ;; + *) die "there is no macOS release for $arch." ;; + esac + ;; + MINGW* | MSYS* | CYGWIN* | Windows_NT) + die "on Windows, download libbui-x86_64-pc-windows-msvc.zip from https://github.com/${repo}/releases and put libbui.exe on your PATH." + ;; + *) + die "there is no release for $os yet. Install with Cargo instead: https://libbui.vinnymac.dev/#install" + ;; + esac +} + +# download URL FILE: HTTPS only, failing on any HTTP error. +download() { + if command -v curl >/dev/null 2>&1; then + curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSL -o "$2" "$1" + elif command -v wget >/dev/null 2>&1; then + wget --https-only --secure-protocol=TLSv1_2 -q -O "$2" "$1" + else + die "libbui needs curl or wget to download a release." + fi +} + +# Prints the SHA-256 of FILE. +sha256() { + if command -v sha256sum >/dev/null 2>&1; then + sha256sum "$1" | cut -d ' ' -f 1 + elif command -v shasum >/dev/null 2>&1; then + shasum -a 256 "$1" | cut -d ' ' -f 1 + elif command -v openssl >/dev/null 2>&1; then + openssl dgst -sha256 -r "$1" | cut -d ' ' -f 1 + else + die "libbui needs sha256sum, shasum or openssl to check the download." + fi +} + +main() { + case "${1:-}" in + -h | --help) + usage + return 0 + ;; + "") ;; + *) die "unknown option '$1'. Settings are environment variables; see --help." ;; + esac + + repo=${LIBBUI_REPO:-vinnymac/libbui} + version=${LIBBUI_VERSION:-latest} + dir=${LIBBUI_INSTALL_DIR:-${HOME:?HOME is not set}/.local/bin} + + target=$(detect_target) + asset="libbui-$target.tar.gz" + if [ "$version" = latest ]; then + base="https://github.com/$repo/releases/latest/download" + else + case "$version" in + v*) ;; + *) version="v$version" ;; + esac + base="https://github.com/$repo/releases/download/$version" + fi + + tmp=$(mktemp -d 2>/dev/null || mktemp -d -t libbui) + trap 'rm -rf "$tmp"' EXIT + trap 'exit 130' INT TERM + + say "downloading $asset ($version)" + download "$base/$asset" "$tmp/$asset" || die "could not download $base/$asset" + download "$base/SHA256SUMS" "$tmp/SHA256SUMS" || die "could not download $base/SHA256SUMS" + + want=$(awk -v name="$asset" '$2 == name || $2 == "*" name { n++; hash = $1 } END { if (n == 1) print hash }' "$tmp/SHA256SUMS") + [ -n "$want" ] || die "SHA256SUMS does not list $asset exactly once. Nothing was installed." + got=$(sha256 "$tmp/$asset") + [ "$got" = "$want" ] || die "the checksum of $asset does not match SHA256SUMS. Nothing was installed." + say "checksum matches" + + tar -xzf "$tmp/$asset" -C "$tmp" + binary="$tmp/libbui-$target/libbui" + [ -f "$binary" ] || die "$asset has no libbui inside." + + mkdir -p "$dir" || die "could not create $dir. Choose another folder with LIBBUI_INSTALL_DIR." + [ -w "$dir" ] || die "$dir is not writable. Choose another folder with LIBBUI_INSTALL_DIR." + # Copied beside the old one and renamed over it, so a libbui that is + # running keeps working and an interrupted install leaves no half a file. + cp "$binary" "$dir/.libbui.new" + chmod 755 "$dir/.libbui.new" + mv -f "$dir/.libbui.new" "$dir/libbui" + + installed=$("$dir/libbui" --version) || die "libbui was copied to $dir but does not run on this system." + say "installed $installed to $dir/libbui" + case ":${PATH:-}:" in + *":$dir:"*) say "run libbui to begin" ;; + *) + say "$dir is not on your PATH yet. Add this line to your shell profile:" + # $PATH stays literal: it is for the profile, not this shell. + # shellcheck disable=SC2016 + printf '\n export PATH="%s:$PATH"\n\n' "$dir" + ;; + esac +} + +main "$@" diff --git a/web/scripts/compress.mjs b/web/scripts/compress.mjs index a80e5a8..b783ec8 100644 --- a/web/scripts/compress.mjs +++ b/web/scripts/compress.mjs @@ -7,7 +7,7 @@ import { fileURLToPath } from "node:url"; import { brotliCompressSync, constants, gzipSync } from "node:zlib"; const dist = fileURLToPath(new URL("../dist/", import.meta.url)); -const COMPRESSIBLE = /\.(html|js|css|svg|wasm|json|txt|bin)$/; +const COMPRESSIBLE = /\.(html|js|css|svg|wasm|json|txt|sh|bin)$/; for (const entry of await readdir(dist, { recursive: true, withFileTypes: true })) { if (!entry.isFile() || !COMPRESSIBLE.test(entry.name)) continue; diff --git a/web/server.mjs b/web/server.mjs index 7c8e292..ee937fa 100644 --- a/web/server.mjs +++ b/web/server.mjs @@ -23,6 +23,9 @@ const TYPES = { ".wasm": "application/wasm", ".json": "application/json", ".txt": "text/plain; charset=utf-8", + // Plain text, so a browser shows install.sh for reading instead of saving it. + ".sh": "text/plain; charset=utf-8", + ".png": "image/png", }; const SECURITY = { diff --git a/web/src/style.css b/web/src/style.css index 0fa36aa..d1012e6 100644 --- a/web/src/style.css +++ b/web/src/style.css @@ -493,6 +493,24 @@ kbd { color: var(--accent); } +.other-ways { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 1.5rem; + margin-block-start: 1.75rem; + padding-block-start: 1.5rem; + border-block-start: 1px solid var(--rule); +} + +.other-ways > div { + min-inline-size: 0; +} + +h4 { + margin: 0 0 0.4rem; + font: 600 1.05rem/1.3 var(--sans); +} + code { font-family: var(--mono); font-size: 0.9em; @@ -550,7 +568,8 @@ code { @media (max-width: 40rem) { .grid, - .steps { + .steps, + .other-ways { grid-template-columns: minmax(0, 1fr); } .masthead ul {