Files
debianito-post-install/modules/desktop_display.sh
T
stornic56 afac6c7876 KDE: add bookworm Wayland gate and release-aware SDDM session probe
Bookworm's plasma-workspace ships only the X11 session; the Wayland
session (plasmawayland.desktop) lives in the separate
plasma-workspace-wayland package (a Recommends of plasma-desktop, now
listed explicitly for the same determinism as the explicit sddm). The
package does not exist on trixie, where plasma-workspace integrates
Wayland natively, so naming it off-bookworm would fail the apt
transaction: resolve it once per installer with _kde_wayland_pkg() and
build the package list in a conditional array so neither the pre-apply
summary nor the apt command ever shows an empty argument. Also correct
the header comment: bookworm still defaults SDDM to the X11 session,
while trixie makes Wayland primary (plasma.desktop in
wayland-sessions) with plasmax11.desktop as the X11 fallback.

Replace the hard-coded SDDM autologin session cascade with an
existence-based ordered probe (_sddm_session_candidates) that prefers
Wayland across releases, keeps the LXQt sessions last for when the
module starts offering LXQt, and reads its session roots from
SESSION_DIR_WAYLAND / SESSION_DIR_X11 for hermetic testing.

Extend tests/desktops.bats with 13 offline tests: gate helper output on
bookworm/trixie, captured apt commands for both installers, summary
content (no empty package line), and the ordered session probe against
fixture trees.
2026-10-20 07:39:35 -05:00

413 lines
16 KiB
Bash

