#!/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:-none}" TWM="${SELECTED_TWM:-none}" INSTALL_LEVEL="${INSTALL_LEVEL:-full}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo color_cyan "Starting Fedora Full setup..." echo #------------------------------------------ # Helper functions #------------------------------------------ install_packages() { sudo dnf install -y "$@"; } is_package_installed() { rpm -q "$@" &>/dev/null; } detect_de() { # Check if a desktop session is currently running or XFCE is available if [ "${XDG_CURRENT_DESKTOP:-}" ]; then echo "${XDG_CURRENT_DESKTOP,,}" # lowercase the output elif command -v xfce4-session >/dev/null 2>&1; then echo "xfce" else echo "" fi } detect_display_manager() { # Fedora/Systemd way to check the active DM symlink if [ -L /etc/systemd/system/display-manager.service ]; then basename "$(readlink /etc/systemd/system/display-manager.service)" | sed 's/\.service//' else echo "" fi } switch_display_manager() { local target_dm="$1" local current_dm current_dm=$(detect_display_manager) if [[ "$current_dm" != "$target_dm" ]]; then if [[ -n "$current_dm" ]]; then say_yellow "Disabling existing display manager: $current_dm" sudo systemctl disable "$current_dm" fi say_yellow "Enabling $target_dm..." sudo systemctl enable "$target_dm" fi sudo systemctl set-default graphical.target } #------------------------------------------ # Start installation #------------------------------------------ say_yellow "Starting Niri setup..." CURRENT_DE="$(detect_de)" CURRENT_DM="$(detect_display_manager)" # Add Terra repo add_terra_repo() { if [ ! -f /etc/yum.repos.d/terra.repo ]; then say_yellow "Adding Terra repository for Noctalia Shell..." TMP_FILE="/tmp/terra.repo" curl -fsSL https://github.com/terrapkg/subatomic-repos/raw/main/terra.repo -o "$TMP_FILE" && sudo mv "$TMP_FILE" /etc/yum.repos.d/terra.repo say_yellow "Clearing DNF cache..." sudo dnf clean metadata else say_gray "Terra repository already configured." fi } pause_if_debug # Core components for Niri & Noctalia setup NIRI_PACKAGES=(niri fuzzel swaybg swaylock noctalia-shell) if [[ -z "$CURRENT_DE" || "$CURRENT_DE" == "none" || "$CURRENT_DE" == "sway" ]]; then say_cyan "No Desktop Environment detected. Installing Niri + Noctalia Shell..." # 1. Add the repo first add_terra_repo # 2. Install everything install_packages sddm "${NIRI_PACKAGES[@]}" switch_display_manager "sddm" say_green "Niri, Noctalia, and SDDM installed successfully." else say_cyan "Detected existing Desktop Environment: $CURRENT_DE" # Always install the window manager packages install_packages "${NIRI_PACKAGES[@]}" if [[ "$CURRENT_DM" == "lightdm" ]]; then say_yellow "LightDM is currently active. Replacing with SDDM..." # Fedora equivalent to purge lightdm safely sudo dnf remove -y lightdm lightdm-gtk install_packages sddm switch_display_manager "sddm" say_green "LightDM removed and replaced with SDDM." else say_cyan "Current display manager: ${CURRENT_DM:-none}. Leaving it to handle Niri login sessions." fi fi pause_if_debug # End of script say_green "Niri / SDDM setup completed."