This commit is contained in:
Michal S.
2026-08-04 17:59:44 +01:00
commit 69071efd58
123 changed files with 7728 additions and 0 deletions
+211
View File
@@ -0,0 +1,211 @@
#!/bin/sh
set -eu
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
repo_dir=$(dirname "$script_dir")
cheesed_dir="$repo_dir/base/cheesed"
build_dir=${MOUSE_BUILD_DIR:-"$repo_dir/build"}
target=${CHEESED_TARGET:-x86_64-unknown-linux-musl}
test_fixtures=${MOUSE_INCLUDE_TEST_FIXTURES:-0}
kernel_modules=${MOUSE_KERNEL_MODULES:-"$build_dir/kernel/modules"}
staging=
image_staging=
cleanup() {
for directory in "$staging" "$image_staging"; do
if [ -n "$directory" ] && [ -d "$directory" ]; then
rm -rf "$directory"
fi
done
}
trap cleanup EXIT HUP INT TERM
case "$test_fixtures" in
0|1) ;;
*)
printf '%s\n' "MOUSE_INCLUDE_TEST_FIXTURES must be 0 or 1" >&2
exit 1
;;
esac
base_root="$build_dir/static/rootfs"
pkgsrc_seed=${MOUSE_PKGSRC_SEED:-"$build_dir/pkgsrc-seed"}
for input in "$base_root" "$build_dir/vmlinuz-virt"; do
if [ ! -e "$input" ]; then
printf '%s\n' "missing prepared image input: $input" >&2
exit 1
fi
done
for seed_directory in "$pkgsrc_seed/usr/local" "$pkgsrc_seed/var/db/pkg"; do
if [ ! -d "$seed_directory" ]; then
printf '%s\n' "missing pkgsrc seed directory: $seed_directory" >&2
exit 1
fi
done
btrfs_image_tool=${MOUSE_BTRFS_IMAGE_TOOL:-"$base_root/sbin/mkfs.btrfs"}
if [ ! -x "$btrfs_image_tool" ]; then
printf '%s\n' "missing btrfs image tool: $btrfs_image_tool" >&2
exit 1
fi
if [ -n "${MOUSE_CHEESED_BINARY:-}" ]; then
cheesed_binary=$MOUSE_CHEESED_BINARY
else
cheesed_binary=$(CHEESED_TARGET="$target" "$cheesed_dir/scripts/build-static.sh")
fi
staging=$(mktemp -d "${TMPDIR:-/tmp}/mouse-rootfs.XXXXXX")
image_staging=$(mktemp -d "${TMPDIR:-/tmp}/mouse-btrfs.XXXXXX")
install -d -m 0755 \
"$staging/dev" \
"$staging/bin" \
"$staging/etc" \
"$staging/etc/default" \
"$staging/etc/rc.d" \
"$staging/etc/skel" \
"$staging/home" \
"$staging/media" \
"$staging/mnt" \
"$staging/proc" \
"$staging/root" \
"$staging/run" \
"$staging/sbin" \
"$staging/srv" \
"$staging/sys" \
"$staging/usr/bin" \
"$staging/usr/local/etc/rc.d" \
"$staging/usr/lib/mouse" \
"$staging/usr/sbin" \
"$staging/var/cache/pkgsrc/distfiles" \
"$staging/var/cache/pkgsrc/packages" \
"$staging/var/db" \
"$staging/var/lib/dhcpcd" \
"$staging/var/empty" \
"$staging/var/log" \
"$staging/var/mail" \
"$staging/var/spool/cron"
chmod 0755 "$staging"
chmod 0700 "$staging/root"
chmod 0755 "$staging/var/empty"
chmod 0700 "$staging/var/spool/cron"
install -d -m 1777 \
"$staging/tmp" \
"$staging/var/tmp" \
"$staging/var/tmp/vi.recover"
ln -s /run "$staging/var/run"
cp -R "$base_root/." "$staging/"
cp -R "$pkgsrc_seed/usr/local/." "$staging/usr/local/"
cp -R "$pkgsrc_seed/var/db/pkg" "$staging/var/db/"
if [ ! -d "$kernel_modules/lib/modules" ]; then
printf '%s\n' "missing kernel module tree: $kernel_modules/lib/modules" >&2
exit 1
fi
cp -R "$kernel_modules/lib/." "$staging/lib/"
if [ "$test_fixtures" -eq 1 ] && [ -d "$kernel_modules/usr/local" ]; then
cp -R "$kernel_modules/usr/local/." "$staging/usr/local/"
fi
install -m 0755 "$cheesed_binary" "$staging/sbin/cheesed"
for command in service shutdown poweroff reboot; do
ln -s cheesed "$staging/sbin/$command"
done
cp -R "$repo_dir/base/rootfs/." "$staging/"
if [ "$test_fixtures" -eq 1 ]; then
cp -R "$repo_dir/tests/fixtures/mouse-echo/rootfs/." "$staging/"
install -m 0755 \
"${MOUSE_MOUSE_ECHO_BINARY:?missing test mouse-echo binary}" \
"$staging/usr/libexec/mouse-echo"
printf '%s\n' "enable_mouse_echo=YES" >>"$staging/etc/rc.conf"
fi
install -d -m 0755 "$staging/usr/share/mouse"
if [ "$test_fixtures" -eq 1 ]; then
install -d -m 0755 "$staging/usr/share/mouse/pkgsrc-fixture"
cp -R "$repo_dir/tests/fixtures/pkgsrc/local" \
"$staging/usr/share/mouse/pkgsrc-fixture/"
fi
printf '%s\n' 2026Q2 >"$staging/usr/share/mouse/pkgsrc.version"
rc_subr_source="$staging/usr/local/src/pkgsrc/pkgtools/rc.subr/files/rc.subr"
[ -f "$rc_subr_source" ] || {
printf '%s\n' "pkgsrc seed lacks rc.subr source" >&2
exit 1
}
sed 's|@SYSCONFBASE@|/usr/local/etc|g' "$rc_subr_source" \
>"$staging/etc/rc.subr"
patch "$staging/etc/rc.subr" \
<"$repo_dir/base/patches/pkgsrc-rc.subr-cgroup.patch"
chmod 0444 "$staging/etc/rc.subr"
ln -s mouse-release "$staging/etc/os-release"
chmod 0755 \
"$staging/etc/rc.d/console_login" \
"$staging/etc/rc.d/cron" \
"$staging/etc/rc.d/daemon" \
"$staging/etc/rc.d/login" \
"$staging/etc/rc.d/loopback" \
"$staging/etc/rc.d/machine_identity" \
"$staging/etc/rc.d/mdevd" \
"$staging/etc/rc.d/network" \
"$staging/etc/rc.d/ntpd" \
"$staging/etc/rc.d/servers" \
"$staging/etc/rc.d/syslogd" \
"$staging/usr/libexec/mouse-dhcpcd-hook"
if [ "$test_fixtures" -eq 1 ]; then
chmod 0755 "$staging/etc/rc.d/mouse_echo"
fi
chmod 0600 "$staging/etc/shadow"
chmod 0444 "$staging/usr/share/mouse/pkgsrc.version"
"$script_dir/audit-static-base.sh" "$staging"
mkdir -p "$build_dir"
btrfs_image="$build_dir/mouse-rootfs.btrfs"
rootfs_size=${MOUSE_ROOTFS_SIZE:-4G}
install -d -m 0755 \
"$image_staging/ROOT/default" \
"$image_staging/ROOT/alternate" \
"$image_staging/usr-local" \
"$image_staging/var" \
"$image_staging/home" \
"$image_staging/srv"
cp -R "$staging/." "$image_staging/ROOT/default/"
cp -R "$staging/." "$image_staging/ROOT/alternate/"
printf '%s\n' default \
>"$image_staging/ROOT/default/etc/mouse-boot-environment"
printf '%s\n' alternate \
>"$image_staging/ROOT/alternate/etc/mouse-boot-environment"
for persistent in \
usr/local:usr-local \
var:var \
home:home \
srv:srv
do
root_path=${persistent%%:*}
subvolume=${persistent#*:}
cp -R "$staging/$root_path/." "$image_staging/$subvolume/"
for environment in default alternate; do
rm -rf "$image_staging/ROOT/$environment/$root_path"
install -d -m 0755 \
"$image_staging/ROOT/$environment/$root_path"
done
done
rm -f "$btrfs_image"
truncate -s "$rootfs_size" "$btrfs_image"
"$btrfs_image_tool" \
--force \
--label MOUSE_ROOT \
--uuid 4d4f5553-4500-4000-8000-00000000000b \
--rootdir "$image_staging" \
--subvol default:ROOT/default \
--subvol rw:ROOT/alternate \
--subvol rw:usr-local \
--subvol rw:var \
--subvol rw:home \
--subvol rw:srv \
"$btrfs_image"
printf '%s\n' "built $build_dir/vmlinuz-virt"
printf '%s\n' "built $btrfs_image"
sh "$script_dir/build-boot-disk.sh"