#!/bin/bash set -euo pipefail ########################## # Color helpers (printf-safe, no tput) ########################## RED="\033[0;31m" GREEN="\033[0;32m" YELLOW="\033[0;33m" CYAN="\033[0;36m" GRAY="\033[0;37m" BOLD="\033[1m" RESET="\033[0m" # Disable colors if output is not a terminal if [ ! -t 1 ]; then RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" fi say_red() { printf "\n"; printf "%b%s%b\n" "$RED" "$*" "$RESET"; } say_green() { printf "\n"; printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } say_yellow() { printf "\n"; printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } say_cyan() { printf "\n"; printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } say_gray() { printf "\n"; printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } say_bold() { printf "\n"; printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } ########################## # Use exported variables from main detection script ########################## OS="${DETECTED_OS}" DDE="${DETECTED_DE}" DE="${SELECTED_DE:-none}" TWM="${SELECTED_TWM:-none}" INSTALL_LEVEL="${INSTALL_LEVEL:-minimal}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ########################## # Helper functions ########################## install_packages() { sudo pacman -S --noconfirm --needed "$@"; } remove_packages() { sudo pacman -Rs --noconfirm "$@"; } is_package_installed() { pacman -Qi "$@" &>/dev/null; } detect_de() { if command -v xfce4-session >/dev/null 2>&1; then echo "xfce" else echo "" fi } detect_display_manager() { if [ -f /etc/X11/default-display-manager ]; then basename "$(cat /etc/X11/default-display-manager)" else echo "" fi } enable_graphical_target() { sudo systemctl enable sddm sudo systemctl set-default graphical.target } ########################## # Start installation ########################## say_yellow -e "Starting XFCE installation..." CURRENT_DE="$(detect_de)" CURRENT_DM="$(detect_display_manager)" if [[ -z "$CURRENT_DE" || "$CURRENT_DE" != "xfce" ]]; then say_cyan -e "XFCE4 not detected. Installing XFCE (light setup with SDDM)..." install_packages sddm xfce4 xfce4-goodies enable_graphical_target say_green -e "XFCE with SDDM installed successfully. You can reboot now to start XFCE." else say_cyan -e "Detected existing Desktop Environment: $CURRENT_DE. Checking Display Manager..." # Check and replace other Display Managers if they conflict with the preferred SDDM setup if [[ "$CURRENT_DM" != "sddm" ]]; then say_yellow -e "Display manager **$CURRENT_DM** is currently active. Replacing with **SDDM**, the default for KDE Plasma..." # Attempt to disable the old DM if detected if [ ! -z "$CURRENT_DM" ]; then sudo systemctl disable "$CURRENT_DM" || true fi # Remove common alternative DMs if they exist to prevent conflicts if is_package_installed lightdm; then say_gray -e "Removing lightdm..." remove_packages lightdm lightdm-gtk-greeter || true fi if is_package_installed gdm; then say_gray -e "Removing gdm..." remove_packages gdm || true fi # Ensure SDDM is installed and enabled install_packages sddm enable_graphical_target say_green -e "Old display manager removed and replaced with SDDM." else say_cyan -e "Current display manager is already **SDDM**. Leaving unchanged." fi fi # End of script say_green -e "XFCE / SDDM setup completed."