Files
fedora/setup.sh
T
Pathfinder 5b7ed5ede9 Package sections: always-on categories + advanced menu installer
Section 6 'Always-installed packages': ALWAYS_PACKAGES array, one line per
category (first: Terminals with ghostty + ghostty-bash-completion). Every
entry installs on every run, no questions. Add a category by adding a line.

Section 7 'Advanced optional tools': menu-driven picker, data-driven —
ADV_CATEGORIES + ADV_<Category> arrays ('id:Label:pkgs...'). Ships
Virtualisation (qemu/kvm stack, VirtualBox) and Browsers (firefox,
chromium, google-chrome, brave; the latter two wire up their repos
automatically). Multi-select with comma-separated picks, invalid picks
warned and skipped, 'x' backs out, menu is skipped under --yes so
unattended runs never hang.

Bugs found by harness testing and fixed before shipping:
- ${!var} on an array name yields only element[0]: Browsers listed one
  entry. Now uses a nameref (declare -n).
- var assignment was lost in an edit: unbound-variable crash on the menu.
- --snapper=no was overwritten by the interactive default; explicit flags
  now always win.
2026-10-27 13:04:15 +01:00

592 lines
18 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=""
SELINUX_OPT=""
SNAPPER_OPT=""
DOTFILES_OPT=""
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
--selinux=X keep | disabled (asked, default keep)
--snapper=X yes | no (automatic on btrfs; use 'no' to opt out)
--dotfiles=X yes | no (clone personal dotfiles, default no)
-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#*=}" ;;
--selinux=*) SELINUX_OPT="${arg#*=}" ;;
--snapper=*) SNAPPER_OPT="${arg#*=}" ;;
--dotfiles=*) DOTFILES_OPT="${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
# Terra up front: it carries mangowc (noctalia moved into Fedora proper in
# F44). Idempotent; also kept for the standalone-mango-module case.
add_terra_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
}
# Ask a yes/no question; $2 is the default (yes|no). Honours --yes.
ask_yes_no() {
local prompt="$1" default="$2" answer
if [[ "$ASSUME_YES" == "true" ]]; then
echo "$default"
return 0
fi
while true; do
read -t 60 -rp "$prompt [y/n] (default: $default): " answer || printf "\n"
answer="${answer,,}"
[[ -z "$answer" ]] && answer="$default"
case "$answer" in
y|yes) echo "yes"; return 0 ;;
n|no) echo "no"; return 0 ;;
esac
err "Please answer y or n."
done
}
#------------------------------------------
# 3 System settings
#------------------------------------------
SELINUX_DISABLED=false
BTRFS_SNAPPER=false
if [[ -z "$SELINUX_OPT" ]]; then
step "3 System settings"
rule
printf "\n"
printf "\n"
choice=$(ask_yes_no "Disable SELinux permanently? (not recommended)" "no")
[[ "$choice" == "yes" ]] && SELINUX_DISABLED=true
printf "\n"
if findmnt -n -o FSTYPE / 2>/dev/null | grep -q btrfs; then
ok "Root filesystem is btrfs — snapshots + zstd compression will be set up."
BTRFS_SNAPPER=true
else
info "Root filesystem is not btrfs; skipping snapshot setup."
fi
fi
case "${SELINUX_OPT:-}" in
disabled) SELINUX_DISABLED=true ;;
keep|"") : ;;
*) err "Unknown --selinux value: '$SELINUX_OPT' (keep|disabled)"; exit 2 ;;
esac
case "${SNAPPER_OPT:-}" in
yes) BTRFS_SNAPPER=true ;;
no) BTRFS_SNAPPER=false ;; # explicit flag beats the interactive default
""|keep) : ;;
*) err "Unknown --snapper value: '$SNAPPER_OPT' (yes|no)"; exit 2 ;;
esac
DOTFILES=false
if [[ -z "$DOTFILES_OPT" ]]; then
printf "\n"
choice=$(ask_yes_no "Clone personal dotfiles (fedora-dots) into \$HOME?" "no")
[[ "$choice" == "yes" ]] && DOTFILES=true
else
case "$DOTFILES_OPT" in
yes) DOTFILES=true ;;
no) : ;;
*) err "Unknown --dotfiles value: '$DOTFILES_OPT' (yes|no)"; exit 2 ;;
esac
fi
pause_if_debug
#------------------------------------------
# 4 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
#------------------------------------------
# 5 Tiling window manager selection
#------------------------------------------
if [[ -z "$TWM" ]]; then
step "5 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 [[ "$SELINUX_DISABLED" == "true" ]]; then
disable_selinux
pause_if_debug
fi
if [[ "$BTRFS_SNAPPER" == "true" ]]; then
ensure_btrfs_compression
setup_snapper
pause_if_debug
fi
if [[ "$DOTFILES" == "true" ]]; then
run_module "$SCRIPT_DIR/modules/user/dotfiles.sh"
pause_if_debug
fi
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
#------------------------------------------
#------------------------------------------
# 6 Always-installed packages
#------------------------------------------
# Add a category here and it is installed on every run, no questions asked.
# Keep each category one line so diffs stay readable.
ALWAYS_PACKAGES=(
# Terminals
"ghostty ghostty-bash-completion"
)
step "6 Always-installed packages"
rule
for category in "${ALWAYS_PACKAGES[@]}"; do
# shellcheck disable=SC2086
install_packages $category
done
ok "Always-packages installed."
pause_if_debug
#------------------------------------------
# 7 Advanced: optional tool selection (menu-driven)
#------------------------------------------
# Add categories/apps by editing these parallel arrays:
# ADV_CATEGORIES : display order
# ADV_<NAME> : "pkg1 pkg2 ..." for each category (dots/minus -> underscore)
ADV_CATEGORIES=(
"Virtualisation"
"Browsers"
)
# shellcheck disable=SC2034 # arrays are read via nameref from ADV_CATEGORIES
ADV_Virtualisation=(
"qemu-kvm:QEMU/KVM (full virt stack):qemu-kvm libvirt virt-install virt-manager virt-viewer edk2-ovmf swtpm guestfs-tools libguestfs-tools"
"virtualbox:VirtualBox (Oracle):VirtualBox kernel-devel kernel-headers dkms akmod-VirtualBox"
)
# shellcheck disable=SC2034 # arrays are read via nameref from ADV_CATEGORIES
ADV_Browsers=(
"firefox:Firefox:firefox"
"chromium:Chromium:chromium"
"google-chrome:Google Chrome (adds repo):google-chrome-stable"
"brave:Brave (adds repo):brave-browser"
)
run_advanced_menu() {
local done_any=false
while true; do
printf "\n"
color_gray "Optional tools - select a category to pick from:"
printf "\n"
local i=1 cat
for cat in "${ADV_CATEGORIES[@]}"; do
echo " $i) $cat"
i=$((i+1))
done
echo " x) Done with optional tools"
local choice
if ! read -t 90 -rp "Category [1-${#ADV_CATEGORIES[@]}/x] (default: x): " choice; then
printf "\n"; choice="x"
fi
[[ "${choice,,}" == "x" || -z "$choice" ]] && break
if [[ ! "$choice" =~ ^[0-9]+$ ]] || (( choice < 1 || choice > ${#ADV_CATEGORIES[@]} )); then
err "Invalid choice: $choice"
continue
fi
cat="${ADV_CATEGORIES[$((choice-1))]}"
# apps for this category — nameref, because ${!var} on an array name
# would only give element 0 (that bug showed in testing: Browsers
# listed exactly one entry)
local var="ADV_${cat//[ .-]/_}"
local -n entries_ref="$var"
local -a entries
# shellcheck disable=SC2206
entries=("${entries_ref[@]}")
printf "\n"
color_cyan "$cat:"
local j=1 entry
local -a ids=() labels=()
for entry in "${entries[@]}"; do
ids+=("${entry%%:*}") # entry id
local rest="${entry#*:}"
labels+=("${rest%%:*}") # display label
echo " $j) ${labels[-1]}"
j=$((j+1))
done
echo " x) Back"
local sel
if ! read -t 90 -rp "Install which? (comma-separate for multiple, default: back): " sel; then
printf "\n"; continue
fi
[[ "${sel,,}" == "x" || -z "$sel" ]] && continue
# Resolve picks to package lists. Entry format: id:Label:packages...
local -a to_install=()
local pick n rest
IFS=',' read -ra picks <<< "$sel"
for pick in "${picks[@]}"; do
pick="${pick// /}"
[[ "$pick" =~ ^[0-9]+$ ]] || { err "Ignoring invalid pick: $pick"; continue; }
n=${#entries[@]}
if (( pick < 1 || pick > n )); then err "Ignoring out-of-range pick: $pick"; continue; fi
entry="${entries[$((pick-1))]}"
rest="${entry#*:}"; rest="${rest#*:}" # drop id and label -> packages
to_install+=("$rest")
done
if (( ${#to_install[@]} > 0 )); then
step "Installing from $cat: ${to_install[*]}"
# Repos for items that need one are handled in install_optional_pkgs below.
install_category_pkgs "$cat" "${to_install[@]}"
done_any=true
fi
done
$done_any && ok "Optional tools installed."
}
# Per-category pre-repo wiring. Add third-party repos here when you add an
# app that needs one; packages alone stay generic.
install_category_pkgs() {
local cat="$1"; shift
case "$cat" in
Browsers)
local needs_chrome=false needs_brave=false item
for item in "$@"; do
[[ "$item" == *google-chrome* ]] && needs_chrome=true
[[ "$item" == *brave* ]] && needs_brave=true
done
if $needs_chrome && ! pkg_installed google-chrome-stable; then
info "Adding Google Chrome repo..."
sudo dnf install -y fedora-workstation-repositories 2>/dev/null || true
sudo dnf config-manager setopt google-chrome.enabled=1 2>/dev/null || \
sudo dnf install -y "https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm"
fi
if $needs_brave && ! pkg_installed brave-browser; then
info "Adding Brave repo..."
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager add --from-repofile=https://brave-browser-rpm-release.s3.brave.com/brave-browser.repo || \
true
sudo rpm --import https://brave-browser-rpm-release.s3.brave.com/brave-core.asc 2>/dev/null || true
fi
;;
esac
install_packages "$@"
}
# Interactive only: an unattended --yes run must not hang on this menu.
# Skip silently there; use --de/--twm/--dotfiles for everything unattended.
if [[ "$ASSUME_YES" != "true" ]]; then
run_advanced_menu
fi
pause_if_debug
step "8 Summary"
rule
ok "DE: $DE"
ok "TWM: $TWM"
ok "SELinux: $([[ "$SELINUX_DISABLED" == "true" ]] && echo disabled || echo keeping)"
ok "Btrfs snapshots: $([[ "$BTRFS_SNAPPER" == "true" ]] && echo yes || echo skipped)"
ok "Dotfiles: $([[ "$DOTFILES" == "true" ]] && echo clone || echo no)"
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