#!/bin/bash # Build our own arm64 packages into debs/, in an arm64 Ubuntu 26.04 build # chroot, on the Altra: run anywhere but on arm64 it hands over to # tools/altra. # # /media/documents/Patrick/1PMagic_arm/pkgs/build-debs [NAME...] # # With no NAME, every package here that has a build.sh. pkgs/NAME/build.sh # runs inside the chroot as root, with pkgs/NAME at /src (read-only), an # empty /work and an empty /out. What it leaves in /out replaces # debs/NAME/. The chroot is /var/tmp/pmarm-pkgbuild/chroot, made when it is # missing; it holds nothing that cannot be made again. PMB_CHROOT names # another one (a copy), so a long build can run beside the others. set -euo pipefail TOP=$(dirname "$(dirname "$(readlink -f "$0")")") # debs/ and the build chroot live on the Altra (notes/altra.md). if [ "$(uname -m)" != aarch64 ]; then exec "$TOP/tools/altra" build-debs "$@" fi PKGS=$TOP/pkgs DEBS=$TOP/debs BASE=/var/tmp/pmarm-pkgbuild CH=${PMB_CHROOT:-$BASE/chroot} SUITE=resolute MIRROR=http://ports.ubuntu.com/ubuntu-ports COMPONENTS="main restricted universe multiverse" die() { echo "build-debs: $*" >&2; exit 1; } say() { echo "build-debs: $(date '+%H:%M:%S') $*"; } [ "$(id -u)" -eq 0 ] || die "run it as root" command -v mmdebstrap >/dev/null || die "mmdebstrap is not installed" if [ $# -eq 0 ]; then set -- $(cd "$PKGS" && for d in */; do [ -x "$d/build.sh" ] && echo "${d%/}"; done) fi for name in "$@"; do [ -x "$PKGS/$name/build.sh" ] || die "$PKGS/$name/build.sh is missing" done if findmnt -rn -o TARGET | grep -q "^$CH\(/\|$\)"; then die "something is mounted under $CH (another build-debs running?)" fi if [ ! -x "$CH/usr/bin/dpkg-buildpackage" ]; then say "making the build chroot $CH" rm -rf --one-file-system "$CH" mkdir -p "$BASE" mmdebstrap --mode=root --variant=buildd --architectures=arm64 \ --keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg \ --include=debhelper,devscripts,fakeroot,cmake,pkgconf,equivs,quilt,lzip,ca-certificates,dpkg-dev \ --dpkgopt='path-exclude=/usr/share/man/*' \ --dpkgopt='path-exclude=/usr/share/doc/*' \ "$SUITE" "$CH" \ "deb $MIRROR $SUITE $COMPONENTS" \ "deb $MIRROR $SUITE-updates $COMPONENTS" \ "deb $MIRROR $SUITE-security $COMPONENTS" \ "deb-src $MIRROR $SUITE $COMPONENTS" \ "deb-src $MIRROR $SUITE-updates $COMPONENTS" \ "deb-src $MIRROR $SUITE-security $COMPONENTS" fi unmount_all() { local m for m in $(findmnt -rn -o TARGET | grep "^$CH/" | sort -r); do umount -l "$m" 2>/dev/null || true done } trap unmount_all EXIT for name in "$@"; do say "$name: building" rm -rf --one-file-system "$BASE/work-$name" "$BASE/out-$name" mkdir -p "$BASE/work-$name" "$BASE/out-$name" "$CH/src" "$CH/work" "$CH/out" cp /etc/resolv.conf "$CH/etc/resolv.conf" mount -t proc proc "$CH/proc" mount -t sysfs sysfs "$CH/sys" mount --rbind /dev "$CH/dev" mount --make-rslave "$CH/dev" mount --bind "$PKGS/$name" "$CH/src" mount -o remount,bind,ro "$CH/src" mount --bind "$BASE/work-$name" "$CH/work" mount --bind "$BASE/out-$name" "$CH/out" rc=0 chroot "$CH" env -i PATH=/usr/sbin:/usr/bin:/sbin:/bin HOME=/root LANG=C.UTF-8 \ DEBIAN_FRONTEND=noninteractive DEBFULLNAME="Parted Magic" \ DEBEMAIL="sales@partedmagic.com" JOBS="$(nproc)" \ bash -eu /src/build.sh > "$BASE/$name.log" 2>&1 || rc=$? unmount_all if [ "$rc" -ne 0 ]; then tail -20 "$BASE/$name.log" >&2 die "$name failed (rc $rc); the log is $BASE/$name.log" fi ls "$BASE/out-$name"/*.deb >/dev/null 2>&1 || die "$name left no .deb in /out" rm -rf "$DEBS/$name" mkdir -p "$DEBS/$name" cp -p "$BASE/out-$name"/*.deb "$DEBS/$name/" cp -p "$BASE/$name.log" "$DEBS/$name/build.log" say "$name: $(ls "$DEBS/$name"/*.deb | wc -l) packages in $DEBS/$name" done