#!/usr/bin/env bash # Build the Phoebus installer + live-desktop ISO. # # The live medium is a Debian rootfs carrying the Mango + DankMaterialShell # desktop; the installed target is Gentoo. The desktop stack comes from the # signed Debian testing archive (wlroots 0.20, scenefx 0.5, quickshell) plus # pinned, SHA-256-verified upstream releases for Mango (built from source) and # DankMaterialShell (prebuilt release tarball). No `curl | sh`, no live/git # packages and no disabled signature checks anywhere. # # The build is rootless: mmdebstrap runs in an unprivileged user namespace and # the rootfs is materialised as a tar, extracted and packed with mksquashfs. # Nothing on the host is modified. The installed system is always Gentoo; # Debian packages never enter the Gentoo target. # # Requirements: mmdebstrap, xorriso, squashfs-tools, curl, dpkg-deb, unshare, # and the static installer built first (see README.md). set -euo pipefail here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(cd "$here/../.." && pwd)" # The rootless build maps a subuid for the unprivileged user namespace, which # cannot traverse a 0750 home directory. The default work directory is therefore # world-traversable; override with WORKDIR. work="${WORKDIR:-/var/tmp/phoebus-live/build}" out="${OUT:-$here/phoebus-installer-amd64.iso}" base="${BASE_ISO:-$root/debian-live-standard.iso}" suite="${SUITE:-testing}" mirror="${MIRROR:-http://deb.debian.org/debian}" mango_version="${MANGO_VERSION:-0.17.2}" dms_version="${DMS_VERSION:-1.6.2}" target="x86_64-unknown-linux-gnu" release_src="$root/installer-rs/target/$target/release" base_url="https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-13.7.0-amd64-standard.iso" base_sha="$(awk '{print $1}' "$here/base.sha256")" say() { printf '\n== %s ==\n' "$*"; } # --------------------------------------------------------------------------- say "preflight" for c in mmdebstrap xorriso mksquashfs curl dpkg-deb unshare sha256sum gpg; do command -v "$c" >/dev/null || { echo "missing tool: $c" >&2; exit 1; } done if ! command -v magick >/dev/null 2>&1 \ && ! command -v convert >/dev/null 2>&1 \ && ! command -v inkscape >/dev/null 2>&1; then echo "missing an SVG rasteriser for the boot background (magick, convert or inkscape)" >&2 exit 1 fi for b in phoebus-installer sys; do [[ -x "$release_src/$b" ]] || { echo "missing $release_src/$b; build it first:" >&2 echo " cd installer-rs && RUSTFLAGS=\"-C target-feature=+crt-static\" \\" >&2 echo " cargo build --release -p phoebus-installer --target $target" >&2 exit 1 } done mkdir -p "$work/src" "$work/assets" "$work/release" # mmdebstrap's rootless user namespace reads and writes these as a mapped uid. chmod 0777 "$work" chmod 0755 "$work/src" "$work/assets" "$work/release" install -m 0755 "$release_src/phoebus-installer" "$work/release/phoebus-installer" install -m 0755 "$release_src/sys" "$work/release/sys" release_dir="$work/release" # --------------------------------------------------------------------------- say "base ISO" if [[ ! -f "$base" ]]; then echo "downloading $base_url" curl -fL --retry 3 -o "$base" "$base_url" fi echo "$base_sha $base" | sha256sum -c - >/dev/null || { echo "base ISO checksum mismatch" >&2; exit 1; } echo "base OK: $base" # --------------------------------------------------------------------------- say "fetch and verify pinned desktop releases" fetch_verified() { local url="$1" file="$2" if [[ ! -f "$work/src/$file" ]]; then echo "fetching $file" curl -fL --retry 3 -o "$work/src/$file" "$url" fi if ! (cd "$work/src" && sha256sum -c "$here/releases.sha256" --ignore-missing) >/dev/null 2>&1; then echo "checksum mismatch for $file (see $here/releases.sha256)" >&2 exit 1 fi } fetch_verified \ "https://github.com/mangowm/mango/archive/refs/tags/${mango_version}.tar.gz" \ "mango-${mango_version}.tar.gz" fetch_verified \ "https://github.com/AvengeMedia/DankMaterialShell/releases/download/v${dms_version}/dms-full-amd64.tar.gz" \ "dms-full-amd64.tar.gz" (cd "$work/src" && sha256sum -c "$here/releases.sha256") echo "releases OK" # --------------------------------------------------------------------------- say "emit shared desktop assets" assets=( session-mango assistant assistant-desktop updates-desktop help help-html help-desktop dms-welcome-desktop install welcome mango-config mango-session-target install-desktop wayland-session-mango greetd-live live-sudoers brand-emblem brand-wordmark brand-wallpaper brand-tokens nvidia-load nvidia-service gpu-report ) for name in "${assets[@]}"; do "$release_dir/phoebus-installer" --emit-asset "$name" > "$work/assets/$name" || { echo "failed to emit asset $name" >&2; exit 1; } [[ -s "$work/assets/$name" ]] || { echo "empty asset $name" >&2; exit 1; } done echo "emitted ${#assets[@]} assets" # --------------------------------------------------------------------------- say "build live desktop rootfs (mmdebstrap, rootless)" # Debian archive keyrings (the host may not ship them). apt's modern # `trusted.gpg.d` only reads `.gpg`/`.asc`, so the Debian `.pgp` files are # copied with a `.gpg` suffix into a directory handed to mmdebstrap. if [[ ! -d "$work/apt-keys" ]]; then keydeb="$work/debian-archive-keyring.deb" curl -fsS -o "$keydeb" \ "https://deb.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2025.1_all.deb" dpkg-deb -x "$keydeb" "$work/keyring-extract" install -d "$work/apt-keys" for f in "$work/keyring-extract/usr/share/keyrings/"debian-archive-*.pgp; do base="$(basename "$f" .pgp)" cp "$f" "$work/apt-keys/$base.gpg" done fi include_csv="$(grep -vE '^[[:space:]]*(#|$)' "$here/live-packages.list" | paste -sd, -)" [[ -n "$include_csv" ]] || { echo "live-packages.list is empty" >&2; exit 1; } # The live kernel is pinned to Debian **stable** (trixie), not testing. Debian # testing's current kernel (7.2) removed the `strncpy` declaration the 550 # NVIDIA driver still uses, so `nvidia-kernel-dkms` cannot build against it. # Stable is also the project's "stability over novelty" choice, and its 6.12 LTS # kernel is exactly what the base live ISO already ships. The rootfs otherwise # stays on testing for wlroots 0.20 / scenefx 0.5 / Quickshell. say "resolve the stable live kernel" trixie_packages_file="$work/trixie-packages.gz" if [[ ! -s "$trixie_packages_file" ]]; then curl -fsSL --retry 3 "http://deb.debian.org/debian/dists/trixie/main/binary-amd64/Packages.gz" -o "$trixie_packages_file" fi trixie_packages() { zcat "$trixie_packages_file" } trixie_meta_dep() { # meta-package -> the exact versioned dependency atom trixie_packages | awk -v p="$1" 'BEGIN{RS=""} $0 ~ "^Package: "p"\\n" {print; exit}' \ | awk '/^Depends:/{for(i=1;i<=NF;i++){gsub(/[(),]/,"",$i); if($i ~ /^linux-(image|headers)-[0-9]/){print $i; exit}}}' || true } kernel_image="$(trixie_meta_dep linux-image-amd64)" kernel_headers="$(trixie_meta_dep linux-headers-amd64)" [[ -n "$kernel_image" && -n "$kernel_headers" ]] || { echo "could not resolve the trixie kernel packages" >&2; exit 1; } kernel_base="$(printf '%s' "$kernel_image" | sed -E 's/^linux-image-([0-9][^-+]*).*/\1/')" kernel_kbuild="linux-kbuild-$kernel_base" echo "live kernel: $kernel_image ($kernel_kbuild)" # Drop the rolling kernel metas; install the pinned stable kernel explicitly. include_csv="$(printf '%s' "$include_csv" | tr ',' '\n' \ | grep -vE '^(linux-image-amd64|linux-headers-amd64)$' | paste -sd, -)" include_csv="$include_csv,$kernel_image,$kernel_headers,$kernel_kbuild" # The setup hook runs as the mapped uid, which cannot traverse a 0750 home # directory, so it is staged into the world-traversable work directory. It adds # the trixie suite and pins only the kernel packages to it. setup_hook="$work/phoebus-setup.sh" cat > "$setup_hook" <<'SETUP' #!/bin/bash set -euo pipefail root="$1" mkdir -p "$root/etc/apt/sources.list.d" "$root/etc/apt/preferences.d" echo "deb http://deb.debian.org/debian trixie main contrib non-free non-free-firmware" \ > "$root/etc/apt/sources.list.d/trixie.list" cat > "$root/etc/apt/preferences.d/phoebus-kernel" <<'PREFS' Package: linux-image-* linux-headers-* linux-kbuild-* Pin: release n=trixie Pin-Priority: 1001 PREFS SETUP chmod 0755 "$setup_hook" # The hook runs as the mapped uid, which cannot traverse a 0750 home directory, # so it is staged into the world-traversable work directory. hook_script="$work/livefs-hook.sh" install -m 0755 "$here/livefs-hook.sh" "$hook_script" rootfs_tar="$work/livefs.tar" if [[ "${PHOEBUS_REUSE_ROOTFS:-0}" == "1" && -s "$rootfs_tar" ]]; then echo "reusing existing $rootfs_tar" else rm -f "$rootfs_tar" hook="PHOEBUS_SRC='$work/src' PHOEBUS_RELEASE='$work/release' PHOEBUS_ASSETS='$work/assets' \ MANGO_VERSION='$mango_version' DMS_VERSION='$dms_version' '$hook_script' \"\$1\"" mmdebstrap \ --mode=unshare \ --format=tar \ --variant=standard \ --components=main,contrib,non-free,non-free-firmware \ --keyring="$work/apt-keys" \ --setup-hook="$setup_hook" \ --include="$include_csv" \ --customize-hook="$hook" \ "$suite" "$rootfs_tar" "$mirror" fi [[ -s "$rootfs_tar" ]] || { echo "mmdebstrap did not produce $rootfs_tar" >&2; exit 1; } say "unpack the rootfs" rootfs="$work/rootfs" rm -rf "$rootfs" mkdir -p "$rootfs" # Device nodes cannot be created without privileges and are supplied by # devtmpfs at boot, so `/dev` is recreated empty. tar -xf "$rootfs_tar" -C "$rootfs" --exclude='./dev' install -d -m 0755 "$rootfs/dev" # The live hostname must not leak the build host's name from mmdebstrap. echo "${LIVE_HOSTNAME:-phoebus-live}" > "$rootfs/etc/hostname" printf '127.0.1.1\t%s\n' "${LIVE_HOSTNAME:-phoebus-live}" >> "$rootfs/etc/hosts" say "install the live payload" # Everything below is installed after the (cached) rootfs is extracted, so # PHOEBUS_REUSE_ROOTFS=1 still picks up new binaries, UI and branding. iso_version="${PHOEBUS_VERSION:-0.1.0}" build_id="${PHOEBUS_BUILD_ID:-$(date -u +%Y%m%dT%H%M%SZ)}" install -d -m 0755 "$rootfs/etc/phoebus" install -D -m 0755 "$release_dir/phoebus-installer" "$rootfs/usr/local/bin/phoebus-installer" install -D -m 0755 "$release_dir/sys" "$rootfs/usr/local/bin/sys" install_asset() { local name="$1" dest="$2" mode="${3:-0644}" local src="$work/assets/$name" [[ -f "$src" ]] || { echo "missing emitted asset $name" >&2; exit 1; } install -D -m "$mode" "$src" "$rootfs/$dest" } install_asset session-mango /usr/local/bin/phoebus-session-mango 0755 ln -sf phoebus-session-mango "$rootfs/usr/local/bin/phoebus-session" install_asset assistant /usr/local/bin/phoebus-assistant 0755 install_asset assistant-desktop /usr/share/applications/phoebus-assistant.desktop install_asset updates-desktop /usr/share/applications/phoebus-updates.desktop install_asset help /usr/local/bin/phoebus-help 0755 install_asset help-html /usr/share/phoebus/help/index.html install_asset help-desktop /usr/share/applications/phoebus-help.desktop install_asset dms-welcome-desktop /usr/share/applications/dms-welcome.desktop install_asset install /usr/local/bin/phoebus-install 0755 install_asset welcome /usr/local/bin/phoebus-welcome 0755 install_asset mango-config /etc/xdg/mango/config.conf install_asset mango-session-target /usr/lib/systemd/user/mango-session.target install_asset install-desktop /usr/share/applications/phoebus-install.desktop install_asset wayland-session-mango /usr/share/wayland-sessions/phoebus-mango.desktop # Live-only automatic login (never copied to an installed system). install_asset greetd-live /etc/greetd/config.toml # Live-only privilege policy. The recovery console keeps root through the # password-authenticated sudo group; unattended escalation is scoped to the # typed brokers. Reject a broad or malformed policy rather than ship it. install -d -m 0755 "$rootfs/etc/sudoers.d" install -D -m 0440 "$work/assets/live-sudoers" "$rootfs/etc/sudoers.d/90-phoebus-live" if command -v visudo >/dev/null 2>&1; then visudo -cf "$rootfs/etc/sudoers.d/90-phoebus-live" >/dev/null || { echo "the emitted live sudoers policy is invalid" >&2; exit 1; } fi grep -qE 'NOPASSWD:[[:space:]]*ALL|ALL=\(ALL\)' "$rootfs/etc/sudoers.d/90-phoebus-live" && { echo "refusing to ship an unscoped live sudoers policy" >&2; exit 1; } || true # NVIDIA accelerated driver: load it before greetd/Mango, and provide # diagnostics. The driver modules themselves are built into the rootfs by # livefs-hook.sh; nouveau blacklisting and module options come from Debian's # nvidia-kernel-common, which is the distro's supported configuration. install_asset nvidia-load /usr/local/bin/phoebus-nvidia-load 0755 install_asset gpu-report /usr/local/bin/phoebus-gpu-report 0755 install_asset nvidia-service /usr/lib/systemd/system/phoebus-nvidia.service install -d -m 0755 "$rootfs/etc/systemd/system/multi-user.target.wants" ln -sf /usr/lib/systemd/system/phoebus-nvidia.service \ "$rootfs/etc/systemd/system/multi-user.target.wants/phoebus-nvidia.service" # nvidia-kernel-common loads nvidia-drm unconditionally at boot. On a machine # with no NVIDIA GPU that can leave a failed unit, so remove it and rely on the # gated service above (which is a no-op without an NVIDIA display device). rm -f "$rootfs/etc/modules-load.d/nvidia.conf" # The live module policy. nouveau is blacklisted so it cannot *auto-bind* a GPU # the accelerated stack is meant to drive; the load script explicitly modprobes # nouveau for an unsupported GPU (a blacklist only suppresses alias-based # auto-loading). Debian's own nvidia-kernel-common file is replaced so its # unconditional nouveau options cannot defeat that fallback, and the file the # payload verifier checks is produced here rather than only on the installed # Gentoo target. rm -f "$rootfs/etc/modprobe.d/nvidia-blacklists-nouveau.conf" install -d -m 0755 "$rootfs/etc/modprobe.d" cat > "$rootfs/etc/modprobe.d/phoebus-nvidia.conf" <<'NVIDIA' # NVIDIA accelerated graphics on the Phoebus live medium (generated at build). blacklist nouveau options nvidia_drm modeset=1 softdep nvidia post: nvidia-uvm NVIDIA # Build-time gate: the assembled rootfs (cached or fresh) MUST carry a complete # NVIDIA payload for its exact kernel, or the build fails. This also writes # /etc/phoebus/nvidia with the bundled driver version, module flavor and kernel. nvidia_version="$(awk '/^Package: nvidia-driver$/{p=1} p&&/^Version:/{print $2; exit}' \ "$rootfs/var/lib/dpkg/status" 2>/dev/null)" if [[ -n "$nvidia_version" ]]; then "$release_dir/phoebus-installer" --verify-live-nvidia "$rootfs" \ --nvidia-version "$nvidia_version" --nvidia-flavor proprietary || { echo "live rootfs NVIDIA payload is incomplete or mismatched" >&2 exit 1 } echo "NVIDIA payload recorded: see /etc/phoebus/nvidia" elif [[ "${PHOEBUS_REQUIRE_NVIDIA:-0}" == "1" ]]; then echo "live rootfs has no nvidia-driver package; refusing to ship without the driver" >&2 exit 1 else echo "live rootfs has no nvidia-driver package; building standard VirtIO live image" mkdir -p "$rootfs/etc/phoebus" cat > "$rootfs/etc/phoebus/nvidia" <<'EOF' # Standard VirtIO live image (no proprietary NVIDIA payload bundled) status=disabled EOF fi # Provision the trusted Gentoo release key for stage3 DIGESTS verification. # The installer authenticates the signed DIGESTS with gpg against # /usr/share/openpgp-keys/gentoo-release.asc and refuses to install without # it, so the live image must ship that key. The key bundle is fetched once # here at build time (never unauthenticated at install time) and accepted # only when its fingerprint matches Gentoo's published release-key # information (https://www.gentoo.org/downloads/signatures/). gentoo_keydir="$rootfs/usr/share/openpgp-keys" gentoo_key="$gentoo_keydir/gentoo-release.asc" weekly_fp="13EBBDBEDE7A12775DFDB1BABB572E0E2D182910" signing_fp="D99EAC7379A850BCE47DA5F29E6438C817072058" keyring_tmp="$(mktemp -d)" curl -fsSL --retry 3 -o "$keyring_tmp/service-keys.gpg" \ "https://qa-reports.gentoo.org/output/service-keys.gpg" GNUPGHOME="$keyring_tmp" gpg --batch --quiet \ --import "$keyring_tmp/service-keys.gpg" if ! GNUPGHOME="$keyring_tmp" gpg --batch --with-colons \ --list-keys "$weekly_fp" 2>/dev/null | grep -q "$weekly_fp"; then echo "Gentoo weekly release key $weekly_fp missing from the fetched bundle;" >&2 echo "refusing to ship an untrusted stage3 verification key" >&2 rm -rf "$keyring_tmp" exit 1 fi install -d -m 0755 "$gentoo_keydir" if ! GNUPGHOME="$keyring_tmp" gpg --batch --quiet --armor \ --export "$weekly_fp" "$signing_fp" > "$gentoo_key" 2>/dev/null; then GNUPGHOME="$keyring_tmp" gpg --batch --quiet --armor \ --export "$weekly_fp" > "$gentoo_key" fi [[ -s "$gentoo_key" ]] || { echo "failed to provision the Gentoo release key" >&2 rm -rf "$keyring_tmp" exit 1 } chmod 0644 "$gentoo_key" verify_tmp="$(mktemp -d)" GNUPGHOME="$verify_tmp" gpg --batch --quiet --import "$gentoo_key" if ! GNUPGHOME="$verify_tmp" gpg --batch --with-colons \ --list-keys "$weekly_fp" 2>/dev/null | grep -q "$weekly_fp"; then echo "provisioned Gentoo release key failed its fingerprint check" >&2 rm -rf "$keyring_tmp" "$verify_tmp" exit 1 fi rm -rf "$keyring_tmp" "$verify_tmp" echo "Gentoo release key provisioned and fingerprint-checked: $gentoo_key" # Branding: shared vector assets, the app icon and the live-only marker. install_asset brand-emblem /usr/share/phoebus/branding/emblem.svg install_asset brand-wordmark /usr/share/phoebus/branding/wordmark.svg install_asset brand-wallpaper /usr/share/phoebus/branding/wallpaper.svg install_asset brand-tokens /usr/share/phoebus/branding/tokens.json install -D -m 0644 "$work/assets/brand-emblem" \ "$rootfs/usr/share/icons/hicolor/scalable/apps/phoebus.svg" install -D -m 0644 "$here/install-help.txt" "$rootfs/usr/share/phoebus/install-help.txt" printf '%s\n' "$iso_version" > "$rootfs/etc/phoebus/version" printf 'PHOEBUS_BUILD_ID=%s\n' "$build_id" > "$rootfs/etc/phoebus/build" # The live marker gates live-only autostart; it is never written to a target. : > "$rootfs/etc/phoebus/live" # Suppress DankMaterialShell's upstream first-run dialogs on the live medium: # the installer is the first thing the user should see. DMS writes these # markers itself when the dialogs are dismissed; pre-seeding them is its # supported "already welcomed" state. The tmpfiles `Z /home/phoebus` rule # chowns them to the live user at boot. The changelog marker is versioned by # DMS (major.minor), so it is derived from the pinned DMS release. install -d -m 0700 "$rootfs/home/phoebus/.config/DankMaterialShell" : > "$rootfs/home/phoebus/.config/DankMaterialShell/.firstlaunch" : > "$rootfs/home/phoebus/.config/DankMaterialShell/.changelog-${dms_version%.*}" # Give the live desktop the same offline wallpaper choices as an installed # account. The tmpfiles rule below owns the entire live home for phoebus. install -d -m 0755 "$rootfs/home/phoebus/Pictures/Wallpapers" for wallpaper in "$root/installer-rs/assets/wallpapers/"*.jpg; do [[ -f "$wallpaper" ]] || { echo "no default wallpapers found" >&2; exit 1; } install -m 0644 "$wallpaper" "$rootfs/home/phoebus/Pictures/Wallpapers/" done # Quickshell frontend: the welcome window and the graphical installer, each a # self-contained config with the shared Common module materialised. if [[ -d "$here/desktop" ]]; then for cfgname in phoebus-welcome phoebus-install phoebus-assistant; do [[ -f "$here/desktop/$cfgname/shell.qml" ]] || { echo "live build: missing desktop config $cfgname" >&2; exit 1; } install -d -m 0755 "$rootfs/etc/xdg/quickshell/$cfgname" cp -rL "$here/desktop/$cfgname/." "$rootfs/etc/xdg/quickshell/$cfgname/" done fi # Fail clearly rather than shipping a text ISO labelled as a desktop image. for bin in usr/bin/mango usr/bin/dms; do [[ -e "$rootfs/$bin" ]] || { echo "live rootfs is missing $bin" >&2; exit 1; } done if [[ ! -e "$rootfs/usr/bin/qs" && ! -e "$rootfs/usr/bin/quickshell" ]]; then echo "live rootfs is missing quickshell (qs/quickshell)" >&2 exit 1 fi [[ -f "$rootfs/etc/greetd/config.toml" ]] || { echo "live rootfs has no greetd config" >&2; exit 1; } grep -q "initial_session" "$rootfs/etc/greetd/config.toml" || { echo "live rootfs greetd config is missing live autologin" >&2; exit 1; } [[ -f "$rootfs/usr/share/applications/phoebus-install.desktop" ]] || { echo "live rootfs has no Install Phoebus launcher" >&2; exit 1; } for check in \ usr/local/bin/phoebus-welcome \ usr/local/bin/phoebus-help \ usr/share/phoebus/help/index.html \ usr/share/applications/phoebus-help.desktop \ usr/share/applications/dms-welcome.desktop \ etc/xdg/quickshell/phoebus-welcome/shell.qml \ etc/xdg/quickshell/phoebus-install/shell.qml \ usr/share/phoebus/branding/emblem.svg \ usr/share/phoebus/branding/wallpaper.svg \ home/phoebus/Pictures/Wallpapers/aurora-lagoon.jpg \ home/phoebus/Pictures/Wallpapers/desert-arch.jpg \ home/phoebus/Pictures/Wallpapers/misty-lake.jpg \ home/phoebus/Pictures/Wallpapers/stone-strata.jpg \ etc/phoebus/live \ usr/local/bin/phoebus-nvidia-load \ usr/local/bin/phoebus-gpu-report \ usr/lib/systemd/system/phoebus-nvidia.service \ etc/modprobe.d/phoebus-nvidia.conf \ etc/phoebus/nvidia; do [[ -e "$rootfs/$check" ]] || { echo "live rootfs is missing payload: $check" >&2; exit 1; } done echo "desktop payload verified" # --------------------------------------------------------------------------- say "pack live filesystem" # A writable home for the live user. The squashfs is packed all-root, so the # live user's home ownership is restored at boot (the live root is a writable # overlay). install -d -m 0755 "$rootfs/etc/tmpfiles.d" cat > "$rootfs/etc/tmpfiles.d/phoebus-live.conf" <<'EOF' d /home/phoebus 0700 phoebus phoebus - Z /home/phoebus 0700 phoebus phoebus - EOF # `tar` run as an unprivileged user drops setuid/setgid/sticky bits; restore # them from the archive so e.g. `sudo` and `pkexec` work in the live image. # `mksquashfs -all-root` then makes those files setuid/setgid root. python3 - "$rootfs_tar" "$rootfs" <<'PY' import os, sys, tarfile tar_path, rootfs = sys.argv[1], sys.argv[2] with tarfile.open(tar_path) as tar: for member in tar: special = member.mode & 0o7000 if not special: continue target = os.path.join(rootfs, member.name.lstrip("./")) if os.path.lexists(target): current = os.lstat(target).st_mode os.chmod(target, (current & 0o7777) | special) PY # Autoload the VirtIO GPU so the compositor gets a DRM node and a logind seat # (the module is not always pulled in by the initramfs). install -d -m 0755 "$rootfs/etc/modules-load.d" printf 'virtio_gpu\n' > "$rootfs/etc/modules-load.d/phoebus-live-gpu.conf" squashfs="$work/filesystem.squashfs" rm -f "$squashfs" mksquashfs "$rootfs" "$squashfs" \ -noappend -comp zstd -all-root -no-progress \ -processors 4 -mem 2G >/dev/null echo "squashfs: $(du -h "$squashfs" | cut -f1)" # Package list for the live medium (informational). grep -a '^Package: ' "$rootfs/var/lib/dpkg/status" 2>/dev/null \ | awk '{print $2}' | sort -u > "$work/filesystem.packages" || true # Kernel and initramfs generated inside the rootfs. vmlinuz="$(find "$rootfs/boot" -maxdepth 1 -name 'vmlinuz-*' \( -type f -o -type l \) -print 2>/dev/null | sort | tail -1 || true)" initrd="$(find "$rootfs/boot" -maxdepth 1 -name 'initrd.img-*' \( -type f -o -type l \) -print 2>/dev/null | sort | tail -1 || true)" [[ -f "$vmlinuz" ]] || { echo "live rootfs has no vmlinuz" >&2; exit 1; } [[ -f "$initrd" ]] || { echo "live rootfs has no initrd" >&2; exit 1; } cp "$vmlinuz" "$work/vmlinuz" cp "$initrd" "$work/initrd.img" # --------------------------------------------------------------------------- say "patch boot config for serial console and Phoebus branding" bootcfg="$work/bootcfg"; mkdir -p "$bootcfg" xorriso -osirrox on -indev "$base" \ -extract /boot/grub/grub.cfg "$bootcfg/grub.cfg" \ -extract /boot/grub/config.cfg "$bootcfg/config.cfg" \ -extract /boot/grub/live-theme/theme.txt "$bootcfg/theme.txt" >/dev/null 2>&1 chmod u+w "$bootcfg/grub.cfg" "$bootcfg/config.cfg" "$bootcfg/theme.txt" sed -i 's#boot=live components quiet splash findiso=#boot=live components console=ttyS0,115200 noautologin findiso=#' "$bootcfg/grub.cfg" python3 - "$bootcfg/config.cfg" <<'PY' import sys p = sys.argv[1] t = open(p).read() t = t.replace("set default=0\n", "set default=0\nset timeout=5\nserial --unit=0 --speed=115200\n" "terminal_input console serial\nterminal_output console serial\n", 1) t = t.replace("terminal_output gfxterm", "terminal_output gfxterm serial") open(p, "w").write(t) PY # Phoebus identity on the boot menu: rename the entries and use the brand # colours and wallpaper. This only rewrites text/theme files; the boot path is # untouched. python3 - "$bootcfg/grub.cfg" <<'PY' import sys p = sys.argv[1] t = open(p).read() t = t.replace('menuentry "Live system (amd64)"', 'menuentry "Start Phoebus OS (live medium)"') t = t.replace('menuentry "Live system (amd64 fail-safe mode)"', 'menuentry "Phoebus OS (fail-safe graphics)"') # The fail-safe entry is the documented fallback when NVIDIA (or any KMS) # initialisation misbehaves: it disables modesetting and blacklists the NVIDIA # modules for that boot, leaving the basic framebuffer in charge. The normal # entry is unaffected. This is a recovery path, not the default. t = t.replace( 'nosplash vga=788', 'nosplash vga=788 nomodeset phoebus.nvidia=off ' 'modprobe.blacklist=nvidia,nvidia_modeset,nvidia_uvm,nvidia_drm') # The Debian installer is not Phoebus's installer. Its menu entries would # become dead links after dropping the unused Debian package pools below. start = t.find('# Installer (if any)\n') end = t.find("submenu 'Utilities...'", start) if start < 0 or end < 0: raise SystemExit('base GRUB installer menu layout changed') t = t[:start] + t[end:] open(p, "w").write(t) PY cat > "$bootcfg/theme.cfg" <<'EOF' set color_normal=light-gray/black set color_highlight=black/brown if [ -e /boot/grub/splash.png ]; then set theme=/boot/grub/live-theme/theme.txt else set menu_color_normal=light-gray/black set menu_color_highlight=white/brown fi EOF python3 - "$bootcfg/theme.txt" <<'PY' import sys p = sys.argv[1] t = open(p).read() t = t.replace('title-text: "Live Boot Menu with GRUB"', 'title-text: "Phoebus OS"') t = t.replace('title-color: "#ffffff"', 'title-color: "#e8a33d"') t = t.replace('item_color = "#a8a8a8"', 'item_color = "#f4efe6"') t = t.replace('selected_item_color= "#ffffff"', 'selected_item_color= "#e8a33d"') t = t.replace('fg_color = "#ffffff"', 'fg_color = "#e8a33d"') t = t.replace('bg_color = "#a8a8a8"', 'bg_color = "#3a3a42"') t = t.replace('border_color = "#ffffff"', 'border_color = "#e8a33d"') open(p, "w").write(t) PY # Rasterise the brand wallpaper for the GRUB background (GRUB does not read # SVG). ImageMagick or Inkscape is required; the build fails clearly otherwise. if command -v magick >/dev/null 2>&1; then magick -background none "$work/assets/brand-wallpaper" -resize 1024x768 "$bootcfg/splash.png" elif command -v convert >/dev/null 2>&1; then convert -background none "$work/assets/brand-wallpaper" -resize 1024x768 "$bootcfg/splash.png" elif command -v inkscape >/dev/null 2>&1; then inkscape "$work/assets/brand-wallpaper" -w 1024 -h 768 -o "$bootcfg/splash.png" else echo "no SVG rasteriser (magick/convert/inkscape) for the boot background" >&2 exit 1 fi [[ -s "$bootcfg/splash.png" ]] || { echo "branded boot background is empty" >&2; exit 1; } # --------------------------------------------------------------------------- say "assemble ISO" rm -f "$out" # Replace every kernel/initrd path the base ISO ships (both the canonical # /live/vmlinuz and the versioned name its GRUB config may reference), plus the # live squashfs and serial-patched GRUB config. Replay the detected boot # configuration after mapping files so the MBR/GPT partition lengths reflect # this ISO's size, while preserving its UEFI and BIOS boot entries. kmap=() while IFS= read -r path; do [ -n "$path" ] || continue case "$path" in *vmlinuz*) kmap+=(-map "$work/vmlinuz" "$path") ;; *initrd*) kmap+=(-map "$work/initrd.img" "$path") ;; esac done < <(xorriso -indev "$base" -find /live 2>/dev/null \ | tr -d "'" | grep -E '^/live/(vmlinuz|initrd)' | sort -u) xorriso -indev "$base" -outdev "$out" \ -rm_r /pool /pool-udeb /install -- \ -map "$squashfs" /live/filesystem.squashfs \ -map "$work/filesystem.packages" /live/filesystem.packages \ "${kmap[@]}" \ -map "$bootcfg/grub.cfg" /boot/grub/grub.cfg \ -map "$bootcfg/config.cfg" /boot/grub/config.cfg \ -map "$bootcfg/theme.cfg" /boot/grub/theme.cfg \ -map "$bootcfg/theme.txt" /boot/grub/live-theme/theme.txt \ -map "$bootcfg/splash.png" /boot/grub/splash.png \ -boot_image any replay >/dev/null # Catch stale partition tables or unreadable boot metadata before publishing. xorriso -indev "$out" -toc >/dev/null sha256sum "$out" | tee "$out.sha256" ls -lh "$out" echo echo "Built with Mango ${mango_version} + DankMaterialShell ${dms_version}." echo "Live login is automatic; an installed system authenticates via greetd."