#!/bin/bash # mmdebstrap customize hook: turn a Debian testing rootfs into the Phoebus live # desktop (Mango + DankMaterialShell). Runs as root inside mmdebstrap's userns. # # Environment (set by build.sh): # PHOEBUS_SRC directory with the verified pinned source tarballs # PHOEBUS_RELEASE directory with the static phoebus-installer and sys # PHOEBUS_ASSETS directory with assets emitted by `phoebus-installer --emit-asset` # MANGO_VERSION, DMS_VERSION set -euo pipefail root="$1" : "${PHOEBUS_SRC:?}" "${PHOEBUS_RELEASE:?}" "${PHOEBUS_ASSETS:?}" 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 \ "$@" } install_asset() { local name="$1" dest="$2" mode="${3:-0644}" local src="$PHOEBUS_ASSETS/$name" [ -f "$src" ] || { echo "livefs-hook: missing asset $name" >&2; exit 1; } install -D -m "$mode" "$src" "$root/$dest" } 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" printf '%s ALL=(ALL) NOPASSWD: ALL\n' "$LIVE_USER" > "$root/etc/sudoers.d/90-phoebus-live" chmod 440 "$root/etc/sudoers.d/90-phoebus-live" # 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 "installer and system broker" install -D -m 0755 "$PHOEBUS_RELEASE/phoebus-installer" "$root/usr/local/bin/phoebus-installer" install -D -m 0755 "$PHOEBUS_RELEASE/sys" "$root/usr/local/bin/sys" say "shared desktop assets" install_asset session-mango /usr/local/bin/phoebus-session-mango 0755 install_asset session-dwl /usr/local/bin/phoebus-session 0755 install_asset assistant /usr/local/bin/phoebus-assistant 0755 install_asset install /usr/local/bin/phoebus-install 0755 install_asset menu /usr/local/bin/phoebus-menu 0755 install_asset lock /usr/local/bin/phoebus-lock 0755 install_asset idle /usr/local/bin/phoebus-idle 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 install_asset wayland-session-dwl /usr/share/wayland-sessions/phoebus-dwl.desktop install_asset waybar-config /etc/xdg/waybar/config install_asset waybar-style /etc/xdg/waybar/style.css # Live-only automatic login (never copied to an installed system). install_asset greetd-live /etc/greetd/config.toml 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 "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"