phoebus_os/installer/live/livefs-hook.sh
Phoebus 4265aefacd fix(live): scope the live privilege policy to the typed brokers
The live user had NOPASSWD: ALL for the graphical broker. Replace it with
an emitted, visudo-validated policy that grants unattended escalation only
to /usr/local/bin/phoebus-installer, /usr/local/bin/sys and the systemctl
power actions; no ALL, no sh -c and no wildcard. The recovery console is
preserved: it logs in with the live-only password and authenticates sudo.
build.sh installs the asset, validates it with visudo and refuses any
unscoped policy. The GUI harness stages its preseed config with the
password-authenticated sudo over a 0600 file instead of bare install, and
the read-only greetd check no longer needs sudo.
2026-09-23 06:22:19 -07:00

121 lines
5.3 KiB
Bash

#!/bin/bash
# mmdebstrap customize hook: turn a Debian testing rootfs into the Phoebus live
# desktop (Mango + DankMaterialShell). Runs as root inside mmdebstrap's userns.
#
# Payload installation (binaries, branding, Quickshell UI, the live marker) is
# done by build.sh after the rootfs is extracted, so a cached rootfs
# (PHOEBUS_REUSE_ROOTFS=1) still picks up changed assets. This hook only does
# the expensive, root-requiring work: user accounts, the Mango build and the
# DMS install.
#
# Environment (set by build.sh):
# PHOEBUS_SRC directory with the verified pinned source tarballs
# MANGO_VERSION, DMS_VERSION
set -euo pipefail
root="$1"
: "${PHOEBUS_SRC:?}"
MANGO_VERSION="${MANGO_VERSION:-0.17.2}"
DMS_VERSION="${DMS_VERSION:-1.6.2}"
LIVE_USER=phoebus
in_root() {
chroot "$root" /usr/bin/env -i \
PATH=/usr/sbin:/usr/bin:/sbin:/bin HOME=/root TERM=linux LANG=C.UTF-8 \
"$@"
}
say() { echo "livefs-hook: $*"; }
say "live user"
if ! in_root id "$LIVE_USER" >/dev/null 2>&1; then
in_root useradd --create-home --shell /bin/bash \
--groups sudo,video,render,input,audio "$LIVE_USER"
fi
install -d -m 0755 "$root/etc/sudoers.d"
# The live privilege policy is the scoped, visudo-validated asset installed by
# build.sh (only the typed brokers escalate without a prompt). The recovery
# console keeps root through the password-authenticated sudo group below.
# A well-known live password so the serial/recovery console is usable; the
# graphical session still logs in automatically via greetd. This is live-only
# and is never written to an installed system.
echo "$LIVE_USER:phoebus" | chroot "$root" chpasswd
# greetd validates its default-session user at startup even when an
# initial_session is configured, so the greeter account must exist.
if ! in_root id greeter >/dev/null 2>&1; then
in_root useradd --system --no-create-home --home-dir /var/lib/greetd \
--shell /sbin/nologin --comment "Phoebus greeter" greeter
fi
say "build Mango ${MANGO_VERSION}"
tar -xzf "$PHOEBUS_SRC/mango-${MANGO_VERSION}.tar.gz" -C "$root/tmp"
in_root sh -c "cd /tmp/mango-${MANGO_VERSION} && \
meson setup build --prefix=/usr --buildtype=release -Dxwayland=enabled && \
ninja -C build && ninja -C build install"
rm -rf "$root/tmp/mango-${MANGO_VERSION}"
say "install DankMaterialShell ${DMS_VERSION}"
mkdir -p "$root/tmp/dms-full"
tar -xzf "$PHOEBUS_SRC/dms-full-amd64.tar.gz" -C "$root/tmp/dms-full"
dmsdir="$root/tmp/dms-full"
[ -x "$dmsdir/bin/dms" ] || { echo "livefs-hook: dms binary missing" >&2; exit 1; }
install -D -m 0755 "$dmsdir/bin/dms" "$root/usr/bin/dms"
install -d "$root/usr/share/quickshell"
cp -a "$dmsdir/dms" "$root/usr/share/quickshell/dms"
if [ -f "$root/usr/share/quickshell/dms/assets/systemd/dms.service" ]; then
install -D -m 0644 \
"$root/usr/share/quickshell/dms/assets/systemd/dms.service" \
"$root/usr/lib/systemd/user/dms.service"
install -d "$root/etc/systemd/user/mango-session.target.wants"
ln -sf /usr/lib/systemd/user/dms.service \
"$root/etc/systemd/user/mango-session.target.wants/dms.service"
fi
for entry in "$root/usr/share/quickshell/dms/assets/"*.desktop; do
[ -f "$entry" ] || continue
install -D -m 0644 "$entry" \
"$root/usr/share/applications/$(basename "$entry")"
done
if [ -d "$dmsdir/completions" ]; then
install -d "$root/usr/share/bash-completion/completions"
[ -f "$dmsdir/completions/completion.bash" ] && \
install -m 0644 "$dmsdir/completions/completion.bash" \
"$root/usr/share/bash-completion/completions/dms"
fi
rm -rf "$root/tmp/dms-full"
say "build NVIDIA kernel modules"
# The accelerated driver must be compiled for the exact kernel this image boots.
# Nothing is built or downloaded at boot; a failure here fails the build.
kernel_version="$(ls -1 "$root"/boot/vmlinuz-* 2>/dev/null | sed 's#.*/vmlinuz-##' | sort -V | tail -1)"
[ -n "$kernel_version" ] || { echo "livefs-hook: no kernel image found for NVIDIA" >&2; exit 1; }
if ! in_root dkms autoinstall -k "$kernel_version"; then
echo "livefs-hook: DKMS failed to build NVIDIA modules for $kernel_version" >&2
exit 1
fi
# Debian's nvidia-kernel-dkms renames the modules nvidia-current*; accept either
# naming so the hook does not depend on the packaging detail.
check_module() { # upstream-name debian-suffix
find "$root/lib/modules/$kernel_version" \
\( -name "$1.ko*" -o -name "nvidia-current$2.ko*" \) -print -quit 2>/dev/null | grep -q .
}
for pair in "nvidia:" "nvidia_modeset:-modeset" "nvidia_uvm:-uvm" "nvidia_drm:-drm"; do
upstream="${pair%%:*}"; suffix="${pair##*:}"
if ! check_module "$upstream" "$suffix"; then
echo "livefs-hook: $upstream.ko is missing for kernel $kernel_version" >&2
exit 1
fi
done
echo "livefs-hook: NVIDIA modules built for $kernel_version"
say "enable services"
# Regenerate the initramfs now that live-boot/live-config and the desktop
# packages are installed, so the live boot hooks are present.
in_root update-initramfs -u -k all >/dev/null 2>&1 || \
echo "livefs-hook: update-initramfs reported an issue" >&2
for svc in greetd.service NetworkManager.service bluetooth.service systemd-resolved.service \
serial-getty@ttyS0.service; do
in_root systemctl enable "$svc" >/dev/null 2>&1 \
|| echo "livefs-hook: could not enable $svc" >&2
done
say "desktop rootfs ready"