Files
leleka/scripts/release/package-5090.sh
T
Pavlo Ratushnyi b4db01728c Keep the Strata files Rust and the product read in third_party/strata (STRA-406)
Owner decision 2026-11-23: the vendored Strata tree engine/strata is removed for good. This first step moves what is still read
at build, test or ship time into one small directory, byte for byte:

- third_party/strata/LICENSE (MIT; `leleka engine license` embeds it, the packagers ship it)
- third_party/strata/ggml/LICENSE, project-maya/LICENSE, project-maya/NOTICE.md (licence texts the release packager ships)
- third_party/strata/serve/chat_template.jinja (one copy, embedded by control-plane server_api.rs and gateway-text prompt.rs)
- third_party/strata/serve/chat_golden.json (gateway-text prompt tests)
- third_party/strata/tests/data/native_experts/*.txt (control-plane native_pack tests)
- control-plane/tests/mcp_hub/mcp_fake_server.py next to its test harness
- third_party/strata/UPSTREAM.md replaces engine/upstream.md: pin 41cf05a0, URL, the 25 locally patched files, where the removed tree is in history

include_str! paths, deploy/build.rs (the `leleka version` Strata pin now reads third_party/strata/UPSTREAM.md), Dockerfile.static-cli,
.dockerignore, .gitattributes, the release packagers (package-5090.sh, package-release.py: the subtree facts of the removed tree are
dropped from PROVENANCE) and the evidence capture scripts follow the move. The tree itself is deleted in a later commit.
2026-11-23 21:11:53 +01:00

438 lines
29 KiB
Bash

#!/bin/sh
# Release packager for the RTX 5090 serve path of Leleka.
#
# Two kinds of host are involved, because the laptop's WSL2 git cannot open a worktree made by Windows git, while the Linux toolchain that builds
# the binaries lives in WSL2 (the 5090 server has no Rust toolchain; every measured binary so far was built in WSL and copied):
#
# 1. a host with the git checkout ("repo mode": Windows Git Bash, Linux):
# package-5090.sh check every gate of the tree, nothing written
# package-5090.sh stage-source [--out DIR] gates, then `git archive HEAD` (LF bytes, no .git) into DIR/src/release-5090-src-COMMIT12
# with PROVENANCE.env (commit, branch, epoch, subtree id, gate result) - clean tree only
# 2. any Linux host with the pinned toolchain, run INSIDE the staged tree ("export mode": no git needed):
# package-5090.sh build [--target-dir DIR] the three cargo builds (sm_120 only, no sm86); the commit and
# the clean/dirty mark come from PROVENANCE.env and are embedded by crates/deploy/build.rs
# package-5090.sh package [--out DIR] [...] git-free gates + build + assemble leleka-VERSION-COMMIT12-5090-linux-x86_64.tar.xz
# package-5090.sh verify TARBALL [--out DIR] unpack beside the tarball, re-check digests, contents, CR bytes and `leleka version`
#
# `package` also works in repo mode on a Linux host whose checkout is LF (a CRLF checkout is refused by gate_lf).
#
# Options: --out DIR output directory (default dist/release-5090; dist/ is git-ignored)
# --target-dir DIR cargo target directory (default: $CARGO_TARGET_DIR or ./target); use a NEW directory per build, never wipe an old one
# --bin-dir DIR package binaries that already exist in DIR (no cargo; their digests go into MANIFEST.json as they are)
# --no-build package from --target-dir/release without building
# --allow-dirty rehearsal in repo mode only: the package is named -dirty and cannot be tagged
# --rehearse package even though gates FAIL (to test the assembly): the archive is named -rehearsal, MANIFEST.json says
# "rehearsal": true and the tag procedure refuses it. Never a release
# --epoch N SOURCE_DATE_EPOCH of the archive (default: commit time of HEAD)
# --expert-profile F ship the ranked-expert table (data/expert-profile.bin of upstream Strata, 196,632 bytes; the same bytes are embedded in `leleka`, so this is optional) as
# share/leleka/data/expert-profile.bin after checking its SHA-256 against the pin of the deploy crate
# --unattended P extra file or directory to ship under share/leleka/unattended/ (repeatable; the defaults below are added when they
# exist: the systemd units and scripts of the unattended-operation work, which the OWNER installs)
#
# What it never does: install or enable anything, touch system settings, download anything, delete anything (an existing output directory is an
# error: move it to garbage/ first), or put model weights, captures, credentials or logs into the archive. Production serving needs no Python
# and the archive contains none.
set -eu
# --- the release identity: change these only with the checklist ------------------------------------------------------------------
RELEASE_TAG=leleka-5090-v0.1
RELEASE_STRATA_PIN=41cf05a06a25dd29103b7b27a2279a3f60c21876 # third_party/strata/UPSTREAM.md; upstream 0.2.8 exists, the pin is NOT moved for this release
BINARIES="leleka leleka-api leleka-inference leleka-daemon leleka-cli leleka-seal-exec"
DOCS="third_party/strata/UPSTREAM.md"
UNATTENDED_DEFAULTS="scripts/ops/README.md scripts/ops/install-leleka-service.sh scripts/ops/leleka.service scripts/ops/owner-wifi-stability.sh"
MAX_TRACKED_BYTES=20000000
SECRET_RE='-----BEGIN [A-Z ]*PRIVATE KEY-----|AKIA[0-9A-Z]{16}|ghp_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{30,}|hf_[A-Za-z0-9]{30,}|sk-[A-Za-z0-9]{32,}|xox[abp]-[A-Za-z0-9-]{10,}|AIza[0-9A-Za-z_-]{35}|eyJ[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.'
FORBIDDEN_NAME_RE='\.(gguf|kar2?|safetensors|pem|key|p12|pfx|jks|sqlite3?|db|log|jsonl|pcap|npz|npy|pt|pth|onnx)$|(^|/)(api-key|runtime\.env|\.env|id_rsa|id_ed25519|credentials)$'
# ---------------------------------------------------------------------------------------------------------------------------------
say() { printf '%s\n' "$*"; }
failures=0
ok() { printf 'PASS %s\n' "$*"; }
bad() { printf 'FAIL %s\n' "$*"; failures=$((failures + 1)); }
note() { printf 'note %s\n' "$*"; }
die() { printf 'package-5090: %s\n' "$*" >&2; exit 2; }
field() { tr -d '\r' | sed -n "s/^$1 *= *\"\\(.*\\)\"/\\1/p" | head -1; }
lf() { tr -d '\r'; }
no_cr() { tr -d '\015' <"$1" | cmp -s - "$1"; }
command=${1:-}
[ -n "$command" ] || { sed -n '2,32p' "$0" | sed 's/^# \{0,1\}//'; exit 2; }
shift || true
out=dist/release-5090
target_dir=${CARGO_TARGET_DIR:-}
bin_dir=
no_build=0
allow_dirty=0
rehearse=0
epoch=
extra_unattended=
tarball_arg=
while [ $# -gt 0 ]; do
case "$1" in
--out) out=${2:?}; shift 2 ;;
--target-dir) target_dir=${2:?}; shift 2 ;;
--bin-dir) bin_dir=${2:?}; shift 2 ;;
--no-build) no_build=1; shift ;;
--allow-dirty) allow_dirty=1; shift ;;
--rehearse) rehearse=1; shift ;;
--epoch) epoch=${2:?}; shift 2 ;;
--unattended) extra_unattended="$extra_unattended ${2:?}"; shift 2 ;;
-*) die "unknown option $1" ;;
*) [ -z "$tarball_arg" ] || die "unexpected argument $1"; tarball_arg=$1; shift ;;
esac
done
for tool in sha256sum tar xz awk sed grep find sort tr cmp; do
command -v "$tool" >/dev/null 2>&1 || die "$tool is required"
done
# Where are we? The repo root is two levels above this script.
here=$(cd "$(dirname "$0")/../.." && pwd)
cd "$here"
mode=
if command -v git >/dev/null 2>&1 && git rev-parse --git-dir >/dev/null 2>&1; then
top=$(cd "$(git rev-parse --show-toplevel)" && pwd)
if [ "$top" = "$here" ]; then mode=repo; fi
fi
if [ -z "$mode" ]; then
if [ -f PROVENANCE.env ]; then mode=export; else die "neither a git checkout nor a staged tree with PROVENANCE.env here ($here); run 'stage-source' on the git host first"; fi
fi
case "$out" in /*) ;; *) out=$here/$out ;; esac
[ -n "$target_dir" ] || target_dir=$here/target
# --- facts about the tree: from git in repo mode, from PROVENANCE.env in export mode ----------------------------------------------
if [ "$mode" = export ]; then
. ./PROVENANCE.env
P_DIRTY=false
else
P_COMMIT=$(git rev-parse HEAD)
P_SHORT=$(git rev-parse --short=12 HEAD)
P_BRANCH=$(git rev-parse --abbrev-ref HEAD)
P_DESCRIBE=$(git describe --always --abbrev=12 2>/dev/null || echo unknown)
P_EPOCH=$(git log -1 --format=%ct HEAD)
P_TREE=$(git rev-parse 'HEAD^{tree}')
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then P_DIRTY=true; else P_DIRTY=false; fi
fi
release_version() { field version <crates/deploy/Cargo.toml; }
upstream_pin() { grep 'Upstream commit SHA' third_party/strata/UPSTREAM.md | head -1 | sed -n 's/.*`\([0-9a-f]\{40\}\)`.*/\1/p'; }
upstream_url() { grep 'Upstream repository URL' third_party/strata/UPSTREAM.md | head -1 | sed -n 's/.*| *\(https[^ |]*\) *|.*/\1/p'; }
ptx_sm120_list() { find crates/cuda-driver -name '*.ptx' -not -path '*/ptx-sm86/*' | LC_ALL=C sort; }
ptx_all_list() { find crates -name '*.ptx' | LC_ALL=C sort; }
# --- gates -------------------------------------------------------------------------------------------------------------------------
gate_tree() {
if [ "$P_DIRTY" = true ]; then
if [ "$allow_dirty" = 1 ]; then note "the tree has uncommitted changes: --allow-dirty, this package cannot be tagged"; else bad "the tree has uncommitted changes (commit them; --allow-dirty is for rehearsals only)"; fi
else
ok "tree is clean at $P_SHORT ($mode mode)"
fi
if [ "$mode" = export ]; then
if [ "${P_CHECK_FAILURES:-1}" = 0 ]; then ok "PROVENANCE.env: the git gates passed at staging time ($P_STAGED_UTC)"; else bad "PROVENANCE.env records ${P_CHECK_FAILURES:-?} failed gate(s) at staging time"; fi
fi
}
gate_versions() {
want=$(release_version)
[ -n "$want" ] || { bad "cannot read the version of crates/deploy"; return 0; }
mismatch=0
for manifest in crates/*/Cargo.toml control-plane/Cargo.toml desktop-core/Cargo.toml; do
[ -f "$manifest" ] || continue
name=$(field name <"$manifest")
version=$(field version <"$manifest")
[ -n "$name" ] && [ -n "$version" ] || continue
if [ "$version" != "$want" ]; then bad "$name is $version, the release is $want ($manifest)"; mismatch=1; fi
lock=$(lf <Cargo.lock | awk -v n="$name" '$0 == "name = \"" n "\"" { getline; sub(/^version = "/, ""); sub(/"$/, ""); print; exit }')
if [ "$lock" != "$version" ]; then bad "Cargo.lock has $name at '${lock:-nothing}', its manifest says $version"; mismatch=1; fi
done
if [ "$mismatch" = 0 ]; then ok "every workspace crate and Cargo.lock agree on version $want"; fi
tag_version=${RELEASE_TAG##*-v}
if [ "${want%.*}" = "$tag_version" ]; then ok "tag $RELEASE_TAG matches version $want"; else bad "tag $RELEASE_TAG does not match version $want"; fi
}
gate_toolchain() {
channel=$(field channel <rust-toolchain.toml)
if command -v rustc >/dev/null 2>&1; then
have=$(rustc --version | awk '{print $2}')
if [ "$have" = "$channel" ]; then ok "rustc $have is the pinned toolchain (rust-toolchain.toml)"; else bad "rustc is $have, rust-toolchain.toml pins $channel"; fi
else
note "rustc not found on this host (pinned: $channel); needed for build and package"
fi
}
gate_pin() {
pin=$(upstream_pin)
if [ "$pin" = "$RELEASE_STRATA_PIN" ]; then ok "Strata pin is $RELEASE_STRATA_PIN (third_party/strata/UPSTREAM.md)"; else bad "third_party/strata/UPSTREAM.md pins '${pin:-nothing}', this release is defined for $RELEASE_STRATA_PIN: moving the pin needs the checklist section 3"; fi
}
gate_ptx() {
total=$(ptx_all_list | wc -l | tr -d ' ')
crs=0
for f in $(ptx_all_list); do
if ! no_cr "$f"; then crs=$((crs + 1)); if [ "$crs" -le 5 ]; then printf ' CR byte in %s\n' "$f"; fi; fi
done
if [ "$crs" = 0 ]; then ok "none of the $total .ptx files contains a CR byte (byte scan of the files that will be built)"; else bad "$crs of $total .ptx files contain CR bytes: a CRLF checkout builds a different binary (use stage-source / git archive)"; fi
if grep -q '^\*\.ptx -text' .gitattributes; then ok ".gitattributes pins *.ptx to -text (no end-of-line conversion on any platform)"; else bad ".gitattributes lacks '*.ptx -text'"; fi
if [ "$mode" = repo ]; then
bad_eol=$(git ls-files --eol -- '*.ptx' | awk '$1 ~ /crlf|mixed/ || $2 ~ /crlf|mixed/ { n++ } END { print n + 0 }')
if [ "$bad_eol" = 0 ]; then ok "git ls-files --eol: every .ptx is LF (or binary) in the index and in the working tree"; else bad "git ls-files --eol reports $bad_eol .ptx files as CRLF or mixed"; fi
fi
if ptx_all_list | grep -q ' '; then bad "a .ptx path contains a space"; fi
note "sealed PTX: $(ptx_sm120_list | wc -l | tr -d ' ') sm_120 files ship with SHA-256 (share/leleka/ptx/sm_120/SHA256SUMS); the sm_86 companions are not shipped by this package"
}
gate_lf() {
# Text that is compiled into the binaries or copied into the archive must be LF. Windows checkouts with core.autocrlf=true are CRLF.
crlf=0
for f in Cargo.toml Cargo.lock rust-toolchain.toml deploy/rust-runtime/install.sh deploy/rust-runtime/profiles/rtx5090-32g.json deploy/rust-runtime/profiles/rtx3080-16g.json deploy/rust-runtime/leleka-daemon.service deploy/rust-runtime/leleka-inference.service deploy/rust-runtime/runtime.env.example crates/deploy/src/cli.rs crates/deploy/src/profile.rs; do
[ -f "$f" ] || continue
if ! no_cr "$f"; then crlf=$((crlf + 1)); printf ' CRLF: %s\n' "$f"; fi
done
if [ "$mode" = repo ]; then
all=$(git ls-files --eol | awk '$2 ~ /w\/crlf/' | wc -l | tr -d ' ')
fi
if [ "$crlf" = 0 ]; then
ok "the files copied into the archive or compiled in as text are LF"
elif [ "$command" = check ] || [ "$command" = stage-source ]; then
note "$crlf of those files, and $all tracked files in all, are CRLF in this working tree (core.autocrlf); build only from the LF export made by stage-source"
else
bad "$crlf files that are copied or compiled in are CRLF"
fi
}
gate_tracked_files() {
[ "$mode" = repo ] || { note "tracked-file and secret gates ran at staging time (PROVENANCE.env)"; return 0; }
hits=$(git ls-files | grep -E "$FORBIDDEN_NAME_RE" | grep -vE '^(benchmarks/(results|quality)/)' || true)
if [ -z "$hits" ]; then ok "no weights, keys, credentials, logs or capture-type files are tracked (benchmarks/ result tables and excluded; see the audit)"; else bad "forbidden file types are tracked:"; printf '%s\n' "$hits" | head -20; fi
big=$(git ls-tree -r -l HEAD | awk -v m="$MAX_TRACKED_BYTES" '$4 > m { print $4, $5 }')
if [ -z "$big" ]; then ok "no tracked file is larger than $MAX_TRACKED_BYTES bytes"; else bad "tracked files over $MAX_TRACKED_BYTES bytes:"; printf '%s\n' "$big"; fi
}
gate_secrets() {
[ "$mode" = repo ] || return 0
hits=$(git grep -InE -e "$SECRET_RE" -- . ':!*.lock' ':!crates/obs/src/redact.rs' 2>/dev/null | cut -d: -f1,2 | head -20 || true)
if [ -z "$hits" ]; then ok "no private key, cloud/VCS/HF token or JWT pattern in any tracked text file (matches are never printed; crates/obs/src/redact.rs is excluded: its unit tests hold synthetic token shapes for the redactor)"; else bad "secret-like patterns at (file:line):"; printf '%s\n' "$hits"; fi
}
gate_licence() {
if [ -f LICENSE ] || [ -f LICENSE.md ] || [ -f LICENSE-APACHE ]; then ok "the repository has a LICENSE file at its root"; else bad "no LICENSE file at the repository root (Cargo.toml declares Apache-2.0; the OWNER must confirm the licence and add the text; see spec node release/licence-and-secrets-audit-5090-v0.1.md)"; fi
unlicensed=
for manifest in crates/*/Cargo.toml control-plane/Cargo.toml desktop-core/Cargo.toml; do
[ -f "$manifest" ] || continue
if ! grep -qE '^license(\.workspace)? *=' "$manifest"; then unlicensed="$unlicensed $(field name <"$manifest")"; fi
done
if [ -z "$unlicensed" ]; then ok "every workspace crate declares a licence"; else bad "workspace crates without a licence field:$unlicensed (these build the shipped binaries leleka-api, leleka-inference, leleka-daemon, leleka-cli, leleka-seal-exec)"; fi
for f in third_party/strata/LICENSE third_party/strata/ggml/LICENSE third_party/strata/project-maya/LICENSE third_party/strata/project-maya/NOTICE.md control-plane/third_party/ggml/LICENSE crates/native-cpu-expert/LICENSE.ggml crates/native-cpu-expert/LICENSE.strata crates/quant-core/LICENSE-GGML crates/cpu-sys/NOTICE.colibri; do
[ -f "$f" ] || bad "third-party licence text missing: $f"
done
}
gate_profile() {
p=deploy/rust-runtime/profiles/rtx5090-32g.json
[ -f "$p" ] || { bad "$p is missing"; return 0; }
if grep -qiE 'TAIL_SKIP|LOSSY|APPROX|EXPERIMENTAL_' "$p" deploy/rust-runtime/runtime.env.example deploy/rust-runtime/*.service; then bad "a lossy or experimental switch is named in the profile or the unit templates"; else ok "the 5090 profile and unit templates enable no lossy or experimental switch"; fi
if grep -q 'Not a formally quality-gated profile' "$p"; then ok "profile description keeps the 'Not a formally quality-gated profile' wording (release notes repeat it)"; else bad "profile description lost the quality-gate wording"; fi
if grep -q 'weighted decode 129-130 tok/s' "$p"; then bad "the profile description still quotes 129-130 tok/s (real Codex sessions of 2026-10-17, older code); the release notes quote the paired 245k series. Reword or date it"; else ok "the profile description quotes no stale speed"; fi
}
run_check() {
failures=0
say "== release gates on $P_SHORT ($P_BRANCH, $mode mode) =="
gate_tree; gate_versions; gate_toolchain; gate_pin; gate_ptx; gate_lf; gate_tracked_files; gate_secrets; gate_licence; gate_profile
say "== $failures gate(s) failed =="
[ "$failures" = 0 ]
}
# --- stage-source (repo mode) --------------------------------------------------------------------------------------------------------
run_stage() {
[ "$mode" = repo ] || die "stage-source needs the git checkout"
[ "$P_DIRTY" = false ] || die "the tree has uncommitted changes; commit first (the export is HEAD)"
checks=0
run_check || checks=1
[ "$checks" = 0 ] || note "gates failed: the staged tree is still written (P_CHECK_FAILURES=$failures) so the build can be rehearsed, but 'package' refuses it"
dest=$out/src/release-5090-src-$P_SHORT
[ ! -e "$dest" ] || die "$dest exists; move it to garbage/ first"
mkdir -p "$dest"
git -c core.autocrlf=false -c core.eol=lf archive --format=tar HEAD | tar -x -C "$dest"
{
printf "P_COMMIT='%s'\nP_SHORT='%s'\nP_BRANCH='%s'\nP_DESCRIBE='%s'\nP_EPOCH='%s'\nP_TREE='%s'\n" "$P_COMMIT" "$P_SHORT" "$P_BRANCH" "$P_DESCRIBE" "$P_EPOCH" "$P_TREE"
printf "P_CHECK_FAILURES='%s'\nP_STAGED_UTC='%s'\n" "$failures" "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
} >"$dest/PROVENANCE.env"
crlf_after=$(cd "$dest" && for f in $(ptx_all_list); do no_cr "$f" || echo "$f"; done | wc -l | tr -d ' ')
[ "$crlf_after" = 0 ] || die "the export has $crlf_after .ptx files with CR bytes"
say "staged: $dest (commit $P_COMMIT)"
say "next, in WSL2 Ubuntu (or any Linux host with the pinned toolchain): cd '$dest' && sh scripts/release/package-5090.sh package --out <dir>"
[ "$checks" = 0 ]
}
# --- build -------------------------------------------------------------------------------------------------------------------------
run_build() {
command -v cargo >/dev/null 2>&1 || die "cargo not found (the 5090 server has none: build in WSL2/Linux, spec node deploy.md section 8)"
LELEKA_GIT_COMMIT=$P_COMMIT; export LELEKA_GIT_COMMIT
if [ "$P_DIRTY" = true ]; then LELEKA_GIT_DIRTY=1; else LELEKA_GIT_DIRTY=0; fi
export LELEKA_GIT_DIRTY
CARGO_TARGET_DIR=$target_dir; export CARGO_TARGET_DIR
say "building commit $LELEKA_GIT_COMMIT (dirty=$LELEKA_GIT_DIRTY) into $CARGO_TARGET_DIR"
# The same three commands as measured dt/bin-* binaries, minus --features sm86 (sm_120 only).
cargo build --release --locked -p leleka-engine-host --bin leleka-inference --bin leleka-daemon --bin leleka-cli --bin leleka-seal-exec
cargo build --release --locked -p leleka-control-plane --bin leleka-api
cargo build --release --locked -p leleka-deploy --bin leleka
}
# --- package -----------------------------------------------------------------------------------------------------------------------
json_escape() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; }
run_package() {
if ! run_check; then
[ "$rehearse" = 1 ] || die "the gates failed; fix them (--rehearse packages anyway, as a non-release, to test the assembly)"
note "--rehearse: continuing past $failures failed gate(s); this archive is not a release"
fi
if [ -z "$bin_dir" ]; then
[ "$no_build" = 1 ] || run_build
bin_dir=$target_dir/release
fi
for b in $BINARIES; do [ -f "$bin_dir/$b" ] || die "$bin_dir/$b is missing"; done
version=$(release_version)
dirty=false; suffix=
if [ "$P_DIRTY" = true ]; then dirty=true; suffix=-dirty; fi
if [ "$rehearse" = 1 ]; then suffix=$suffix-rehearsal; fi
[ -n "$epoch" ] || epoch=$P_EPOCH
name=leleka-$version-$P_SHORT$suffix-5090-linux-x86_64
[ ! -e "$out/stage/$name" ] || die "$out/stage/$name exists; move it to garbage/ (and add a line to garbage/LOG.txt) before packaging again"
mkdir -p "$out/stage/$name"
stage=$out/stage/$name
say "assembling $name (epoch $epoch)"
mkdir -p "$stage/bin" "$stage/share/leleka/profiles" "$stage/share/leleka/templates" "$stage/share/leleka/ptx/sm_120" "$stage/share/leleka/docs" "$stage/share/leleka/licenses" "$stage/share/leleka/unattended"
for b in $BINARIES; do cp "$bin_dir/$b" "$stage/bin/$b"; chmod 0755 "$stage/bin/$b"; done
cp deploy/rust-runtime/profiles/rtx5090-32g.json "$stage/share/leleka/profiles/"
for t in leleka-daemon.service leleka-inference.service runtime.env.example; do cp "deploy/rust-runtime/$t" "$stage/share/leleka/templates/"; done
cp deploy/rust-runtime/install.sh "$stage/install.sh"; chmod 0755 "$stage/install.sh"
for f in $(ptx_sm120_list); do cp "$f" "$stage/share/leleka/ptx/sm_120/$(basename "$f")"; done
( cd "$stage/share/leleka/ptx/sm_120" && LC_ALL=C ls | grep -v '^SHA256SUMS$' | xargs sha256sum >SHA256SUMS )
for d in $DOCS; do
[ -f "$d" ] || die "$d is missing"
rel=${d#third_party/strata/}; mkdir -p "$stage/share/leleka/docs/$(dirname "$rel")"; cp "$d" "$stage/share/leleka/docs/$rel"
done
[ ! -f LICENSE ] || cp LICENSE "$stage/LICENSE"
cp third_party/strata/LICENSE "$stage/share/leleka/licenses/strata-MIT.txt"
cp crates/deploy/data/expert-profile.NOTICE "$stage/share/leleka/licenses/expert-profile-NOTICE.txt"
cp crates/deploy/data/expert-profile.NOTICE "$stage/share/leleka/licenses/strata-expert-profile-NOTICE.txt"
cp third_party/strata/ggml/LICENSE "$stage/share/leleka/licenses/ggml-MIT.txt"
cp third_party/strata/project-maya/LICENSE "$stage/share/leleka/licenses/project-maya-MIT.txt"
cp third_party/strata/project-maya/NOTICE.md "$stage/share/leleka/licenses/project-maya-NOTICE.md"
cp crates/cpu-sys/NOTICE.colibri "$stage/share/leleka/licenses/colibri-NOTICE.txt"
[ ! -f deploy/release/third-party-crates-5090-v0.1.tsv ] || cp deploy/release/third-party-crates-5090-v0.1.tsv "$stage/share/leleka/licenses/rust-crates.tsv"
found_unattended=
for p in $UNATTENDED_DEFAULTS $extra_unattended; do
if [ -e "$p" ]; then cp -R "$p" "$stage/share/leleka/unattended/"; found_unattended="$found_unattended $p"; fi
done
if [ -n "$found_unattended" ]; then say "unattended files shipped (the owner installs them; nothing here does):$found_unattended"; else rmdir "$stage/share/leleka/unattended"; note "no unattended-operation files found (claude/unattended not merged yet?): the package carries only the two service templates"; fi
# Provenance and manifest.
cargo_lock=$(lf <Cargo.lock | sha256sum | awk '{print $1}')
rustc_v=$(rustc --version 2>/dev/null || echo unknown); cargo_v=$(cargo --version 2>/dev/null || echo unknown)
glibc_v=$(ldd --version 2>/dev/null | head -1 || echo unknown)
{
printf '{\n "schema_version": 1,\n "name": "leleka",\n "release": "%s",\n "version": "%s",\n "git_commit": "%s",\n "dirty": %s,\n "rehearsal": %s,\n "features": [],\n' "$RELEASE_TAG" "$version" "$P_COMMIT" "$dirty" "$([ "$rehearse" = 1 ] && echo true || echo false)"
printf ' "binaries": {\n'
first=1
for b in $BINARIES; do
[ "$first" = 1 ] || printf ',\n'
first=0
printf ' "%s": "%s"' "$b" "$(sha256sum "$stage/bin/$b" | awk '{print $1}')"
done
printf '\n },\n'
printf ' "target": "x86_64-unknown-linux-gnu, RTX 5090 (sm_120) serve path; the sm_86 companion PTX and the sm86 feature are NOT in this package",\n'
printf ' "strata_upstream_pin": "%s",\n' "$RELEASE_STRATA_PIN"
printf ' "built_with": {"rustc": "%s", "cargo": "%s", "glibc": "%s"},\n' "$(json_escape "$rustc_v")" "$(json_escape "$cargo_v")" "$(json_escape "$glibc_v")"
printf ' "runtime_requirements": {"os": "linux x86_64, glibc 2.39 or newer", "nvidia_driver_min": 595, "gpu": "RTX 5090 class, sm_120, 32 GB", "ram": "100 GiB total, 113 GB available at start (rtx5090-32g profile)", "cublas": "libcublas.so.12 and libcublasLt.so.12 (CUDA 12; leleka up downloads the pinned 12.9.1.4 redistributable unless the host has them)"},\n'
printf ' "ptx_sm120_files": %s,\n "created_utc": "%s"\n}\n' "$(ptx_sm120_list | wc -l | tr -d ' ')" "$(date -u -d "@$epoch" +%Y-%m-%dT%H:%M:%SZ)"
} >"$stage/MANIFEST.json"
{
printf '{\n "schema_version": 1,\n "release": "%s",\n "git_commit": "%s",\n "git_branch": "%s",\n "git_describe": "%s",\n "git_tree": "%s",\n "dirty": %s,\n' "$RELEASE_TAG" "$P_COMMIT" "$P_BRANCH" "$P_DESCRIBE" "$P_TREE" "$dirty"
printf ' "cargo_lock_sha256": "%s",\n "rust_toolchain": "%s",\n "built_in_mode": "%s",\n' "$cargo_lock" "$(field channel <rust-toolchain.toml)" "$mode"
printf ' "strata": {"upstream_url": "%s", "upstream_commit": "%s", "note": "the vendored Strata tree is not part of this release and was removed from the repository; see third_party/strata/UPSTREAM.md (pin, local patches, where the tree is in history)"}\n}\n' "$(upstream_url)" "$(upstream_pin)"
} >"$stage/PROVENANCE.json"
printf '%s\n' "$RELEASE_TAG" >"$stage/RELEASE"
# Content scan of what is about to be archived: nothing a release must not carry.
badfiles=$(cd "$stage" && find . -type f | sed 's|^\./||' | grep -E "$FORBIDDEN_NAME_RE|\.py$" | grep -v 'runtime\.env\.example$' || true)
[ -z "$badfiles" ] || { printf '%s\n' "$badfiles"; die "forbidden file types in the staging directory (above)"; }
if grep -rIlE -e "$SECRET_RE" "$stage" >/dev/null 2>&1; then die "a secret-like pattern is in the staging directory"; fi
if find "$stage" -type f -size +200000000c | grep -q .; then die "a file over 200 MB is in the staging directory"; fi
if find "$stage" -name '* *' | grep -q .; then die "a path with a space is in the staging directory"; fi
# SHA256SUMS over every file, then a deterministic archive (sorted names, fixed owner and mtime, one xz thread).
( cd "$stage" && find . -type f ! -name SHA256SUMS | sed 's|^\./||' | LC_ALL=C sort | xargs sha256sum >SHA256SUMS )
find "$stage" -exec touch -h -d "@$epoch" {} +
archive=$out/$name.tar.xz
[ ! -e "$archive" ] || die "$archive exists; move it to garbage/ first"
( cd "$out/stage" && tar --sort=name --format=gnu --owner=0 --group=0 --numeric-owner --mtime="@$epoch" -cf - "$name" ) | xz -6 -T1 -c >"$archive"
( cd "$out" && sha256sum "$name.tar.xz" >"$name.tar.xz.sha256" )
say "package: $archive"
say "sha256: $(awk '{print $1}' "$out/$name.tar.xz.sha256")"
say "bytes: $(wc -c <"$archive" | tr -d ' ') files: $(wc -l <"$stage/SHA256SUMS" | tr -d ' ') (+ SHA256SUMS) dirty=$dirty"
if [ "$dirty" = true ]; then say "NOT TAGGABLE: built from a dirty tree"; fi
if [ "$rehearse" = 1 ]; then say "NOT A RELEASE: --rehearse (gates were not enforced)"; fi
}
# --- verify ------------------------------------------------------------------------------------------------------------------------
run_verify() {
failures=0
[ -n "$tarball_arg" ] && [ -f "$tarball_arg" ] || die "usage: package-5090.sh verify TARBALL [--out DIR]"
case "$out" in "$here"/dist/release-5090) out=$(cd "$(dirname "$tarball_arg")" && pwd) ;; esac
base=$(basename "$tarball_arg" .tar.xz)
if [ -f "$tarball_arg.sha256" ]; then
want=$(awk '{print $1}' "$tarball_arg.sha256"); have=$(sha256sum "$tarball_arg" | awk '{print $1}')
if [ "$want" = "$have" ]; then ok "tarball digest matches $(basename "$tarball_arg").sha256"; else bad "tarball digest differs from $(basename "$tarball_arg").sha256"; fi
else
note "no .sha256 file next to the tarball; digest not compared"
fi
dest=$out/verify-$base
[ ! -e "$dest" ] || die "$dest exists; move it to garbage/ first"
mkdir -p "$dest"
tar -xJf "$tarball_arg" -C "$dest"
root=$dest/$base
[ -d "$root" ] || root=$(find "$dest" -mindepth 1 -maxdepth 1 -type d | head -1)
if ( cd "$root" && sha256sum --quiet -c SHA256SUMS ); then ok "SHA256SUMS: every file matches"; else bad "SHA256SUMS: a file does not match"; fi
( cd "$root" && sed 's/^[0-9a-f]* //' SHA256SUMS | LC_ALL=C sort ) >"$dest/.listed"
( cd "$root" && find . -type f ! -name SHA256SUMS | sed 's|^\./||' | LC_ALL=C sort ) >"$dest/.found"
extra=$(comm -13 "$dest/.listed" "$dest/.found")
if [ -z "$extra" ]; then ok "no file outside SHA256SUMS"; else bad "files not listed in SHA256SUMS:"; printf '%s\n' "$extra"; fi
badfiles=$(cd "$root" && find . -type f | sed 's|^\./||' | grep -E "$FORBIDDEN_NAME_RE|\.py$" | grep -v 'runtime\.env\.example$' || true)
if [ -z "$badfiles" ]; then ok "no weights, captures, credentials, logs or Python files in the package"; else bad "forbidden content:"; printf '%s\n' "$badfiles"; fi
if grep -rIlE -e "$SECRET_RE" "$root" >/dev/null 2>&1; then bad "a secret-like pattern is in the package"; else ok "no secret-like pattern in the package"; fi
for b in $BINARIES; do
m=$(sed -n "s/.*\"$b\": *\"\\([0-9a-f]*\\)\".*/\\1/p" "$root/MANIFEST.json" | head -1)
h=$(sha256sum "$root/bin/$b" | awk '{print $1}')
if [ -n "$m" ] && [ "$m" = "$h" ]; then ok "MANIFEST.json digest of bin/$b matches the file"; else bad "MANIFEST.json digest of bin/$b does not match the file"; fi
done
for f in "$root"/share/leleka/ptx/sm_120/*.ptx; do
if ! no_cr "$f"; then bad "CR byte in shipped $(basename "$f")"; fi
done
ok "shipped sm_120 PTX files were scanned for CR bytes"
if [ "$(uname -s)/$(uname -m)" = "Linux/x86_64" ] && [ -x "$root/bin/leleka" ]; then
ver=$("$root/bin/leleka" version 2>&1 || true)
printf '%s\n' "$ver" | sed 's/^/ /'
mc=$(sed -n 's/.*"git_commit": *"\([0-9a-f]*\)".*/\1/p' "$root/MANIFEST.json" | head -1)
case "$ver" in *"$mc"*"(clean)"*) ok "leleka version names the commit of MANIFEST.json and says clean" ;; *) bad "leleka version does not name the commit $mc of MANIFEST.json with (clean)" ;; esac
case "$ver" in *"$RELEASE_STRATA_PIN"*) ok "leleka version names the Strata pin $RELEASE_STRATA_PIN" ;; *) bad "leleka version does not name the Strata pin" ;; esac
else
note "not Linux x86_64: leleka version was not executed"
fi
say "unpacked at $root (left in place; move it to garbage/ when done)"
say "== $failures check(s) failed =="
[ "$failures" = 0 ]
}
case "$command" in
check) run_check ;;
stage-source) run_stage ;;
build) run_build ;;
package) run_package ;;
verify) run_verify ;;
*) die "unknown command $command (check | stage-source | build | package | verify)" ;;
esac