#!/bin/bash set -uo pipefail #------------------------------------------ # Argument parsing (must come before anything reads DEBUG_MODE) #------------------------------------------ DEBUG_MODE=false for arg in "$@"; do case "$arg" in -d|--debug) DEBUG_MODE=true ;; -h|--help) cat <<'EOF' Usage: ./setup.sh [-d|--debug] -d, --debug Pause after each section instead of aborting on error -h, --help Show this help EOF exit 0 ;; *) echo "Unknown argument: $arg (try --help)" >&2; exit 2 ;; esac done export DEBUG_MODE # Abort on error unless we are walking through it step by step if [[ "$DEBUG_MODE" == "true" ]]; then set +e else set -e fi #------------------------------------------ # 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"; } #------------------------------------------ # Helper functions #------------------------------------------ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 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 } #------------------------------------------ # 0 STARTING the script #------------------------------------------ #------------------------------------------ # Script Version 1.1 #------------------------------------------ # Wipe the terminal history view cleanly. Guarded: without TERM (cron, piped # installs, ssh without a tty) `clear` fails and would abort the whole run. clear 2>/dev/null || true 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.1" color_yellow "----------------------------------------------------------------" echo #------------------------------------------ # OS Detection #------------------------------------------ echo color_yellow "----------------------------------------------------------------" color_yellow "Start OS Detection" color_yellow "----------------------------------------------------------------" echo source /etc/os-release OS_ID="${ID:-unknown}"; OS_ID="${OS_ID,,}" OS_LIKE="${ID_LIKE:-}"; OS_LIKE="${OS_LIKE,,}" OS_VERSION="${VERSION_ID:-unknown}" OS_PRETTY="${PRETTY_NAME:-unknown}" OS="" 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 # Minimum supported release: this repo targets Fedora 44 and newer. FEDORA_REL=$(rpm -E %fedora) if [[ "$FEDORA_REL" =~ ^[0-9]+$ ]] && (( FEDORA_REL < 44 )); then color_red "$OS_PRETTY reports release $FEDORA_REL, but this setup targets Fedora 44+." color_red "Refusing to continue. Re-run on F44 or newer." exit 1 fi pause_if_debug #------------------------------------------ # 1 Basic 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 color_yellow "curl is not installed. Installing..." install_packages curl fi # config-manager lives in dnf5-plugins; make sure it is present before using it if ! dnf config-manager --help >/dev/null 2>&1; then color_yellow "dnf config-manager missing. Installing dnf5-plugins..." install_packages dnf5-plugins 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 # Define the version variable for readability FEDORA_VER=$(rpm -E %fedora) color_cyan "Enabling RPM Fusion repositories for Fedora ${FEDORA_VER}..." # 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 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 Flathub (system-wide)..." # --if-not-exists keeps this idempotent on re-runs sudo flatpak remote-add --if-not-exists --system flathub https://dl.flathub.org/repo/flathub.flatpakrepo # Update the system color_gray "Updating the system" echo sudo dnf update -y pause_if_debug #------------------------------------------ # 2 Tiling Window Manager Selection #------------------------------------------ echo color_yellow "----------------------------------------------------------------" color_yellow "2 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 "----------------------------------------------------------------" export TWM pause_if_debug #------------------------------------------ # 3 Tiling Window Manager installation #------------------------------------------ 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" # Run in a subshell: a module's set -e / exit cannot leak into this script ( 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