#!/usr/bin/env bash
manage_desktop_display() {
# Hardware state is detected on demand; HAS_NVIDIA
# (GDM3 Wayland option) is populated by the battery.
_ensure_state_detected
while true; do
local choice
choice=$(_menu "Desktop & Display" \
"Select an option:" $TUI_ALTO $TUI_ANCHO 6 \
"1" "Desktop Environment" \
"2" "Display Manager" \
"3" "Back to main menu")
[ -z "$choice" ] && break
clear
case "$choice" in
1) desktop_environment_menu ;;
2) display_manager_menu ;;
3) break ;;
esac
done
}
desktop_environment_menu() {
while true; do
local -a env_items=()
env_items+=("1" "XFCE")
env_items+=("2" "LXDE")
env_items+=("3" "GNOME")
env_items+=("4" "KDE Plasma")
env_items+=("5" "Back")
local choice
choice=$(_menu "Desktop Environment" \
"Select a desktop environment:" $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \
"${env_items[@]}")
[ -z "$choice" ] && break
clear
case "$choice" in
1)
_load_module xfce || continue
xfce_menu
;;
2)
_load_module lxde || continue
lxde_menu
;;
3)
_load_module gnome || continue
gnome_menu
;;
4)
_load_module kde || continue
kde_menu
;;
5) break ;;
esac
done
}
display_manager_menu() {
while true; do
local -a dm_items=()
dm_items+=("1" "LightDM")
dm_items+=("2" "GDM3")
dm_items+=("3" "SDDM")
if [ "$DEBIAN_VERSION" = "12" ] || [ "$DEBIAN_VERSION" = "13" ]; then
dm_items+=("4" "greetd")
dm_items+=("5" "Back")
else
dm_items+=("4" "Back")
fi
local choice
choice=$(_menu "Display Manager" \
"Select an option:" $TUI_ALTO $TUI_ANCHO 6 \
"${dm_items[@]}")
[ -z "$choice" ] && break
clear
case "$choice" in
1) lightdm_config_menu ;;
2) configure_gdm3 ;;
3) configure_sddm ;;
4)
if [ "$DEBIAN_VERSION" = "12" ] || [ "$DEBIAN_VERSION" = "13" ]; then
configure_greetd
else
break
fi
;;
5) break ;;
esac
done
}
lightdm_config_menu() {
local -a items=()
items+=("install_lightdm" "Install LightDM & GTK Greeter" "$(_state lightdm)")
items+=("enable_userlist" "Enable user list at login screen" "OFF")
items+=("enable_autologin" "Enable autologin for current user" "OFF")
local choices
choices=$(_checklist "LightDM Configuration" \
"Select options to apply:" $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \
"${items[@]}")
if [ -z "$choices" ]; then
echo "No changes."
_pause
return
fi
local cleaned
cleaned=$(echo "$choices" | tr -d '"')
# SECURITY: Convert to array to avoid word splitting and command injection.
local -a lm_items=()
while IFS= read -r _item; do
[ -n "$_item" ] && lm_items+=("$_item")
done < <(echo "$cleaned" | tr ' ' '\n')
for item in "${lm_items[@]}"; do
case $item in
install_lightdm)
if ! is_installed lightdm || ! is_installed lightdm-gtk-greeter-settings; then
echo "lightdm shared/default-x-display-manager select lightdm" | sudo debconf-set-selections
_run_cmd "LightDM" "sudo apt install -y lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings" "Installing LightDM & GTK Greeter..."
else
echo -e "${GREEN}[LightDM] LightDM and GTK Greeter settings are already installed, skipping...${NC}"
fi
;;
enable_userlist)
local conf="/etc/lightdm/lightdm.conf.d/50-debianito-userlist.conf"
sudo mkdir -p "$(dirname "$conf")"
if echo "[Seat:*]
greeter-hide-users=false" | sudo tee "$conf" >/dev/null; then
echo -e "${GREEN}User list enabled in LightDM.${NC}"
else
echo -e "${RED}Failed to write configuration.${NC}"
fi
;;
enable_autologin)
local dm_conf="/etc/lightdm/lightdm.conf"
local lightdm_user="${SUDO_USER:-}"
if [ -z "$lightdm_user" ] || [ "$lightdm_user" = "root" ]; then
lightdm_user=$(awk -F: '$3>=1000 && $3<65534 {print $1}' /etc/passwd | head -1)
fi
sudo sed -i 's/^#[[:space:]]*autologin-user[[:space:]=].*/autologin-user='"$lightdm_user"'/' "$dm_conf"
sudo sed -i 's/^#[[:space:]]*autologin-user-timeout[[:space:]=].*/autologin-user-timeout=0/' "$dm_conf"
echo -e "${GREEN}Autologin enabled for user: ${lightdm_user}${NC}"
;;
esac
done
_pause
}
configure_greetd() {
while true; do
local -a gd_items=()
gd_items+=("1" "Install base greetd")
gd_items+=("2" "Install greetd + tuigreet (Recommended TUI greeter)")
if [ "$DEBIAN_VERSION" = "13" ]; then
gd_items+=("3" "Install gtkgreet (Requires manual setup)")
gd_items+=("4" "Install nwg-hello (Requires manual setup)")
gd_items+=("5" "Install wlgreet (Requires manual setup)")
gd_items+=("6" "Back")
else
gd_items+=("3" "Back")
fi
local choice
choice=$(_menu "greetd Configuration" \
"Select an option:" \
$TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \
"${gd_items[@]}")
[ -z "$choice" ] && return
clear
case "$choice" in
1)
echo "greetd shared/default-x-display-manager select greetd" | sudo debconf-set-selections
_run_cmd "greetd" "sudo apt install -y greetd" "Installing greetd..."
_msg "greetd" "Warning: greetd was installed but NOT configured.\n\nYou must manually create /etc/greetd/config.toml\nto be able to log in.\n\nSee 'man greetd' and 'man 5 greetd-sessions'."
;;
2)
if [ "$DEBIAN_VERSION" = "12" ]; then
if [ "$(is_backports_enabled)" != true ]; then
_write_deb822_backports "bookworm"
_ensure_apt_updated
fi
_run_cmd "greetd" "sudo apt install -y -t bookworm-backports tuigreet greetd" "Installing greetd + tuigreet..."
else
_run_cmd "greetd" "sudo apt install -y greetd tuigreet" "Installing greetd + tuigreet..."
fi
_msg "greetd" "Warning: greetd was installed but NOT configured.\n\nYou must manually create /etc/greetd/config.toml\nto be able to log in.\n\nSee 'man greetd' and 'man 5 greetd-sessions'."
;;
3)
if [ "$DEBIAN_VERSION" = "13" ]; then
echo "greetd shared/default-x-display-manager select greetd" | sudo debconf-set-selections
_run_cmd "greetd" "sudo apt install -y greetd gtkgreet" "Installing greetd + gtkgreet..."
_msg "greetd" "Warning: greetd was installed but NOT configured.\n\nYou must manually create /etc/greetd/config.toml\nto be able to log in.\n\nSee 'man greetd' and 'man 5 greetd-sessions'."
else
return
fi
;;
4)
if [ "$DEBIAN_VERSION" = "13" ]; then
echo "greetd shared/default-x-display-manager select greetd" | sudo debconf-set-selections
_run_cmd "greetd" "sudo apt install -y greetd nwg-hello" "Installing greetd + nwg-hello..."
_msg "greetd" "Warning: greetd was installed but NOT configured.\n\nYou must manually create /etc/greetd/config.toml\nto be able to log in.\n\nSee 'man greetd' and 'man 5 greetd-sessions'."
fi
;;
5)
if [ "$DEBIAN_VERSION" = "13" ]; then
echo "greetd shared/default-x-display-manager select greetd" | sudo debconf-set-selections
_run_cmd "greetd" "sudo apt install -y greetd wlgreet" "Installing greetd + wlgreet..."
_msg "greetd" "Warning: greetd was installed but NOT configured.\n\nYou must manually create /etc/greetd/config.toml\nto be able to log in.\n\nSee 'man greetd' and 'man 5 greetd-sessions'."
fi
;;
6) return ;;
esac
done
}
configure_gdm3() {
while true; do
local items_enabled=()
items_enabled+=("install" "Install/Reinstall gdm3 (Set as default)" "$(_state gdm3)")
items_enabled+=("userlist" "Hide user list (disable-user-list)" "OFF")
items_enabled+=("autologin" "Configure Autologin" "OFF")
if [ "$DEBIAN_VERSION" = "12" ] || [ "$DEBIAN_VERSION" = "13" ]; then
if [ "$HAS_NVIDIA" = true ]; then
items_enabled+=("wayland" "Force Enable Wayland on NVIDIA (Risk!)" "OFF")
fi
fi
local choice
choice=$(_checklist "GDM3 Configuration" \
"Select options to apply:" \
$TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \
"${items_enabled[@]}")
[ -z "$choice" ] && return
clear
local cleaned
cleaned=$(echo "$choice" | tr -d '"')
# SECURITY: Convert to array to avoid word splitting and command injection.
local -a gdm_items=()
while IFS= read -r _item; do
[ -n "$_item" ] && gdm_items+=("$_item")
done < <(echo "$cleaned" | tr ' ' '\n')
for item in "${gdm_items[@]}"; do
case $item in
install)
echo "gdm3 shared/default-x-display-manager select gdm3" | sudo debconf-set-selections
_run_cmd "GDM3" "sudo apt install -y gdm3" "Installing gdm3..."
;;
userlist)
local greeter_conf="/etc/gdm3/greeter.dconf-defaults"
if sudo grep -q '^disable-user-list=true' "$greeter_conf" 2>/dev/null; then
sudo sed -i 's/^disable-user-list=true/# disable-user-list=true/' "$greeter_conf"
echo -e "${GREEN}User list is now VISIBLE.${NC}"
else
sudo sed -i 's/^#[[:space:]]*disable-user-list=true/disable-user-list=true/' "$greeter_conf"
echo -e "${GREEN}User list is now HIDDEN.${NC}"
fi
sudo dpkg-reconfigure gdm3 >/dev/null 2>&1
;;
autologin)
local daemon_conf="/etc/gdm3/daemon.conf"
local username
username=$(_inputbox "GDM3 Autologin" \
"Enter username to autologin (leave empty to DISABLE autologin):" 10 60)
if [ -n "$username" ]; then
if ! [[ "$username" =~ ^[a-z_][a-z0-9_-]{0,31}$ ]]; then
_msg_red "GDM3 Autologin" "Invalid username: ${username}"
continue
fi
[ -f "$daemon_conf" ] || sudo touch "$daemon_conf"
sudo sed -i 's/^# *AutomaticLoginEnable[[:space:]=].*/AutomaticLoginEnable=true/' "$daemon_conf"
sudo sed -i "s|^# *AutomaticLogin[[:space:]=].*|AutomaticLogin=${username}|" "$daemon_conf"
echo -e "${GREEN}Autologin enabled for user: ${username}${NC}"
else
sudo sed -i 's/^AutomaticLoginEnable[[:space:]=].*/# AutomaticLoginEnable=false/' "$daemon_conf"
sudo sed -i 's/^AutomaticLogin[[:space:]=].*/# AutomaticLogin=/' "$daemon_conf"
echo -e "${GREEN}Autologin disabled.${NC}"
fi
;;
wayland)
local rules_link="/etc/udev/rules.d/61-gdm.rules"
if [ -L "$rules_link" ] || [ -f "$rules_link" ]; then
sudo rm -f "$rules_link"
echo -e "${GREEN}Reverted. Wayland will be disabled by default on next reboot.${NC}"
elif [ -f "/lib/udev/rules.d/61-gdm.rules" ]; then
if _confirm "Wayland on NVIDIA" \
"Force-enable Wayland on NVIDIA?\n\nRisk: This may break graphics or cause instability.\nProceed?"; then
sudo ln -s /dev/null "$rules_link"
echo -e "${GREEN}Wayland override created. Reboot required.${NC}"
fi
fi
;;
esac
done
_pause
done
}
# Ordered session candidates for SDDM autologin:
# Wayland first, then X11, per release. Existence
# decides (no codename gates). The LXQt sessions
# stay last for when the module starts offering LXQt.
_sddm_session_candidates() {
local wayland_dir="${SESSION_DIR_WAYLAND:-/usr/share/wayland-sessions}"
local x11_dir="${SESSION_DIR_X11:-/usr/share/xsessions}"
local candidate
for candidate in \
"$wayland_dir/plasmawayland.desktop" \
"$wayland_dir/plasma.desktop" \
"$x11_dir/plasma.desktop" \
"$x11_dir/plasmax11.desktop" \
"$wayland_dir/lxqt-wayland.desktop" \
"$x11_dir/lxqt.desktop"; do
if [ -f "$candidate" ]; then
basename "$candidate" .desktop
return 0
fi
done
return 0
}
configure_sddm() {
while true; do
local choice
choice=$(_menu "SDDM Configuration" \
"Select an option:" \
$TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \
"1" "Install SDDM (Set as default)" \
"2" "Enable Autologin" \
"3" "Back")
[ -z "$choice" ] && return
clear
case "$choice" in
1)
echo "sddm shared/default-x-display-manager select sddm" | sudo debconf-set-selections
_run_cmd "SDDM" "sudo apt install -y sddm" "Installing SDDM..."
;;
2)
local sddm_session=""
sddm_session=$(_sddm_session_candidates)
local sddm_user="${SUDO_USER:-}"
if [ -z "$sddm_user" ] || [ "$sddm_user" = "root" ]; then
sddm_user=$(awk -F: '$3>=1000 && $3<65534 {print $1}' /etc/passwd | head -1)
fi
sudo mkdir -p /etc/sddm.conf.d
cat <<EOF | sudo tee /etc/sddm.conf.d/autologin.conf >/dev/null
[Autologin]
User=${sddm_user}
Session=${sddm_session}
Relogin=false
EOF
if [ -n "$sddm_session" ]; then
echo -e "${GREEN}Autologin enabled for user ${sddm_user}, session: ${sddm_session}.${NC}"
else
echo -e "${YELLOW}Autologin enabled for user ${sddm_user}. No session set (SDDM will use default).${NC}"
fi
_pause
;;
3) return ;;
esac
done
}
# ── SP2 shared helpers ────────────────────────────
# Print the display manager already configured as the
# X11 default (/etc/X11/default-display-manager), or an
# enabled DM systemd unit; print nothing when none is
# found. Desktop installers use this to avoid overwriting
# an existing display manager setup.
_existing_display_manager() {
local dm=""
local dm_path=""
# Config path is overridable for tests (same pattern as
# APT_DIR): the suite must never read the real system file.
local dm_file="${DM_FILE:-/etc/X11/default-display-manager}"
if [ -s "$dm_file" ]; then
dm_path=$(cat "$dm_file" 2>/dev/null) || dm_path=""
[ -n "$dm_path" ] && dm=$(basename "$dm_path")
fi
if [ -z "$dm" ]; then
local cand
for cand in gdm3 lightdm sddm greetd gdm; do
if systemctl is-enabled "$cand" 2>/dev/null | grep -q '^enabled$'; then
dm="$cand"
break
fi
done
fi
printf '%s\n' "$dm"
}
# Offer the standard PipeWire audio stack right after a
# desktop install, when no PipeWire server is present
# yet. _install_pipewire_standard gates itself internally,
# so no pre-prompt is needed here. Declining is a choice,
# not an error: always ends in return 0 so it is safe as
# the last call of an installer.
_offer_pipewire_after_desktop() {
local pkg_check="pipewire-audio"
[ "$DEBIAN_VERSION" = "11" ] && pkg_check="pipewire"
is_installed "$pkg_check" && return 0
if _confirm "PipeWire Audio" \
"No PipeWire audio server is installed.\n\nInstall the PipeWire audio stack (recommended)?"; then
_install_pipewire_standard
fi
return 0
}