#!/bin/sh # License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. # cd3.sh -- the install CDs after the second: binary packages (Firefox, # Thunderbird, QEMU for the museum, PulseAudio, CUPS, ...), on as many CDs as # they need. # # usage: cd3.sh [stage] # stage only the directory build/cd3 with all the packages (for the DVD: # `make iso' stages it before build.sh; installdvd takes it into # CDBUILDEXTRA) # # Makronix installs from CDs on machines without a DVD drive: CD 1 carries the # system, CD 2 the `makronix' set (tools/cd2.sh), CD 3 and the next ones the # binary packages that the NetBSD project builds and Makronix does not patch # (docs/BUILD-VM.md, "Binary first"; tools/pkg-binaries.sh fetches them). # sysinst asks for them after the sets, when the user wants the extra programs, # copies them all into the target and installs them with the target's own # pkg_add (src/usr.sbin/sysinst/extras.c). A package on one CD can need # one on another, which is why the CDs are copied first. # # The packages are put on the CDs first-fit, biggest first, each CD up to the # size of a 700 MB CD (CDPKG_LIMIT, in bytes, to try another size); a build with # fewer packages is one CD, a build with more is CD 3, CD 4, ... Every CD is a # data CD, ISO 9660 with Rock Ridge, made with the build's own makefs, and has # # amd64/packages/All/*.tgz pkg_summary.gz its share of the packages # amd64/packages/disc "N M": package CD N of M # amd64/packages/top.list the names sysinst installs (packages.list: repo, # those that are here); the rest comes by dependency # # Written to RELEASEDIR/images/Makronix--amd64-cd3.iso (cd4, ...). Run # by `make iso' after cd2.sh, when build/packages/amd64/All exists (otherwise it # says so and does nothing). The DVD has all the packages in one directory with # "1 1" in `disc'. set -eu TOP=$(cd "$(dirname "$0")/.." && pwd) # This tool writes build/obj or releasedir: only inside the build lock. if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then echo "${0##*/}: run this through make or tools/build-lock.sh" >&2 exit 1 fi OBJ=$TOP/build/obj REL=$OBJ/releasedir PKGS=$TOP/build/packages/amd64/All STAGE=$TOP/build/cd3 # a CD holds 700 MB; the image must not be bigger than the medium LIMIT=${CDPKG_LIMIT:-737280000} # what the file system and the summary need on top of the packages MARGIN=12000000 FIRSTCD=3 die() { echo "cd3: $*" >&2 exit 1 } rm -rf "$STAGE" "$TOP"/build/cd3-[0-9]* # no package wanted (no "repo" or "fetch" line in packages.list): none on the media if [ -z "$("$TOP/tools/pkglist.sh" repo)$("$TOP/tools/pkglist.sh" fetch)" ]; then echo "cd3: packages.list names no repo or fetch package: no packages on the media" exit 0 fi if [ ! -s "$PKGS/pkg_summary.gz" ]; then echo "cd3: no binary packages in ${PKGS#$TOP/} (make userland, tools/pkg-binaries.sh): no packages on the media" exit 0 fi summary=$PKGS/pkg_summary.gz # The lists of a medium's packages directory DIR (sysinst reads them, # src/usr.sbin/sysinst/extras.c): # # top.list the names of the wanted packages (repo, fetch, games) # desktop.list the files of this medium that the desktop needs: the # packages of kind repo and fetch and their dependencies # games.list the same for Makronix Games (kind games) # museum.list the same for Makronix Museum (kind museum) # # The closure is taken by PKGPATH through the summary (the name of a package # is not the last part of its path: net/samba4 is samba-4.x), in dependency # order; a list holds only the files that are on this medium -- the others # are on an earlier CD and installed already (the packing below). closure() { zcat "$summary" | awk -v want="$1" ' function base(s) { sub(/[<>\[{].*/, "", s); sub(/-[0-9][^-]*$/, "", s) sub(/-$/, "", s); return s } function visit(p, i, k, d) { if (seen[p]++) return k = split(deps[p], d, " ") for (i = 1; i <= k; i++) if (base(d[i]) in byname) visit(byname[base(d[i])]) print file[p] } BEGIN { k = split(want, w, " "); for (i = 1; i <= k; i++) ok[w[i]] = 1 } /^PKGNAME=/ { name = substr($0, 9); byname[base(name)] = name } /^PKGPATH=/ { if (substr($0, 9) in ok) top[++t] = name } /^DEPENDS=/ { deps[name] = deps[name] " " substr($0, 9) } /^FILE_NAME=/ { file[name] = substr($0, 11) } END { for (i = 1; i <= t; i++) visit(top[i]) } ' } lists() { # "bin" packages are in the makronix set (installed into the sysroot), not # on the media CDs as separate packages (t0242): exclude them from the # desktop repository on the media. bin=$("$TOP/tools/pkglist.sh" bin | tr '\n' ' ') desk=$({ "$TOP/tools/pkglist.sh" repo; "$TOP/tools/pkglist.sh" fetch; } | \ awk -v b="$bin" 'BEGIN{n=split(b,a," "); for(i=1;i<=n;i++) if(a[i]!="") drop[a[i]]=1} !($0 in drop)' | tr '\n' ' ') games=$("$TOP/tools/pkglist.sh" games | tr '\n' ' ') museum=$("$TOP/tools/pkglist.sh" museum | tr '\n' ' ') closure "$desk" | while read -r f; do if [ -f "$1/All/$f" ]; then echo "$f"; fi done > "$1/desktop.list" closure "$games" | while read -r f; do if [ -f "$1/All/$f" ]; then echo "$f"; fi done > "$1/games.list" closure "$museum" | while read -r f; do if [ -f "$1/All/$f" ]; then echo "$f"; fi done > "$1/museum.list" zcat "$summary" | awk -v want="$desk $games $museum" ' BEGIN { n = split(want, w, " "); for (i = 1; i <= n; i++) ok[w[i]] = 1 } /^PKGNAME=/ { name = substr($0, 9) } /^PKGPATH=/ { if (substr($0, 9) in ok) { sub(/-[0-9][^-]*$/, "", name); print name } } ' | sort -u > "$1/top.list" [ -s "$1/top.list" ] || die "no wanted package is in ${PKGS#$TOP/}" } link() { ln "$1" "$2" 2>/dev/null || cp -p "$1" "$2" } # --- the directory for the DVD: all of them --- mkdir -p "$STAGE/amd64/packages/All" # "bin" packages are in the makronix set, not on the media (t0242). bin=$("$TOP/tools/pkglist.sh" bin | tr '\n' ' ') # only what the summary names and that belongs on the media; bin are excluded # so they are not shipped twice. build/packages/amd64/All keeps older files. zcat "$summary" | awk -v b="$bin" ' BEGIN { n = split(b, a, " "); for (i = 1; i <= n; i++) if (a[i] != "") drop[a[i]] = 1 } /^PKGNAME=/ { name = substr($0, 9) } /^PKGPATH=/ { path = substr($0, 9) } /^FILE_NAME=/ { file = substr($0, 11) } /^$/ { if (path != "" && !(path in drop)) print file; name = ""; path = ""; file = "" } ' | while read -r f; do [ -n "$f" ] || continue link "$PKGS/$f" "$STAGE/amd64/packages/All/$f" done link "$PKGS/pkg_summary.gz" "$STAGE/amd64/packages/All/pkg_summary.gz" # the signify signature of the package list signs the repository (make iso, # tools/sign-release.sh); it travels next to the summary if [ -f "$PKGS/pkg_summary.gz.sig" ]; then link "$PKGS/pkg_summary.gz.sig" \ "$STAGE/amd64/packages/All/pkg_summary.gz.sig" fi lists "$STAGE/amd64/packages" echo "1 1" > "$STAGE/amd64/packages/disc" if [ "${1:-}" = stage ]; then echo "cd3: staged ${STAGE#$TOP/}" exit 0 fi # --- the CDs --- MAKEFS=$(ls "$OBJ"/tooldir.*/bin/nbmakefs 2>/dev/null | head -1) [ -x "$MAKEFS" ] || die "no nbmakefs in $OBJ/tooldir.*/bin" # the version is in the name of the first CD cd1=$(ls "$REL"/images/Makronix-*-amd64.iso 2>/dev/null | head -1) [ -n "$cd1" ] || die "no first CD in $REL/images (build.sh iso-image first)" ver=${cd1##*/Makronix-} ver=${ver%-amd64.iso} # ISOs of an earlier run with more CDs would be stale rm -f "$REL"/images/Makronix-$ver-amd64-cd[3-9].iso ssize=$(wc -c < "$summary" | tr -d ' ') cap=$((LIMIT - MARGIN - ssize)) tmp=$(mktemp "${TMPDIR:-/tmp}/cd3.XXXXXX") trap 'rm -f "$tmp"' EXIT # Dependencies first, then filled CD after CD in that order: every package # finds what it needs on its own CD or on an earlier one, so sysinst installs # one CD after the other straight from the medium (extras.c) and never needs # a CD back (Konrad, 2026-11-13). The order is a depth-first walk over # DEPENDS of the summary; a pattern is resolved by the base name of the # package (one version of each is in the repository). "CD-index file" zcat "$summary" | awk -v dir="$PKGS" -v cap="$cap" ' function base(s) { sub(/[<>\[{].*/, "", s); sub(/-[0-9][^-]*$/, "", s) sub(/-$/, "", s); return s } function visit(p, i, k, d) { if (seen[p]++) return k = split(deps[p], d, " ") for (i = 1; i <= k; i++) if (base(d[i]) in byname) visit(byname[base(d[i])]) order[++n] = p } /^PKGNAME=/ { name = substr($0, 9); names[++m] = name byname[base(name)] = name } /^DEPENDS=/ { deps[name] = deps[name] " " substr($0, 9) } /^FILE_NAME=/ { file[name] = substr($0, 11) } /^FILE_SIZE=/ { size[name] = substr($0, 11) } END { for (j = 1; j <= m; j++) visit(names[j]) cd = 1 for (j = 1; j <= n; j++) { p = order[j] if (used > 0 && used + size[p] > cap) { cd++; used = 0 } used += size[p] print cd, dir "/" file[p] } }' > "$tmp" ncd=$(awk '{ if ($1 > m) m = $1 } END { print m + 0 }' "$tmp") [ "$ncd" -ge 1 ] || die "no package to put on a CD" i=1 while [ $i -le "$ncd" ]; do d=$TOP/build/cd3-$i rm -rf "$d" mkdir -p "$d/amd64/packages/All" awk -v i="$i" '$1 == i { print $2 }' "$tmp" | while read -r f; do link "$f" "$d/amd64/packages/All/${f##*/}" done link "$summary" "$d/amd64/packages/All/pkg_summary.gz" if [ -f "$summary.sig" ]; then link "$summary.sig" "$d/amd64/packages/All/pkg_summary.gz.sig" fi lists "$d/amd64/packages" echo "$i $ncd" > "$d/amd64/packages/disc" cdno=$((FIRSTCD + i - 1)) OUT=$REL/images/Makronix-$ver-amd64-cd$cdno.iso rm -f "$OUT" "$MAKEFS" -t cd9660 -o rockridge,label=MAKRONIX_INSTALL_CD$cdno,publisher=Makronix "$OUT" "$d" size=$(wc -c < "$OUT" | tr -d ' ') echo "cd3: ${OUT#$TOP/}: package CD $i of $ncd, $(du -h "$OUT" | cut -f1), $size bytes" [ "$size" -le "$LIMIT" ] || echo "cd3: WARNING: $size bytes do not fit on the CD (limit $LIMIT)" rm -rf "$d" i=$((i + 1)) done