Restore restructured setup.sh (main was broken by 'corrections' merge)

The corrections commit replaced the lib/+modules/ entrypoint with the
older single-file version, reintroducing the DEBUG_MODE unbound-variable
crash, the unguarded clear, and TWM dispatch pointing at nonexistent
root-level scripts. lib/ and modules/ were orphaned.

Restores the tested restructured setup.sh + the SC2034 fix in lib/common.sh.
This commit is contained in:
Pathfinder
2026-10-27 10:30:17 +01:00
committed by yuri
parent 047eeebcc2
commit c443e4edf3
2 changed files with 239 additions and 196 deletions
+2
View File
@@ -27,6 +27,8 @@ BOLD='\033[1m'
RESET='\033[0m' RESET='\033[0m'
# Disable colors if output is not a terminal # Disable colors if output is not a terminal
# (PURPLE/BLUE/BOLD defined for future use; shellcheck has no way to know that)
# shellcheck disable=SC2034
if [ ! -t 1 ]; then if [ ! -t 1 ]; then
RED='' GREEN='' YELLOW='' CYAN='' PURPLE='' BLUE='' GRAY='' BOLD='' RESET='' RED='' GREEN='' YELLOW='' CYAN='' PURPLE='' BLUE='' GRAY='' BOLD='' RESET=''
fi fi
+237 -196
View File
@@ -5,231 +5,231 @@
# #
set -uo pipefail set -uo pipefail
#------------------------------------------ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Color helpers (printf-safe, no tput) # shellcheck source=lib/common.sh
#------------------------------------------ source "$SCRIPT_DIR/lib/common.sh"
RED='\033[0;31m' # shellcheck source=lib/session.sh
GREEN='\033[0;32m' source "$SCRIPT_DIR/lib/session.sh"
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 # Defaults + argument parsing
# DEBUG_MODE must be initialised before anything reads it under set -u. # DEBUG_MODE must be initialised before anything reads it under set -u.
#------------------------------------------ #------------------------------------------
pause_if_debug() { DEBUG_MODE=false
if [[ "${DEBUG_MODE:-false}" == "true" ]]; then ASSUME_YES=false
echo DE=""
color_yellow "----------------------------------------------------------------" TWM=""
read -rp "Section complete. Press [Enter] to continue, or [q] to abort: " debug_choice
if [[ "${debug_choice,,}" == "q" ]]; then usage() {
color_red "Script aborted by user." cat <<'EOF'
exit 1 setup.sh — unified Fedora configuration (Fedora 44+)
fi
color_yellow "----------------------------------------------------------------" Usage:
echo ./setup.sh interactive: pick a DE and a TWM
fi ./setup.sh --de=none --twm=niri non-interactive, explicit choices
./setup.sh --debug pause after each section
Options:
--de=NAME gnome | plasma | xfce | none
--twm=NAME chadwm | hyprland | mango | niri | none
-y, --yes never prompt (requires --de and --twm)
-d, --debug pause after each section instead of aborting on error
-h, --help show this help
Valid DE/TWM combinations:
any DE + any TWM DE provides the session, TWM is added alongside it
none + any TWM TWM-only machine, SDDM is installed as the greeter
any DE + none plain desktop, no tiling window manager
none + none refused: that is not a graphical system
Notes:
* chadwm is an X11 window manager; the other three are Wayland compositors.
* Run as your normal user, not root. sudo is used where needed.
EOF
} }
install_packages() { sudo dnf install -y "$@"; } for arg in "$@"; do
is_package_installed() { rpm -q "$@" &>/dev/null; } case "$arg" in
-d|--debug) DEBUG_MODE=true ;;
remove_packages() { -y|--yes) ASSUME_YES=true ;;
local packages_to_remove=() --de=*) DE="${arg#*=}" ;;
for pkg in "$@"; do --twm=*) TWM="${arg#*=}" ;;
if is_package_installed "$pkg"; then -h|--help) usage; exit 0 ;;
packages_to_remove+=("$pkg") *)
fi err "Unknown argument: $arg"
done printf "\n"
usage
if [ ${#packages_to_remove[@]} -gt 0 ]; then exit 2
color_cyan "Removing packages: ${packages_to_remove[*]}" ;;
sudo dnf remove -y "${packages_to_remove[@]}" esac
fi done
} export DEBUG_MODE ASSUME_YES
if is_debug; then
set +e # walk through failures instead of dying on the first one
else
set -e
fi
#------------------------------------------ #------------------------------------------
# Preconditions # Preconditions
#------------------------------------------ #------------------------------------------
# clear can fail without TERM (cron, piped install, ssh without a tty) and would
# abort the whole run under set -e.
clear 2>/dev/null || true
#------------------------------------------ printf "\n"
# Script Version 1.0 color_yellow "----------------------------------------------------------------"
#------------------------------------------ color_yellow "Fedora unified configuration"
clear # Wipe the terminal history view cleanly for the main menu execution color_yellow "----------------------------------------------------------------"
if [[ "$DEBUG_MODE" == "true" ]]; then if [[ ${EUID} -eq 0 ]]; then
color_red "!!! DEBUG MODE ENABLED !!!" err "Do not run this as root. Run it as your user; it calls sudo itself."
color_red "The script will pause after each major section." exit 1
echo
fi fi
echo if [[ "$ASSUME_YES" == "true" && ( -z "$DE" || -z "$TWM" ) ]]; then
color_yellow "----------------------------------------------------------------" err "--yes requires explicit --de and --twm, so nothing is guessed on an"
color_yellow "Script version 1.0" err "unattended run. Example:"
color_yellow "----------------------------------------------------------------" err " ./setup.sh --yes --de=none --twm=niri"
echo exit 2
fi
if is_debug; then
color_red "!!! DEBUG MODE ENABLED !!!"
color_red "The script will pause after each section."
fi
#------------------------------------------ #------------------------------------------
# OS gate — Fedora only, 44+ # OS gate — Fedora only, 44+
#------------------------------------------ #------------------------------------------
echo step "OS detection"
color_yellow "----------------------------------------------------------------" rule
color_yellow "Start OS Detection"
color_yellow "----------------------------------------------------------------"
echo
source /etc/os-release # Overridable so the script can be tested on a non-Fedora host.
OS_RELEASE_FILE="${OS_RELEASE_FILE:-/etc/os-release}"
# shellcheck source=/dev/null
source "$OS_RELEASE_FILE"
OS_ID="${ID,,}" OS_ID="${ID:-unknown}"; OS_ID="${OS_ID,,}"
OS_LIKE="${ID_LIKE:-}" OS_PRETTY="${PRETTY_NAME:-unknown}"
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 if [[ "$OS_ID" != "fedora" ]]; then
fedora) OS="fedora" ;; err "Unsupported distribution: $OS_PRETTY (ID=${OS_ID})"
*) err "This repo targets Fedora only. RHEL clones are refused on purpose:"
if [[ "$OS_LIKE" == *"fedora"* || "$OS_LIKE" == *"rhel"* ]]; then err "they ship no dnf5 config-manager and no RPM Fusion, so both the base"
OS="fedora" err "setup and every module would fail half-way."
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 exit 1
fi fi
FEDORA_REL=$(rpm -E %fedora)
if [[ "$FEDORA_REL" =~ ^[0-9]+$ ]] && (( FEDORA_REL < 44 )); then
err "$OS_PRETTY reports release ${FEDORA_REL}, but this setup targets Fedora 44+."
exit 1
fi
ok "Detected: $OS_PRETTY (release ${FEDORA_REL})"
pause_if_debug pause_if_debug
#------------------------------------------ #------------------------------------------
# 1 Base settings # 1 Base settings
#------------------------------------------ #------------------------------------------
echo step "1 Base settings"
color_yellow "----------------------------------------------------------------" rule
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 if ! command -v curl >/dev/null 2>&1; then
info "curl missing. Installing..." info "curl missing. Installing..."
install_packages curl install_packages curl
fi fi
pause_if_debug # config-manager lives in dnf5-plugins; every repo step below depends on it.
if ! dnf config-manager --help >/dev/null 2>&1; then
info "dnf config-manager missing. Installing dnf5-plugins..."
install_packages dnf5-plugins
fi
#------------------------------------------ info "Tuning DNF..."
# 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 max_parallel_downloads=20
sudo dnf config-manager setopt defaultyes=True sudo dnf config-manager setopt defaultyes=True
color_green "DNF optimized. Refreshing metadata..." info "Refreshing metadata..."
sudo dnf makecache --refresh sudo dnf makecache --refresh
color_cyan "Enabling RPM Fusion repositories for Fedora $(rpm -E %fedora)..." add_rpmfusion_repo
pause_if_debug
# Define the version variable for readability if ! command -v flatpak >/dev/null 2>&1; then
FEDORA_VER=$(rpm -E %fedora) info "Flatpak missing. Installing..."
install_packages flatpak
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 fi
info "Ensuring Flathub is available (system-wide)..."
sudo flatpak remote-add --if-not-exists --system flathub https://dl.flathub.org/repo/flathub.flatpakrepo
color_cyan "Enabling Flathub..." info "Updating the system..."
# 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 sudo dnf update -y
pause_if_debug pause_if_debug
#------------------------------------------
# Tiling Window Manager Selection
#------------------------------------------
echo
color_yellow "----------------------------------------------------------------"
color_yellow "Tiling WM Selection"
color_yellow "----------------------------------------------------------------"
echo
while true; do #------------------------------------------
echo # 2 Menu helpers
color_gray "Select a tiling window manager:" #------------------------------------------
echo # $1 = prompt, $2 = default answer, rest = valid answers
echo " 1) CHADWM" ask_choice() {
echo " 2) Hyprland" local prompt="$1" default="$2"; shift 2
echo " 3) MangoWC" local answer
echo " 4) Niri" if [[ "$ASSUME_YES" == "true" ]]; then
echo " x) None (default)" echo "$default"
if ! read -t 15 -rp "Enter choice [1/2/3/4/x] (default: x): " choice; then return 0
choice="x"
fi fi
while true; do
if ! read -t 60 -rp "$prompt (default: $default): " answer; then
printf "\n"
answer=""
fi
answer="${answer:-$default}"
answer="${answer,,}"
local v
for v in "$@"; do
if [[ "$answer" == "$v" ]]; then
echo "$answer"
return 0
fi
done
err "Invalid option: '$answer'. Choose from: $*"
done
}
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 # 3 Desktop environment selection
#------------------------------------------
if [[ -z "$DE" ]]; then
step "3 Desktop environment"
rule
printf "\n"
color_gray " This system is treated as a bare Fedora install — picking a DE"
color_gray " here is what gives you a graphical login."
printf "\n"
echo " 1) GNOME (gdm)"
echo " 2) Plasma (sddm)"
echo " 3) XFCE (lightdm)"
echo " 4) None (TWM only — SDDM will be installed by the TWM module)"
printf "\n"
choice=$(ask_choice "Select desktop environment [1/2/3/4]" "1" 1 2 3 4)
case "$choice" in
1) DE="gnome" ;;
2) DE="plasma" ;;
3) DE="xfce" ;;
4) DE="none" ;;
esac
fi
case "$DE" in
gnome|plasma|xfce|none) ;;
*) err "Unknown --de value: '$DE' (gnome|plasma|xfce|none)"; exit 2 ;;
esac
pause_if_debug
#------------------------------------------
# 4 Tiling window manager selection
#------------------------------------------ #------------------------------------------
if [[ -z "$TWM" ]]; then if [[ -z "$TWM" ]]; then
step "4 Tiling window manager" step "4 Tiling window manager"
@@ -252,33 +252,74 @@ if [[ -z "$TWM" ]]; then
fi fi
case "$TWM" in case "$TWM" in
chadwm|hyprland|mango|niri) niri|hyprland|mango|chadwm|none) ;;
color_yellow "Installing $TWM" *) err "Unknown --twm value: '$TWM' (niri|hyprland|mango|chadwm|none)"; exit 2 ;;
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 esac
ok "Selection: DE=${DE} TWM=${TWM}"
# A bare install with neither is not a graphical system. Refuse rather than
# leave the user with a machine that boots to a black screen.
if [[ "$DE" == "none" && "$TWM" == "none" ]]; then
err "DE=none with TWM=none would leave no graphical session at all."
err "Pick a desktop environment, a tiling window manager, or both."
exit 2
fi
pause_if_debug pause_if_debug
echo #------------------------------------------
color_yellow "----------------------------------------------------------------" # 5 Dispatch
color_yellow "End Detection" #------------------------------------------
color_yellow "----------------------------------------------------------------" export DE TWM
color_green "Fedora setup complete." run_module() {
color_red "The installation has finished. A reboot is recommended." local path="$1"
# Reboots are dangerous to automate; we use a shorter timeout and default to No if [[ ! -f "$path" ]]; then
if read -t 10 -rp "Reboot now? [y/N]: " reboot_choice; then err "Module not found: $path"
return 1
fi
info "Running $(basename "$path")"
printf "\n"
# Separate process: a module's own shell options and exit codes stay its own.
bash "$path"
}
step "5 Installation"
rule
if [[ "$DE" != "none" ]]; then
run_module "$SCRIPT_DIR/modules/de/${DE}.sh"
pause_if_debug
fi
if [[ "$TWM" != "none" ]]; then
run_module "$SCRIPT_DIR/modules/twm/${TWM}.sh"
pause_if_debug
fi
#------------------------------------------
# 6 Done
#------------------------------------------
step "6 Summary"
rule
ok "DE: $DE"
ok "TWM: $TWM"
DM=$(detect_display_manager)
ok "Display manager: ${DM:-none}"
if [[ -z "$DM" ]]; then
warn "No display manager is active. You will boot to a text console."
warn "Install one, or run a TWM module which sets up SDDM."
fi
printf "\n"
color_green "Fedora setup complete. A reboot is recommended."
if [[ "$ASSUME_YES" == "true" ]]; then
info "Unattended run: not rebooting."
exit 0
fi
if read -t 15 -rp "Reboot now? [y/N]: " reboot_choice; then
case "${reboot_choice,,}" in case "${reboot_choice,,}" in
y|yes) y|yes)
color_red "Rebooting now." color_red "Rebooting now."