#!/bin/bash # # setup.sh — unified Fedora configuration # Target: bare/minimal Fedora 44 and newer # set -uo pipefail #------------------------------------------ # Color helpers (printf-safe, no tput) #------------------------------------------ RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' CYAN='\033[0;36m' PURPLE='\033[0;35m' BLUE='\033[0;34m' 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='' PURPLE='' BLUE='' GRAY='' BOLD='' RESET='' fi color_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } color_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } color_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } color_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } color_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } #------------------------------------------ # Defaults + argument parsing # DEBUG_MODE must be initialised before anything reads it under set -u. #------------------------------------------ pause_if_debug() { if [[ "${DEBUG_MODE:-false}" == "true" ]]; then echo color_yellow "----------------------------------------------------------------" read -rp "Section complete. Press [Enter] to continue, or [q] to abort: " debug_choice if [[ "${debug_choice,,}" == "q" ]]; then color_red "Script aborted by user." exit 1 fi color_yellow "----------------------------------------------------------------" echo fi } install_packages() { sudo dnf install -y "$@"; } is_package_installed() { rpm -q "$@" &>/dev/null; } remove_packages() { local packages_to_remove=() for pkg in "$@"; do if is_package_installed "$pkg"; then packages_to_remove+=("$pkg") fi done if [ ${#packages_to_remove[@]} -gt 0 ]; then color_cyan "Removing packages: ${packages_to_remove[*]}" sudo dnf remove -y "${packages_to_remove[@]}" fi } #------------------------------------------ # Preconditions #------------------------------------------ #------------------------------------------ # Script Version 1.0 #------------------------------------------ clear # Wipe the terminal history view cleanly for the main menu execution if [[ "$DEBUG_MODE" == "true" ]]; then color_red "!!! DEBUG MODE ENABLED !!!" color_red "The script will pause after each major section." echo fi echo color_yellow "----------------------------------------------------------------" color_yellow "Script version 1.0" color_yellow "----------------------------------------------------------------" echo #------------------------------------------ # OS gate — Fedora only, 44+ #------------------------------------------ echo color_yellow "----------------------------------------------------------------" color_yellow "Start OS Detection" color_yellow "----------------------------------------------------------------" echo source /etc/os-release OS_ID="${ID,,}" OS_LIKE="${ID_LIKE:-}" OS_LIKE="${OS_LIKE,,}" OS_VERSION="${VERSION_ID:-unknown}" OS_PRETTY="$PRETTY_NAME" OS="" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" case "$OS_ID" in fedora) OS="fedora" ;; *) if [[ "$OS_LIKE" == *"fedora"* || "$OS_LIKE" == *"rhel"* ]]; then OS="fedora" fi ;; esac if [[ -n "$OS" ]]; then color_cyan "----------------------------------------------------------------" color_cyan "Detected OS: $OS_PRETTY" color_cyan "Version: $OS_VERSION" color_cyan "----------------------------------------------------------------" else color_red "----------------------------------------------------------------" color_red "ERROR: Unsupported or unknown Linux distribution." color_red "Detected: ID=$OS_ID ID_LIKE=${OS_LIKE:-empty}" color_red "----------------------------------------------------------------" exit 1 fi pause_if_debug #------------------------------------------ # 1 Base settings #------------------------------------------ echo color_yellow "----------------------------------------------------------------" color_yellow "1 Basic Settings" color_yellow "----------------------------------------------------------------" echo #------------------------------------------ # 1.1 Ensure base is ready for installation #------------------------------------------ if ! command -v curl >/dev/null 2>&1; then info "curl missing. Installing..." install_packages curl fi pause_if_debug #------------------------------------------ # 1.2 Update and Enable Repos + Flatpak #------------------------------------------ color_cyan "Optimizing DNF for speed..." # 1. Increase parallel downloads (allows downloading multiple packages at once) # 2. Set dnf to set YES as default instead of NO sudo dnf config-manager setopt max_parallel_downloads=20 sudo dnf config-manager setopt defaultyes=True color_green "DNF optimized. Refreshing metadata..." sudo dnf makecache --refresh color_cyan "Enabling RPM Fusion repositories for Fedora $(rpm -E %fedora)..." # Define the version variable for readability FEDORA_VER=$(rpm -E %fedora) color_yellow "Checking for updates and sources..." sudo dnf check-update || true # Check if flatpak is installed, if not, install it if ! command -v flatpak &> /dev/null; then color_yellow "Flatpak not found. Installing..." sudo dnf install -y flatpak fi color_cyan "Enabling Flathub..." # Using --if-not-exists is good practice to prevent errors on re-runs sudo flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo sudo dnf install -y \ "https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-${FEDORA_VER}.noarch.rpm" \ "https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-${FEDORA_VER}.noarch.rpm" color_cyan "Enabling full Flathub support..." flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo # Update the system color_gray "Updating the system" echohttps://git.ku-it.org/terrabeam/starburst.git sudo dnf update -y pause_if_debug #------------------------------------------ # Tiling Window Manager Selection #------------------------------------------ echo color_yellow "----------------------------------------------------------------" color_yellow "Tiling WM Selection" color_yellow "----------------------------------------------------------------" echo while true; do echo color_gray "Select a tiling window manager:" echo echo " 1) CHADWM" echo " 2) Hyprland" echo " 3) MangoWC" echo " 4) Niri" echo " x) None (default)" if ! read -t 15 -rp "Enter choice [1/2/3/4/x] (default: x): " choice; then choice="x" fi case "${choice,,}" in 1) TWM="chadwm"; break ;; 2) TWM="hyprland"; break ;; 3) TWM="mango"; break ;; 4) TWM="niri"; break ;; x|"") TWM="none"; break ;; *) echo "Invalid option. Please enter 1, 2, 3, 4 or x." ;; esac done echo color_cyan "----------------------------------------------------------------" color_cyan "Selected Tiling WM: $TWM" color_cyan "----------------------------------------------------------------" pause_if_debug #------------------------------------------ # 5. Tiling Window Manager installation #------------------------------------------ if [[ -z "$TWM" ]]; then step "4 Tiling window manager" rule printf "\n" echo " 1) Niri (Wayland, scrollable)" echo " 2) Hyprland (Wayland, dynamic)" echo " 3) MangoWC (Wayland, dwl-based, Terra repo)" echo " 4) chadwm (X11, dwm fork, built from source)" echo " 5) None" printf "\n" choice=$(ask_choice "Select tiling window manager [1/2/3/4/5]" "1" 1 2 3 4 5) case "$choice" in 1) TWM="niri" ;; 2) TWM="hyprland" ;; 3) TWM="mango" ;; 4) TWM="chadwm" ;; 5) TWM="none" ;; esac fi case "$TWM" in chadwm|hyprland|mango|niri) color_yellow "Installing $TWM" SCRIPT_NAME="$SCRIPT_DIR/${TWM}.sh" if [[ -f "$SCRIPT_NAME" ]]; then color_cyan "Running $SCRIPT_NAME" source "$SCRIPT_NAME" else color_red "Error: $SCRIPT_NAME not found!" exit 1 fi ;; none) color_gray "No tiling window manager selected, skipping TWM installation." ;; esac pause_if_debug echo color_yellow "----------------------------------------------------------------" color_yellow "End Detection" color_yellow "----------------------------------------------------------------" color_green "Fedora setup complete." color_red "The installation has finished. A reboot is recommended." # Reboots are dangerous to automate; we use a shorter timeout and default to No if read -t 10 -rp "Reboot now? [y/N]: " reboot_choice; then case "${reboot_choice,,}" in y|yes) color_red "Rebooting now." sudo reboot ;; *) color_yellow "Skipping reboot." exit 0 ;; esac else color_yellow "No input detected. Skipping reboot for safety." exit 0 fi