Files
alkane-os/ci/make-afw.sh
T
noahandDeepSeek Harness 553f6a04fb Add a full-OS .afw bundle and strict CI gate
Replace the release-tree producer with a board-aware schema-2 manifest,
fixed-order ustar packing, optional Ed25519 signing, and a checker that
rejects a wrong board or arch, a missing or oversized image, a bootloader
member under preserve, a hash or size mismatch, and a traversal member.
Document the format and add offline fixtures for every refusal.

Co-Authored-By: DeepSeek Harness <noreply@deepseek.com>
2026-11-04 14:31:35 -06:00

143 lines
4.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build a full-OS .afw install bundle for one board family.
#
# A .afw is a strict POSIX ustar with members in this exact order:
# manifest.json
# manifest.json.sig (only for an Ed25519-signed bundle)
# payload/<image>... (in manifest.images order)
#
# The manifest carries the board, arch, SDK/OS revisions, every image's size
# and SHA-256, the partition plan, bootloader_policy, the network recovery path
# and a liveness marker. ci/check-afw.py verifies the finished bundle before
# this script returns success. There is no default signing key: unsigned is
# allowed only with an explicit --allow-unsigned, and that is bench-only.
#
# usage:
# ci/make-afw.sh --board cv1835 --version 0.1.0 \
# --input build/out/cv1835 --sdk-dir ../alkane-sdk \
# --sdk-revision "$(git -C ../alkane-sdk rev-parse HEAD)" \
# --os-revision "$(git rev-parse HEAD)" \
# --output dist [--plan plan.json] [--signing-key FILE] [--allow-unsigned]
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BOARD=
VERSION=
INPUT=
OUTPUT=dist
PLAN=
SIGNING_KEY=
SDK_DIR=
SDK_REVISION=
OS_REVISION=
KERNEL_VERSION=
ALLOW_UNSIGNED=0
usage() {
sed -n '2,30p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
exit "${1:-1}"
}
while [ "$#" -gt 0 ]; do
case "$1" in
--board) BOARD=${2:?--board needs a value}; shift 2 ;;
--version) VERSION=${2:?--version needs a value}; shift 2 ;;
--input) INPUT=${2:?--input needs a value}; shift 2 ;;
--output) OUTPUT=${2:?--output needs a value}; shift 2 ;;
--plan) PLAN=${2:?--plan needs a value}; shift 2 ;;
--signing-key) SIGNING_KEY=${2:?--signing-key needs a value}; shift 2 ;;
--sdk-dir) SDK_DIR=${2:?--sdk-dir needs a value}; shift 2 ;;
--sdk-revision) SDK_REVISION=${2:?--sdk-revision needs a value}; shift 2 ;;
--os-revision) OS_REVISION=${2:?--os-revision needs a value}; shift 2 ;;
--kernel-version) KERNEL_VERSION=${2:?--kernel-version needs a value}; shift 2 ;;
--allow-unsigned) ALLOW_UNSIGNED=1; shift ;;
-h|--help) usage 0 ;;
*) echo "make-afw: unknown argument: $1" >&2; usage 2 ;;
esac
done
[ -n "$BOARD" ] || { echo "make-afw: --board is required" >&2; usage 2; }
[ -n "$VERSION" ] || { echo "make-afw: --version is required" >&2; usage 2; }
[ -n "$INPUT" ] || { echo "make-afw: --input is required" >&2; usage 2; }
[ -d "$INPUT" ] || { echo "make-afw: input directory not found: $INPUT" >&2; exit 1; }
if [ -z "$SDK_REVISION" ] && [ -n "$SDK_DIR" ]; then
SDK_REVISION=$(git -C "$SDK_DIR" rev-parse HEAD)
fi
if [ -z "$OS_REVISION" ]; then
OS_REVISION=$(git -C "$ROOT" rev-parse HEAD)
fi
[ -n "$SDK_REVISION" ] || { echo "make-afw: --sdk-revision or --sdk-dir is required" >&2; exit 1; }
mkdir -p "$OUTPUT"
OUTPUT="$(cd "$OUTPUT" && pwd)"
WORK=$(mktemp -d "${TMPDIR:-/tmp}/make-afw.XXXXXX")
trap 'rm -rf "$WORK"' EXIT
MANIFEST_ARGS=(
--board "$BOARD"
--version "$VERSION"
--input "$INPUT"
--staging "$WORK"
--sdk-revision "$SDK_REVISION"
--os-revision "$OS_REVISION"
--os-dir "$ROOT"
)
[ -n "$PLAN" ] && MANIFEST_ARGS+=(--plan "$PLAN")
[ -n "$SIGNING_KEY" ] && MANIFEST_ARGS+=(--signing-key "$SIGNING_KEY")
[ -n "$KERNEL_VERSION" ] && MANIFEST_ARGS+=(--kernel-version "$KERNEL_VERSION")
python3 "$ROOT/ci/afw_manifest.py" "${MANIFEST_ARGS[@]}" >/dev/null
ARCH=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["arch"])' "$WORK/manifest.json")
NAME="alkane-os-$VERSION-$BOARD-$ARCH.afw"
MEMBERS="$WORK/members.txt"
python3 - "$WORK" >"$MEMBERS" <<'PY'
import json
import sys
from pathlib import Path
stage = Path(sys.argv[1])
manifest = json.loads((stage / "manifest.json").read_text())
members = ["manifest.json"]
if manifest["signature"]["member"]:
members.append(manifest["signature"]["member"])
members.extend(image["file"] for image in manifest["images"])
for member in members:
if not (stage / member).is_file():
raise SystemExit(f"staged member is missing: {member}")
print("\n".join(members))
PY
MTIME=()
if [ -n "${SOURCE_DATE_EPOCH:-}" ]; then
MTIME=(--mtime="@${SOURCE_DATE_EPOCH}")
fi
tar --format=ustar --owner=0 --group=0 --numeric-owner "${MTIME[@]}" \
--create --file "$OUTPUT/$NAME" -C "$WORK" -T "$MEMBERS"
GOT=$(tar -tf "$OUTPUT/$NAME")
WANT=$(cat "$MEMBERS")
if [ "$GOT" != "$WANT" ]; then
echo "make-afw: FATAL: member order is wrong" >&2
printf 'expected:\n%s\nactual:\n%s\n' "$WANT" "$GOT" >&2
rm -f "$OUTPUT/$NAME"
exit 1
fi
CHECK=(--expect-board "$BOARD")
if [ -f "$WORK/manifest.pub" ]; then
CHECK+=(--public-key "$(cat "$WORK/manifest.pub")")
elif [ "$ALLOW_UNSIGNED" -eq 1 ]; then
CHECK+=(--allow-unsigned)
else
echo "make-afw: unsigned bundle needs --allow-unsigned (bench-only)" >&2
rm -f "$OUTPUT/$NAME"
exit 1
fi
python3 "$ROOT/ci/check-afw.py" "$OUTPUT/$NAME" "${CHECK[@]}"
printf '%s\n' "$OUTPUT/$NAME"