Replace pkgsrc and mdevd with mouse ports desktop base

This commit is contained in:
Michal S.
2026-08-06 10:26:36 +01:00
parent c9dae15bc4
commit 6a8be734f3
97 changed files with 3129 additions and 810 deletions
+96 -37
View File
@@ -3,11 +3,13 @@ set -eu
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
repo_dir=$(dirname "$script_dir")
. "$script_dir/mouse-arch.sh"
cheesed_dir="$repo_dir/base/cheesed"
build_dir=${MOUSE_BUILD_DIR:-"$repo_dir/build"}
target=${CHEESED_TARGET:-x86_64-unknown-linux-musl}
build_dir=${MOUSE_BUILD_DIR:-"$repo_dir/build/$MOUSE_ARCH"}
target=${CHEESED_TARGET:-$MOUSE_RUST_TARGET}
test_fixtures=${MOUSE_INCLUDE_TEST_FIXTURES:-0}
kernel_modules=${MOUSE_KERNEL_MODULES:-"$build_dir/kernel/modules"}
device_firmware=${MOUSE_DEVICE_FIRMWARE:-"$build_dir/device-firmware"}
staging=
image_staging=
@@ -28,19 +30,18 @@ case "$test_fixtures" in
;;
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
ports_seed=${MOUSE_PORTS_SEED:-"$build_dir/mouse-ports-seed"}
for input in "$base_root" "$build_dir/vmlinuz-virt" \
"$device_firmware/lib/firmware"; 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
if [ ! -d "$ports_seed/usr/local" ]; then
printf '%s\n' "missing mouse-ports seed directory: $ports_seed/usr/local" >&2
exit 1
fi
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
@@ -74,8 +75,8 @@ install -d -m 0755 \
"$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/cache/mouse/ports/distfiles" \
"$staging/var/cache/mouse/packages" \
"$staging/var/db" \
"$staging/var/lib/dhcpcd" \
"$staging/var/empty" \
@@ -94,13 +95,13 @@ install -d -m 1777 \
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/"
cp -R "$ports_seed/usr/local/." "$staging/usr/local/"
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/"
cp -R "$device_firmware/lib/firmware" "$staging/lib/"
if [ "$test_fixtures" -eq 1 ] && [ -d "$kernel_modules/usr/local" ]; then
cp -R "$kernel_modules/usr/local/." "$staging/usr/local/"
fi
@@ -110,29 +111,40 @@ for command in service shutdown poweroff reboot; do
done
cp -R "$repo_dir/base/rootfs/." "$staging/"
install -d -m 0700 -o 1000 -g 1000 "$staging/home/mouse"
sed "s/@MOUSE_ARCH@/$MOUSE_ARCH/g" \
"$staging/etc/mouse-release" >"$staging/etc/mouse-release.new"
mv "$staging/etc/mouse-release.new" "$staging/etc/mouse-release"
sed "s/@MOUSE_ARCH@/$MOUSE_ARCH/g" \
"$staging/etc/motd" >"$staging/etc/motd.new"
mv "$staging/etc/motd.new" "$staging/etc/motd"
for console_file in \
"$staging/etc/rc.d/console_login" \
"$staging/etc/securetty"
do
sed "s/@MOUSE_CONSOLE@/$MOUSE_CONSOLE/g" \
"$console_file" >"$console_file.new"
mv "$console_file.new" "$console_file"
done
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"
test_password_hash='$6$mouse$LofYSsSObtmx/zmS97A.TFONKSQSATXE4bD6dY1H7JSBSayuyAuc4Qwpm7JdfW9lUnri9DrQfUKGiLTNKA3v81'
awk -F: -v OFS=: -v password_hash="$test_password_hash" '
$1 == "root" || $1 == "toor" { $2 = password_hash }
{ print }
' "$staging/etc/shadow" >"$staging/etc/shadow.test"
mv "$staging/etc/shadow.test" "$staging/etc/shadow"
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"
install -m 0444 \
"${MOUSE_PORTS_REVISION_FILE:-/work/mouse-ports-revision}" \
"$staging/usr/share/mouse/ports.revision"
patch "$staging/etc/rc.subr" \
<"$repo_dir/base/patches/pkgsrc-rc.subr-cgroup.patch"
<"$repo_dir/base/patches/rc.subr-cgroup.patch"
chmod 0444 "$staging/etc/rc.subr"
ln -s mouse-release "$staging/etc/os-release"
chmod 0755 \
@@ -142,24 +154,56 @@ chmod 0755 \
"$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/gardendevd" \
"$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"
"$staging/etc/rc.d/wpa_supplicant" \
"$staging/usr/libexec/mouse-dhcpcd-hook" \
"$staging/usr/libexec/mouse-wpa-supplicant"
if [ "$test_fixtures" -eq 1 ]; then
chmod 0755 "$staging/etc/rc.d/mouse_echo"
fi
chown 0:0 \
"$staging/bin/ping" \
"$staging/bin/su" \
"$staging/usr/bin/crontab" \
"$staging/usr/bin/doas" \
"$staging/usr/bin/passwd"
chmod 4755 \
"$staging/bin/ping" \
"$staging/bin/su" \
"$staging/usr/bin/crontab" \
"$staging/usr/bin/doas" \
"$staging/usr/bin/passwd"
chmod 0600 "$staging/etc/shadow"
chmod 0444 "$staging/usr/share/mouse/pkgsrc.version"
chmod 0600 "$staging/etc/wpa_supplicant/wpa_supplicant.conf"
"$script_dir/audit-static-base.sh" "$staging"
for desktop_input in \
/usr/local/bin/bmake \
/usr/local/bin/dwl \
/usr/local/bin/havoc \
/usr/local/bin/mouse-dwl-session \
/usr/local/bin/seatd \
/usr/local/bin/tuigreet \
/usr/local/lib/libudev.so \
/usr/local/lib/libwlroots-0.19.so \
/usr/local/sbin/greetd \
/usr/local/etc/rc.d/greetd \
/usr/local/etc/rc.d/seatd
do
[ -e "$staging$desktop_input" ] || {
printf '%s\n' "missing mouse-ports seed input: $desktop_input" >&2
exit 1
}
done
mkdir -p "$build_dir"
btrfs_image="$build_dir/mouse-rootfs.btrfs"
rootfs_size=${MOUSE_ROOTFS_SIZE:-4G}
rootfs_size=${MOUSE_ROOTFS_SIZE:-8G}
install -d -m 0755 \
"$image_staging/ROOT/default" \
"$image_staging/ROOT/alternate" \
@@ -168,8 +212,8 @@ install -d -m 0755 \
"$image_staging/home" \
"$image_staging/srv"
cp -R "$staging/." "$image_staging/ROOT/default/"
cp -R "$staging/." "$image_staging/ROOT/alternate/"
cp -a "$staging/." "$image_staging/ROOT/default/"
cp -a "$staging/." "$image_staging/ROOT/alternate/"
printf '%s\n' default \
>"$image_staging/ROOT/default/etc/mouse-boot-environment"
printf '%s\n' alternate \
@@ -183,7 +227,7 @@ for persistent in \
do
root_path=${persistent%%:*}
subvolume=${persistent#*:}
cp -R "$staging/$root_path/." "$image_staging/$subvolume/"
cp -a "$staging/$root_path/." "$image_staging/$subvolume/"
for environment in default alternate; do
rm -rf "$image_staging/ROOT/$environment/$root_path"
install -d -m 0755 \
@@ -191,6 +235,21 @@ do
done
done
for environment in default alternate; do
metadata=$(stat -c '%a %u %g' \
"$image_staging/ROOT/$environment/usr/bin/doas")
if [ "$metadata" != "4755 0 0" ]; then
printf '%s\n' \
"image staging lost doas setuid metadata in $environment" >&2
exit 1
fi
done
metadata=$(stat -c '%a %u %g' "$image_staging/home/mouse")
if [ "$metadata" != "700 1000 1000" ]; then
printf '%s\n' "image staging lost mouse home ownership" >&2
exit 1
fi
rm -f "$btrfs_image"
truncate -s "$rootfs_size" "$btrfs_image"
"$btrfs_image_tool" \
@@ -207,5 +266,5 @@ truncate -s "$rootfs_size" "$btrfs_image"
"$btrfs_image"
printf '%s\n' "built $build_dir/vmlinuz-virt"
printf '%s\n' "built $btrfs_image"
sh "$script_dir/build-boot-disk.sh"
rm -f "$btrfs_image"