#!/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; do command -v "$c" >/dev/null || { echo "missing tool: $c" >&2; exit 1; } done 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 session-dwl assistant install menu lock idle mango-config mango-session-target install-desktop wayland-session-mango wayland-session-dwl waybar-config waybar-style greetd-live ) 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 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 \ --keyring="$work/apt-keys" \ --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 and verify the desktop payload" 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" # 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; } 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 >/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="$(ls -1 "$rootfs"/boot/vmlinuz-* 2>/dev/null | sort | tail -1 || true)" initrd="$(ls -1 "$rootfs"/boot/initrd.img-* 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" 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" >/dev/null 2>&1 chmod u+w "$bootcfg/grub.cfg" "$bootcfg/config.cfg" 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 # --------------------------------------------------------------------------- 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. `-boot_image any keep` preserves # the UEFI/BIOS boot equipment. 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" \ -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 \ -boot_image any keep >/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."