consmirror.c: the BSD notice is replaced (Makronix's own file). Files with changes of other sessions pending are left for their commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
60 lines
2.4 KiB
Bash
60 lines
2.4 KiB
Bash
#!/bin/sh
|
|
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
#
|
|
# Build the root file system of the Void (glibc) base for one device, as a tar:
|
|
# Void's pinned ROOTFS (checked against its sha256), plus base/void/packages
|
|
# from the repository, plus the runit services. No root: everything runs in a
|
|
# user namespace (unshare --map-root-user --map-auto, with subuid/subgid); aarch64 code runs through
|
|
# qemu-user-binfmt.
|
|
#
|
|
# Usage: mkrootfs-void.sh DEVICEDIR OUT.tar
|
|
|
|
set -eu
|
|
. "$(dirname "$0")/lib.sh"
|
|
|
|
[ $# -eq 2 ] || { echo "usage: $0 DEVICEDIR OUT.tar" >&2; exit 2; }
|
|
load_device "$1"
|
|
out=$(cd "$(dirname "$2")" && pwd)/$(basename "$2")
|
|
|
|
[ "$ARCH" = arm64 ] || die "the Void base is built for arm64 only so far (device: $ARCH)"
|
|
. "$ROOT/base/void/base.conf"
|
|
|
|
dl=$ROOT/build/downloads
|
|
mkdir -p "$dl"
|
|
if [ ! -f "$dl/$VOID_ROOTFS" ]; then
|
|
curl -fsSL -o "$dl/$VOID_ROOTFS.part" "$VOID_ROOTFS_URL"
|
|
mv "$dl/$VOID_ROOTFS.part" "$dl/$VOID_ROOTFS"
|
|
fi
|
|
echo "$VOID_ROOTFS_SHA256 $dl/$VOID_ROOTFS" | sha256sum -c - >/dev/null ||
|
|
die "$VOID_ROOTFS does not match its pinned sha256"
|
|
|
|
pkgs=$(sed 's/#.*//' "$ROOT/base/void/packages" | tr -s ' \n' ' ')
|
|
work=$ROOT/build/void-rootfs-work.$$
|
|
mkdir -p "$work"
|
|
# the tree holds files of the subuid range: only the namespace can delete them
|
|
trap 'unshare --map-root-user --map-auto rm -rf "$work"' EXIT
|
|
lock=${out%.tar}.lock
|
|
|
|
export VOID_ROOTFS_FILE="$dl/$VOID_ROOTFS" VOID_WORK="$work" VOID_REPO VOID_SERVICES \
|
|
VOID_PKGS="$pkgs" VOID_OUT="$out" VOID_LOCK="$lock" BASE_HOSTNAME
|
|
|
|
unshare --map-root-user --map-auto --mount sh -eu -c '
|
|
r=$VOID_WORK/root
|
|
mkdir -p "$r"
|
|
tar -xpf "$VOID_ROOTFS_FILE" -C "$r"
|
|
cp /etc/resolv.conf "$r/etc/resolv.conf"
|
|
mkdir -p "$r/etc/xbps.d"
|
|
echo "repository=$VOID_REPO" > "$r/etc/xbps.d/00-repository-main.conf"
|
|
/usr/sbin/chroot "$r" /usr/bin/env XBPS_ARCH=aarch64 /usr/bin/xbps-install -Syu xbps
|
|
/usr/sbin/chroot "$r" /usr/bin/env XBPS_ARCH=aarch64 /usr/bin/xbps-install -Sy $VOID_PKGS
|
|
rm -rf "$r/var/cache/xbps"
|
|
for s in $VOID_SERVICES; do
|
|
[ -d "$r/etc/sv/$s" ] || { echo "no runit service $s" >&2; exit 1; }
|
|
ln -sf "/etc/sv/$s" "$r/etc/runit/runsvdir/default/$s"
|
|
done
|
|
echo "$BASE_HOSTNAME" > "$r/etc/hostname"
|
|
/usr/sbin/chroot "$r" /usr/bin/xbps-query -l | awk "{print \$2}" | sort > "$VOID_LOCK"
|
|
tar -cpf "$VOID_OUT" -C "$r" .
|
|
'
|
|
echo "$out: $(wc -c < "$out" | tr -d ' ') bytes; $(wc -l < "$lock" | tr -d ' ') packages in $lock"
|