187 lines
5.6 KiB
Bash
Executable File
187 lines
5.6 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# Source parent definitions (adjust path if needed)
|
|
source "$(dirname "$0")/../main_script.sh"
|
|
|
|
# Map the exported variables to your local names with fallbacks to satisfy set -u
|
|
OS="${DETECTED_OS:-fedora}"
|
|
DE="${SELECTED_DE:-none}"
|
|
TWM="${SELECTED_TWM:-none}"
|
|
INSTALL_LEVEL="${INSTALL_LEVEL:-minimal}"
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
echo
|
|
color_cyan "Starting Fedora setup..."
|
|
echo
|
|
color_gray "DE: $DE, TWM: $TWM, Install Level: $INSTALL_LEVEL"
|
|
|
|
#------------------------------------------
|
|
# Helper functions
|
|
#------------------------------------------
|
|
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. 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
|
|
|
|
pause_if_debug
|
|
|
|
#------------------------------------------
|
|
# 1. Update and Enable Repos
|
|
#------------------------------------------
|
|
color_cyan "Optimizing DNF for speed..."
|
|
|
|
# 1. Enable fastest mirror (lowest latency)
|
|
# 2. Increase parallel downloads (allows downloading multiple packages at once)
|
|
# 3. Set a minimum rate to drop slow mirrors automatically
|
|
# $. Set dnf to set YES as default instead of NO
|
|
sudo dnf config-manager setopt fastestmirror=1
|
|
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"
|
|
echo
|
|
sudo dnf update -y
|
|
|
|
pause_if_debug
|
|
|
|
#------------------------------------------
|
|
# 3. Detected OS / DE / TWM info
|
|
#------------------------------------------
|
|
color_yellow "Detected OS / Desktop Environment / Tiling Window Manager"
|
|
echo
|
|
color_gray "Installing OS-specific packages..."
|
|
color_gray "Selected DE: $DE"
|
|
color_gray "Selected TWM: $TWM"
|
|
color_gray "Installation Level: $INSTALL_LEVEL"
|
|
|
|
pause_if_debug
|
|
|
|
#------------------------------------------
|
|
# 4. Desktop Environment installation
|
|
#------------------------------------------
|
|
case "$DE" in
|
|
xfce|plasma|gnome)
|
|
color_yellow "Preparing to install $DE"
|
|
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${DE}.sh"
|
|
if [[ -f "$SCRIPT_NAME" ]]; then
|
|
color_cyan "Running $SCRIPT_NAME"
|
|
bash "$SCRIPT_NAME"
|
|
else
|
|
color_red "Error: $SCRIPT_NAME not found!"
|
|
exit 1
|
|
fi
|
|
;;
|
|
none)
|
|
color_gray "No Desktop Environment selected, skipping DE installation."
|
|
;;
|
|
esac
|
|
|
|
pause_if_debug
|
|
|
|
#------------------------------------------
|
|
# 5. Tiling Window Manager installation
|
|
#------------------------------------------
|
|
case "$TWM" in
|
|
chadwm|hyprland|niri)
|
|
color_yellow "Installing $TWM"
|
|
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${TWM}.sh"
|
|
if [[ -f "$SCRIPT_NAME" ]]; then
|
|
color_cyan "Running $SCRIPT_NAME"
|
|
bash "$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
|
|
|
|
#------------------------------------------
|
|
# 6. Installation level handling
|
|
#------------------------------------------
|
|
case "$INSTALL_LEVEL" in
|
|
minimal|full|workstation|server)
|
|
color_cyan "Installation level: $INSTALL_LEVEL"
|
|
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${INSTALL_LEVEL}.sh"
|
|
if [[ -f "$SCRIPT_NAME" ]]; then
|
|
color_cyan "Running $SCRIPT_NAME"
|
|
bash "$SCRIPT_NAME"
|
|
else
|
|
color_red "Error: $SCRIPT_NAME not found!"
|
|
exit 1
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
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 |