Files
fedora/setup.sh
T
Pathfinder 1cd8d26d01 XFCE on SDDM; menu defaults to none for DE and TWM
- XFCE module installs/enables sddm instead of lightdm; one greeter across
  every session choice, no lightdm left anywhere.
- Interactive menus now default to 'none' for both DE and TWM (press Enter
  for no DE / no TWM). none+none is still refused by the existing guard.
- README and session.sh comments updated to match.
2026-10-27 11:06:50 +01:00

337 lines
9.4 KiB
Bash
Executable File

#!/bin/bash
#
# setup.sh — unified Fedora configuration
# Target: bare/minimal Fedora 44 and newer
#
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib/common.sh
source "$SCRIPT_DIR/lib/common.sh"
# shellcheck source=lib/session.sh
source "$SCRIPT_DIR/lib/session.sh"
#------------------------------------------
# Defaults + argument parsing
# DEBUG_MODE must be initialised before anything reads it under set -u.
#------------------------------------------
DEBUG_MODE=false
ASSUME_YES=false
DE=""
TWM=""
usage() {
cat <<'EOF'
setup.sh — unified Fedora configuration (Fedora 44+)
Usage:
./setup.sh interactive: pick a DE and a TWM
./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
}
for arg in "$@"; do
case "$arg" in
-d|--debug) DEBUG_MODE=true ;;
-y|--yes) ASSUME_YES=true ;;
--de=*) DE="${arg#*=}" ;;
--twm=*) TWM="${arg#*=}" ;;
-h|--help) usage; exit 0 ;;
*)
err "Unknown argument: $arg"
printf "\n"
usage
exit 2
;;
esac
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
#------------------------------------------
# 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"
color_yellow "----------------------------------------------------------------"
color_yellow "Fedora unified configuration"
color_yellow "----------------------------------------------------------------"
if [[ ${EUID} -eq 0 ]]; then
err "Do not run this as root. Run it as your user; it calls sudo itself."
exit 1
fi
if [[ "$ASSUME_YES" == "true" && ( -z "$DE" || -z "$TWM" ) ]]; then
err "--yes requires explicit --de and --twm, so nothing is guessed on an"
err "unattended run. Example:"
err " ./setup.sh --yes --de=none --twm=niri"
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+
#------------------------------------------
step "OS detection"
rule
# 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:-unknown}"; OS_ID="${OS_ID,,}"
OS_PRETTY="${PRETTY_NAME:-unknown}"
if [[ "$OS_ID" != "fedora" ]]; then
err "Unsupported distribution: $OS_PRETTY (ID=${OS_ID})"
err "This repo targets Fedora only. RHEL clones are refused on purpose:"
err "they ship no dnf5 config-manager and no RPM Fusion, so both the base"
err "setup and every module would fail half-way."
exit 1
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
#------------------------------------------
# 1 Base settings
#------------------------------------------
step "1 Base settings"
rule
if ! command -v curl >/dev/null 2>&1; then
info "curl missing. Installing..."
install_packages curl
fi
# 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..."
sudo dnf config-manager setopt max_parallel_downloads=20
sudo dnf config-manager setopt defaultyes=True
info "Refreshing metadata..."
sudo dnf makecache --refresh
add_rpmfusion_repo
pause_if_debug
if ! command -v flatpak >/dev/null 2>&1; then
info "Flatpak missing. Installing..."
install_packages flatpak
fi
info "Ensuring Flathub is available (system-wide)..."
sudo flatpak remote-add --if-not-exists --system flathub https://dl.flathub.org/repo/flathub.flatpakrepo
info "Updating the system..."
sudo dnf update -y
pause_if_debug
#------------------------------------------
# 2 Menu helpers
#------------------------------------------
# $1 = prompt, $2 = default answer, rest = valid answers
ask_choice() {
local prompt="$1" default="$2"; shift 2
local answer
if [[ "$ASSUME_YES" == "true" ]]; then
echo "$default"
return 0
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
}
#------------------------------------------
# 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 (sddm)"
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]" "4" 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
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]" "5" 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
niri|hyprland|mango|chadwm|none) ;;
*) err "Unknown --twm value: '$TWM' (niri|hyprland|mango|chadwm|none)"; exit 2 ;;
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
#------------------------------------------
# 5 Dispatch
#------------------------------------------
export DE TWM
run_module() {
local path="$1"
if [[ ! -f "$path" ]]; 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
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