script improvements

This commit is contained in:
2026-04-23 09:39:06 +02:00
parent 2191db7a43
commit 0a735a2690
5 changed files with 218 additions and 419 deletions
+162 -91
View File
@@ -2,113 +2,184 @@
set -euo pipefail
##########################
# Color helpers
# Color helpers (printf-safe, no tput)
##########################
tput_reset() { tput sgr0; }
tput_black() { tput setaf 0; }
tput_red() { tput setaf 1; }
tput_green() { tput setaf 2; }
tput_yellow() { tput setaf 3; }
tput_blue() { tput setaf 4; }
tput_purple() { tput setaf 5; }
tput_cyan() { tput setaf 6; }
tput_gray() { tput setaf 7; }
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
CYAN="\033[0;36m"
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="" GRAY="" BOLD="" RESET=""
fi
say_red() { printf "\n"; printf "%b%s%b\n" "$RED" "$*" "$RESET"; }
say_green() { printf "\n"; printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; }
say_yellow() { printf "\n"; printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; }
say_cyan() { printf "\n"; printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; }
say_gray() { printf "\n"; printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; }
say_bold() { printf "\n"; printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; }
##########################
# Use exported variables from main detection script
##########################
OS="${DETECTED_OS}"
DDE="${DETECTED_DE}"
DE="${SELECTED_DE:-none}"
TWM="${SELECTED_TWM:-none}"
INSTALL_LEVEL="${INSTALL_LEVEL:-minimal}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo
tput_yellow
echo "################################################################################"
echo "################### Detected OS / Desktop Environmet / Tiling Window Manager"
echo "################################################################################"
tput_reset
say_cyan "Starting Fedora setup..."
echo
say_gray "DE: $DE, TWM: $TWM, Install Level: $INSTALL_LEVEL"
echo "Installing OS-specific packages..."
echo "Selected DE: $SELECTED_DE"
echo "Selected TWM: $SELECTED_TWM"
echo "Installation Level: $INSTALL_LEVEL"
##########################
# Helper functions
##########################
install_packages() { sudo dnf install -y "$@"; }
is_package_installed() { rpm -q "$@" &>/dev/null; }
if [[ "$SELECTED_DE" == "xfce" ]]; then
echo
tput_green
echo "################################################################################"
echo "################### Installing XFCE4"
echo "################################################################################"
tput_reset
echo
remove_packages() {
local packages_to_remove=()
for pkg in "$@"; do
if is_package_installed "$pkg"; then
packages_to_remove+=("$pkg")
fi
done
echo "Installing XFCE packages..."
if [ ${#packages_to_remove[@]} -gt 0 ]; then
say_cyan "Removing packages: ${packages_to_remove[*]}"
sudo dnf remove -y "${packages_to_remove[@]}"
fi
}
##########################
# 0. Ensure base is ready for installation
##########################
installed_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
pkg_dir="packages"
if [[ ! -d "$pkg_dir" ]]; then
say_red "Directory not found: $pkg_dir"
exit 1
fi
if [[ "$SELECTED_DE" == "plasma" ]]; then
echo
tput_green
echo "################################################################################"
echo "################### Installing KDE Plasma 6"
echo "################################################################################"
tput_reset
echo
echo "Installing Plasma packages..."
if ! command -v curl >/dev/null 2>&1; then
say_yellow "curl is not installed. Installing..."
install_packages curl
fi
if [[ "$SELECTED_DE" == "gnome" ]]; then
echo
tput_green
echo "################################################################################"
echo "################### Installing Gnome 48"
echo "################################################################################"
tput_reset
echo
##########################
# 1. Add repositories if missing and update system
##########################
say_yellow "Checking for updates and sources..."
sudo dnf check-update || true
echo "Installing Gnome packages..."
# Update the system
say_gray "Updating the system - sudo dnf update"
echo
sudo dnf update
##########################
# 2. Fix missing console font
##########################
say_yellow "Fix missing console font"
if grep -q FONT= /etc/vconsole.conf; then
say_green "Font is already set in /etc/vconsole.conf"
else
say_green "Setting console font in /etc/vconsole.conf"
echo 'FONT=gr737c-8x14' | sudo tee -a /etc/vconsole.conf
fi
if [[ "$SELECTED_DE" == "none" ]]; then
echo
tput_green
echo "################################################################################"
echo "################### Installing no Desktop Environment"
echo "################################################################################"
tput_reset
echo
##########################
# 3. Detected OS / DE / TWM info
##########################
say_yellow "Detected OS / Desktop Environment / Tiling Window Manager"
echo
say_gray "Installing OS-specific packages..."
say_gray "Selected DE: $DE"
say_gray "Selected TWM: $TWM"
say_gray "Installation Level: $INSTALL_LEVEL"
echo "Installing no Desktop Environment packages..."
fi
##########################
# 4. Desktop Environment installation
##########################
case "$DE" in
xfce|plasma|gnome)
say_yellow "Preparing to install $DE..."
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${DE}.sh"
if [[ -f "$SCRIPT_NAME" ]]; then
say_cyan "Running $SCRIPT_NAME..."
bash "$SCRIPT_NAME"
else
say_red "Error: $SCRIPT_NAME not found!"
exit 1
fi
;;
none)
say_gray "No Desktop Environment selected, skipping DE installation."
;;
esac
##########################
# 5. Tiling Window Manager installation
##########################
case "$TWM" in
chadwm|hyprland)
say_yellow "Installing $TWM..."
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${TWM}.sh"
if [[ -f "$SCRIPT_NAME" ]]; then
say_cyan "Running $SCRIPT_NAME..."
bash "$SCRIPT_NAME"
else
say_red "Error: $SCRIPT_NAME not found!"
exit 1
fi
;;
none)
say_gray "No tiling window manager selected."
;;
esac
if [[ "$SELECTED_TWM" == "chadwm" ]]; then
echo
tput_green
echo "################################################################################"
echo "################### Installing Chadwm"
echo "################################################################################"
tput_reset
echo
##########################
# 6. Installation level handling
##########################
case "$INSTALL_LEVEL" in
minimal|full|workstation|server)
say_cyan "Installation level: $INSTALL_LEVEL"
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${INSTALL_LEVEL}.sh"
if [[ -f "$SCRIPT_NAME" ]]; then
say_cyan "Running $SCRIPT_NAME..."
bash "$SCRIPT_NAME"
else
say_red "Error: $SCRIPT_NAME not found!"
exit 1
fi
;;
esac
echo "Installing CHADWM..."
fi
if [[ "$SELECTED_TWM" == "hyprland" ]]; then
echo
tput_green
echo "################################################################################"
echo "################### Installing Hyprland"
echo "################################################################################"
tput_reset
echo
echo "Installing Hyperland..."
fi
if [[ "$SELECTED_TWM" == "none" ]]; then
echo
tput_green
echo "################################################################################"
echo "################### Installing no Tiling Window Manager"
echo "################################################################################"
tput_reset
echo
echo "Installing no Tiling Window Manager packages..."
fi
say_green "Fedora setup complete."
say_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)
say_red "Rebooting now."
sudo reboot
;;
*)
say_yellow "Skipping reboot."
exit 0
;;
esac
else
say_yellow "\nNo input detected. Skipping reboot for safety."
exit 0
fi