#!/bin/bash set -euo pipefail # Map the exported variables to your local names with fallbacks to satisfy set -u OS="${DETECTED_OS:-fedora}" DE="${SELECTED_DE:-xfce}" TWM="${SELECTED_TWM:-none}" INSTALL_LEVEL="${INSTALL_LEVEL:-minimal}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo color_cyan "Starting Fedora XFCE setup..." echo #------------------------------------------ # Helper functions #------------------------------------------ install_packages() { sudo dnf install -y "$@"; } is_package_installed() { rpm -q "$@" &>/dev/null; } detect_de() { echo "${XDG_CURRENT_DESKTOP:-${DESKTOP_SESSION:-}}" } detect_display_manager() { if systemctl is-active --quiet sddm; then echo "sddm" elif systemctl is-active --quiet lightdm; then echo "lightdm" elif systemctl is-active --quiet gdm; then echo "gdm" else echo "none" fi } enable_graphical_target() { sudo systemctl set-default graphical.target } #------------------------------------------ # Main Execution Flow #------------------------------------------ echo color_yellow "Starting XFCE installation..." CURRENT_DE="$(detect_de)" CURRENT_DM="$(detect_display_manager)" if [[ -z "$CURRENT_DE" || "$CURRENT_DE" == "none" ]]; then color_cyan "No Desktop Environment detected. Installing XFCE (light setup with SDDM)..." # 1. Install core XFCE desktop components + SDDM install_packages sddm xfce4-session xfce4-settings xfwm4 xfce4-panel xfdesktop Thunar xorg-x11-xinit xorg-x11-server-Xorg xhost # 2. Install the XFCE core plugins safely via DNF group/virtual syntax install_packages @xfce-extra-plugins enable_graphical_target sudo systemctl enable sddm color_green "XFCE with SDDM installed successfully. You can reboot now to start XFCE." else color_cyan "Detected existing Desktop Environment: $CURRENT_DE" if [[ "$CURRENT_DM" == "lightdm" ]]; then color_yellow "LightDM is currently active. Replacing with SDDM..." sudo systemctl disable lightdm sudo dnf remove -y lightdm lightdm-gtk-greeter install_packages sddm sudo systemctl enable sddm enable_graphical_target color_green "LightDM removed and replaced with SDDM." else color_cyan "Current display manager: ${CURRENT_DM}. Leaving unchanged." fi fi pause_if_debug #------------------------------------------ # XFCE-specific configuration #------------------------------------------ if [[ "${DE}" == "xfce" || "${DDE}" == "xfce" ]]; then echo color_cyan "Applying XFCE defaults: fonts, browser, and terminal..." # Ensure xfconf-query exists (for XFCE settings) if ! command -v xfconf-query >/dev/null 2>&1; then color_yellow "xfconf-query not found — installing xfce4-settings..." install_packages xfce4-settings fi pause_if_debug # Set fonts via xfconf-query if command -v xfconf-query >/dev/null 2>&1; then # Interface font (UI) xfconf-query -c xsettings -p /Gtk/FontName -s "RobotoMono Nerd Font Regular 10" || true # Monospace font (terminals, editors) xfconf-query -c xsettings -p /Gtk/MonospaceFontName -s "RobotoMono Nerd Font Mono Regular 10" || true color_green "XFCE fonts updated successfully!" else color_yellow "xfconf-query not found — skipping XFCE font config (will apply at first login)." fi pause_if_debug # Set default terminal to Alacritty if command -v alacritty >/dev/null 2>&1; then # 1. Force initialize the base XDG/XFCE config hierarchy mkdir -p "$HOME/.config/xfce4" mkdir -p "$HOME/.config/menus" # 2. Configure XFCE's preferred application files HELPERS_FILE="$HOME/.config/xfce4/helpers.rc" touch "$HELPERS_FILE" for entry in TerminalEmulator TerminalEmulatorCommand; do if grep -q "^${entry}=" "$HELPERS_FILE"; then sed -i "s|^${entry}=.*|${entry}=alacritty|" "$HELPERS_FILE" else echo "${entry}=alacritty" >> "$HELPERS_FILE" fi done # 3. Create the missing standard XDG MIME association files manually MIME_FILE="$HOME/.config/mimeapps.list" touch "$MIME_FILE" # Rewrite/initialize the file cleanly with explicit defaults cat < "$MIME_FILE" [Default Applications] x-scheme-handler/terminal=alacritty.desktop user-extension/x-terminal-emulator=alacritty.desktop EOF # 4. Handle System-Wide Alternatives (For Debian/Ubuntu/Fedora base integrations) # This covers the underlying system-wide 'x-terminal-emulator' mapping if command -v update-alternatives >/dev/null 2>&1; then if [ -f "/usr/share/applications/alacritty.desktop" ] || [ -f "/usr/local/share/applications/alacritty.desktop" ]; then sudo update-alternatives --set x-terminal-emulator $(which alacritty) 2>/dev/null || true fi fi # 5. Pre-seed Xfconf properties directly into the XML tree file structure # Since xfconfd might not be running yet, we write the raw file backup structure directly XFCONF_DIR="$HOME/.config/xfce4/xfconf/xfce-perchannel-xml" mkdir -p "$XFCONF_DIR" # Pre-populate the session XML so xfce skips selection entirely on first boot cat < "$XFCONF_DIR/xfce4-session.xml" EOF color_green "XFCE default terminal configurations written directly to persistent user storage!" fi pause_if_debug # End of script color_green "XFCE / SDDM setup completed."