#!/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 "$@"; } is_package_installed() { pacman -Qi "$@" &>/dev/null; } remove_packages() { local packages_to_remove=() # 1. Identify which packages are actually installed for pkg in "$@"; do if is_package_installed "$pkg"; then packages_to_remove+=("$pkg") else say_gray "Package '$pkg' not found. Skipping removal." fi done # 2. Only run pacman if there are packages to remove if [ ${#packages_to_remove[@]} -gt 0 ]; then say_cyan "Removing packages: ${packages_to_remove[*]}" sudo pacman -Rs --noconfirm "${packages_to_remove[@]}" || true else say_gray "No packages to remove from the list." fi } detect_de() { if command -v plasmashell >/dev/null 2>&1; then echo "kde" 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 KDE Plasma installation..." CURRENT_DE="$(detect_de)" CURRENT_DM="$(detect_display_manager)" if [[ -z "$CURRENT_DE" || "$CURRENT_DE" != "kde" ]]; then say_cyan -e "KDE Plasma not detected. Installing KDE Plasma (light setup with SDDM)..." install_packages sddm plasma enable_graphical_target say_green -e "KDE Plasma 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 gst-libav qt5-graphicaleffects qt5-quickcontrols qt5-quickcontrols2 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 ###### TODO ### from paru install pamac-tray-icon-plasma ### let autostart pamac-tray-plasma # End of script say_green -e "KDE Plasma / SDDM setup completed."