Files
makronix/tools/pkg-binaries.sh
T
lotherkandClaude Sonnet 5.5 6c714a0ea7 tools, Makefile, package lists: media (CD 2, CD 3), install tests, build VM, source sets, binary packages
make iso now also writes CD 2 (makronix set) and CD 3 (binary packages); make sourcesets/isosrc make the source sets and the DVD with them. tools: cd2.sh cd3.sh, install-simple.sh install-cgd.sh (end-to-end tests on the serial console), vmsh.sh devvm.sh (QEMU sessions, the kept build VM), vm-pkgbuild.sh vm-pkgcollect.sh (native pkgsrc builds), pkg-binaries.sh (the project's binary packages), host-nfs-setup.sh (NFS for the build VM; loopback-only through an nftables rule), makronix-distfiles.sh makronix-pins.sh msrc-stage.sh. Package lists: common, per platform, and binary.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 12:53:21 +00:00

163 lines
5.5 KiB
Bash
Executable File

#!/bin/sh
# pkg-binaries.sh -- binary packages from the NetBSD project, for the media.
#
# usage: pkg-binaries.sh [-a amd64|aarch64] [-b BRANCH] list|fetch
#
# list the packages and everything they need at run time, with sizes
# fetch put them into build/packages/ARCH/All, with a pkg_summary.gz
#
# Policy (docs/BUILD-VM.md, "Binary first"): where the NetBSD project publishes
# a binary package for the platform and Makronix does not patch the package, the
# binary is taken instead of a build: firefox, thunderbird, qemu are hours of
# compiling (rust, llvm, ...) for nothing a patch of ours changes. What
# Makronix patches or what is not published is built (tools/vm-pkgbuild.sh).
#
# What is wanted is named in tracked lists, one package name (PKGBASE, not the
# path) a line, `#' comments:
# packages.binary.list every platform
# packages.binary.ARCH.list one platform (amd64, aarch64)
# A package the project does not publish for the platform is reported and
# skipped, not an error: thunderbird has no aarch64 binary in 11.0_2026Q3.
#
# Where they come from: cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/<arch>/<BRANCH>
# -- the quarterly branch built for NetBSD 11.0; Makronix is NetBSD 11.99.9, the
# binaries of the release branch are what the project offers for it. The
# dependencies are resolved over the repository's own pkg_summary.gz with
# pkg_admin pmatch (the pkgsrc bootstrap's, build/pkg/sbin), the way pkg_add
# would pick them; the newest package that matches wins. The archives are
# checked against FILE_SIZE of the summary (it carries no checksum for them).
#
# The result is a pkgsrc binary repository: `pkg_add' with PKG_PATH pointing at
# the directory installs from it without a network.
set -u
set -f
TOP=$(cd "$(dirname "$0")/.." && pwd)
ARCH=amd64
BRANCH=${BRANCH:-11.0_2026Q3}
BASE=${PKGREPO:-https://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD}
PKGADMIN=${PKGADMIN:-$TOP/build/pkg/sbin/pkg_admin}
die()
{
echo "pkg-binaries: $*" >&2
exit 1
}
while getopts a:b: ch; do
case $ch in
a) ARCH=$OPTARG ;;
b) BRANCH=$OPTARG ;;
*) die "usage: ${0##*/} [-a amd64|aarch64] [-b BRANCH] list|fetch" ;;
esac
done
shift $((OPTIND - 1))
[ $# -eq 1 ] || die "usage: ${0##*/} [-a amd64|aarch64] [-b BRANCH] list|fetch"
CMD=$1
case $ARCH in
amd64) PARCH=x86_64 ;;
aarch64) PARCH=aarch64 ;;
*) die "unknown platform $ARCH" ;;
esac
[ -x "$PKGADMIN" ] || die "no pkg_admin at $PKGADMIN (the pkgsrc bootstrap, AGENTS.md)"
REPO=$BASE/$PARCH/$BRANCH/All
OUT=$TOP/build/packages/$ARCH
mkdir -p "$OUT/All" || exit 1
tmp=$(mktemp -d "${TMPDIR:-/tmp}/pkgbin.XXXXXX") || exit 1
trap 'rm -rf "$tmp"' EXIT
SUMMARY=$OUT/pkg_summary.repo.gz
[ -s "$SUMMARY" ] || curl -s -f -m 300 -o "$SUMMARY" "$REPO/pkg_summary.gz" ||
die "cannot fetch $REPO/pkg_summary.gz"
# one line a package: name <TAB> size <TAB> file <TAB> dependency patterns
zcat "$SUMMARY" | awk '
/^PKGNAME=/ { n = substr($0, 9); dep = ""; file = ""; size = 0 }
/^FILE_NAME=/ { file = substr($0, 11) }
/^FILE_SIZE=/ { size = substr($0, 11) }
/^DEPENDS=/ { dep = dep substr($0, 9) " " }
/^$/ { if (n != "") printf "%s\t%s\t%s\t%s\n", n, size, file, dep; n = "" }
' > "$tmp/index"
# the base name of a pattern or a package name: up to the first -<digit>, or
# the first of >=<[{ that starts the version part
base_of()
{
echo "$1" | sed -e 's/[<>\[{].*//' -e 's/-[0-9].*//' -e 's/-$//'
}
# the newest package of the index that matches the pattern
best()
{
b=$(base_of "$1")
awk -F'\t' -v b="$b" '{ n = $1; sub(/-[0-9].*/, "", n); if (n == b) print $1 }' "$tmp/index" |
while read -r cand; do
"$PKGADMIN" pmatch "$1" "$cand" 2>/dev/null && echo "$cand"
done | LC_ALL=C sort -V | tail -1
}
# the wanted names
: > "$tmp/want"
for f in "$TOP/packages.binary.list" "$TOP/packages.binary.$ARCH.list"; do
[ -f "$f" ] && grep -v '^#' "$f" | grep -v '^[[:space:]]*$' >> "$tmp/want"
done
[ -s "$tmp/want" ] || die "no packages named (packages.binary*.list)"
# closure
: > "$tmp/done"
queue=$(cat "$tmp/want")
missing=
while [ -n "$queue" ]; do
set -- $queue
pat=$1
shift
queue="$*"
pkg=$(best "$pat")
if [ -z "$pkg" ]; then
missing="$missing $pat"
continue
fi
grep -qx "$pkg" "$tmp/done" && continue
echo "$pkg" >> "$tmp/done"
deps=$(awk -F'\t' -v p="$pkg" '$1 == p { print $4 }' "$tmp/index")
queue="$queue $deps"
done
sort -u "$tmp/done" > "$tmp/pkgs"
total=0
while read -r p; do
s=$(awk -F'\t' -v p="$p" '$1 == p { print $2 }' "$tmp/index")
total=$((total + s))
[ "$CMD" = list ] && printf '%12d %s\n' "$s" "$p"
done < "$tmp/pkgs"
echo "pkg-binaries: $ARCH $BRANCH: $(wc -l < "$tmp/pkgs" | tr -d ' ') packages, $total bytes" >&2
[ -n "$missing" ] && echo "pkg-binaries: not published for $ARCH:$missing" >&2
[ "$CMD" = fetch ] || exit 0
fail=0
while read -r p; do
file=$(awk -F'\t' -v p="$p" '$1 == p { print $3 }' "$tmp/index")
size=$(awk -F'\t' -v p="$p" '$1 == p { print $2 }' "$tmp/index")
dst=$OUT/All/$file
have=$({ wc -c < "$dst"; } 2>/dev/null | tr -d ' ')
if [ "${have:-0}" != "$size" ]; then
curl -s -f -m 1800 -o "$dst.part" "$REPO/$file" || { echo "FAIL: $file"; fail=1; continue; }
mv "$dst.part" "$dst"
have=$(wc -c < "$dst" | tr -d ' ')
[ "$have" = "$size" ] || { echo "FAIL: $file is $have bytes, want $size"; fail=1; }
fi
done < "$tmp/pkgs"
# the summary of what is here: the records of these packages only
zcat "$SUMMARY" | awk -v list="$tmp/pkgs" '
BEGIN { while ((getline l < list) > 0) want[l] = 1 }
/^PKGNAME=/ { keep = (substr($0, 9) in want) }
keep
' | gzip -9n > "$OUT/All/pkg_summary.gz"
[ $fail -eq 0 ] || die "some packages failed"
echo "pkg-binaries: $OUT/All ($(du -sh "$OUT/All" | cut -f1))"