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
+21 -10
View File
@@ -28,13 +28,15 @@ color_reset() { printf '%b' "$RESET"; }
##########################
# Script Version Selection
##########################
SCRIPT_VERSION="${SCRIPT_VERSION:-v2}" # Default to v2 if not set
echo
echo "Select script version:"
echo " 1) v1 (legacy)"
echo " 2) v2 (stable)"
read -rp "Enter choice [1/2] (default: 2): " ver_choice
# Added a 10-second timeout and default to 2
if ! read -t 10 -rp "Enter choice [1/2] (default: 2): " ver_choice; then
ver_choice=2
echo -e "\nTimeout reached, defaulting to v2."
fi
case "$ver_choice" in
1) SCRIPT_VERSION="v1" ;;
*) SCRIPT_VERSION="v2" ;;
@@ -140,12 +142,17 @@ if [[ -n "$DE" ]]; then
else
echo
echo "No Desktop Environment detected. Select one to install:"
echo "No Desktop Environment detected. Select one to install:"
while true; do
echo " 1) XFCE"
echo " 2) Plasma"
echo " 3) GNOME"
echo " x) None (default)"
read -rp "Enter choice [1/2/3/x] (default: x): " choice
# Added timeout to avoid hanging
if ! read -t 15 -rp "Enter choice [1/2/3/x] (default: x): " choice; then
choice="x"
fi
case "${choice,,}" in
1) DE="xfce"; break ;;
2) DE="plasma"; break ;;
@@ -173,7 +180,6 @@ echo "################################################################"
color_reset
echo
TWM="none"
while true; do
echo
echo "Select a tiling window manager:"
@@ -181,13 +187,16 @@ while true; do
echo " 2) Hyprland"
echo " 3) Niri"
echo " x) None (default)"
read -rp "Enter choice [1/2/x] (default: x): " choice
if ! read -t 15 -rp "Enter choice [1/2/3/x] (default: x): " choice; then
choice="x"
fi
case "${choice,,}" in
1) TWM="chadwm"; break ;;
2) TWM="hyprland"; break ;;
3) TWM="niri"; break ;;
x|"") TWM="none"; break ;;
*) echo "Invalid option. Please enter 1, 2, or x." ;;
*) echo "Invalid option. Please enter 1, 2, 3 or x." ;;
esac
done
@@ -209,7 +218,6 @@ echo "################################################################"
color_reset
echo
INSTALL_LEVEL="minimal" # default
while true; do
echo
echo "Select installation level:"
@@ -217,7 +225,10 @@ while true; do
echo " 2) full"
echo " 3) workstation"
echo " 4) server"
read -rp "Enter choice [1/2/3/4] (default: 1): " choice
if ! read -t 15 -rp "Enter choice [1/2/3/4] (default: 1): " choice; then
choice="1"
fi
case "$choice" in
1|"") INSTALL_LEVEL="minimal"; break ;;
2) INSTALL_LEVEL="full"; break ;;
-293
View File
@@ -1,293 +0,0 @@
#!/bin/bash
set -euo pipefail
##########################
# Color helpers (no tput)
##########################
RED='\033[0;31m'
GREEN='\033[0;32m'
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' "$YELLOW"; }
color_cyan() { printf '%b' "$CYAN"; }
color_red() { printf '%b' "$RED"; }
color_green() { printf '%b' "$GREEN"; }
color_reset() { printf '%b' "$RESET"; }
##########################
# Script Version Selection
##########################
SCRIPT_VERSION="${SCRIPT_VERSION:-v2}" # Default to v2 if not set
echo
echo "Select script version:"
echo " 1) v1 (legacy)"
echo " 2) v2 (stable)"
read -rp "Enter choice [1/2] (default: 2): " ver_choice
case "$ver_choice" in
1) SCRIPT_VERSION="v1" ;;
*) SCRIPT_VERSION="v2" ;;
esac
echo
color_cyan
echo "################################################################################"
echo "Selected Script Version: $SCRIPT_VERSION"
echo "################################################################################"
color_reset
if [[ ! -d "./${SCRIPT_VERSION}" ]]; then
color_red
echo "ERROR: Version folder not found: ${SCRIPT_VERSION}"
color_reset
exit 1
fi
##########################
# OS Detection
##########################
echo
color_yellow
echo "################################################################"
echo "################### Start OS Detection"
echo "################################################################"
color_reset
echo
source /etc/os-release
OS_ID="${ID,,}"
OS_LIKE="${ID_LIKE:-}"
OS_LIKE="${OS_LIKE,,}"
OS_VERSION="${VERSION_ID:-unknown}"
OS_PRETTY="$PRETTY_NAME"
OS=""
case "$OS_ID" in
arch) OS="arch" ;;
debian) OS="debian" ;;
ubuntu) OS="ubuntu" ;;
fedora) OS="fedora" ;;
*)
if [[ "$OS_LIKE" == *"ubuntu"* ]]; then
OS="ubuntu"
elif [[ "$OS_LIKE" == *"arch"* ]]; then
OS="arch"
elif [[ "$OS_LIKE" == *"debian"* ]]; then
OS="debian"
elif [[ "$OS_LIKE" == *"fedora"* || "$OS_LIKE" == *"rhel"* ]]; then
OS="fedora"
fi
;;
esac
if [[ -n "$OS" ]]; then
color_cyan
echo "################################################################################"
echo "Detected OS: $OS ($OS_PRETTY)"
echo "Version: $OS_VERSION"
echo "################################################################################"
color_reset
else
color_red
echo "################################################################################"
echo "ERROR: Unsupported or unknown Linux distribution."
echo "Detected: ID=$OS_ID, ID_LIKE=${OS_LIKE:-empty}"
echo "################################################################################"
color_reset
exit 1
fi
##########################
# Desktop Environment Detection / Selection
##########################
echo
color_yellow
echo "################################################################"
echo "################### Desktop Environment Selection"
echo "################################################################"
color_reset
echo
DE_RAW="${XDG_CURRENT_DESKTOP:-${DESKTOP_SESSION:-}}"
DE=""
case "${DE_RAW,,}" in
*xfce*) DE="xfce" ;;
*plasma*|*kde*) DE="plasma" ;;
*gnome*) DE="gnome" ;;
""|none) DE="" ;;
esac
if [[ -n "$DE" ]]; then
echo
color_cyan
echo "################################################################################"
echo "Detected Desktop Environment: $DE (${DE_RAW})"
echo "################################################################################"
color_reset
else
echo
echo "No Desktop Environment detected. Select one to install:"
while true; do
echo " 1) XFCE"
echo " 2) Plasma"
echo " 3) GNOME"
echo " x) None (default)"
read -rp "Enter choice [1/2/3/x] (default: x): " choice
case "${choice,,}" in
1) DE="xfce"; break ;;
2) DE="plasma"; break ;;
3) DE="gnome"; break ;;
x|"") DE="none"; break ;;
*) echo "Invalid option. Please enter 1, 2, 3, or x." ;;
esac
done
echo
color_cyan
echo "################################################################################"
echo "Selected Desktop Environment: $DE"
echo "################################################################################"
color_reset
fi
##########################
# Tiling Window Manager Selection
##########################
echo
color_yellow
echo "################################################################"
echo "################### Tiling WM Selection"
echo "################################################################"
color_reset
echo
TWM="none"
while true; do
echo
echo "Select a tiling window manager:"
echo " 1) CHADWM"
echo " 2) Hyprland"
echo " x) None (default)"
read -rp "Enter choice [1/2/x] (default: x): " choice
case "${choice,,}" in
1) TWM="chadwm"; break ;;
2) TWM="hyprland"; break ;;
x|"") TWM="none"; break ;;
*) echo "Invalid option. Please enter 1, 2, or x." ;;
esac
done
echo
color_cyan
echo "################################################################################"
echo "Selected Tiling WM: $TWM"
echo "################################################################################"
color_reset
##########################
# Installation Level Selection
##########################
echo
color_yellow
echo "################################################################"
echo "################### Installation Level Selection"
echo "################################################################"
color_reset
echo
INSTALL_LEVEL="minimal" # default
while true; do
echo
echo "Select installation level:"
echo " 1) minimal"
echo " 2) full"
echo " 3) workstation"
echo " 4) server"
read -rp "Enter choice [1/2/3/4] (default: 1): " choice
case "$choice" in
1|"") INSTALL_LEVEL="minimal"; break ;;
2) INSTALL_LEVEL="full"; break ;;
3) INSTALL_LEVEL="workstation"; break ;;
4) INSTALL_LEVEL="server"; break ;;
*) echo "Invalid option. Please enter 1, 2, 3, or 4." ;;
esac
done
echo
color_cyan
echo "################################################################################"
echo "Selected Installation Level: $INSTALL_LEVEL"
echo "################################################################################"
color_reset
##########################
# Export selections for OS script
##########################
export DETECTED_OS="$OS"
export DETECTED_DE="$DE_RAW"
export SELECTED_DE="$DE"
export SELECTED_TWM="$TWM"
export INSTALL_LEVEL
##########################
# Determine OS script
##########################
case "$OS" in
debian) OS_SCRIPT="./${SCRIPT_VERSION}/debian.sh" ;;
ubuntu) OS_SCRIPT="./${SCRIPT_VERSION}/ubuntu.sh" ;;
arch) OS_SCRIPT="./${SCRIPT_VERSION}/arch.sh" ;;
fedora) OS_SCRIPT="./${SCRIPT_VERSION}/fedora.sh" ;;
*)
color_red
echo
echo "No OS script available for $OS"
color_reset
exit 1
;;
esac
##########################
# Preflight check & run
##########################
if [[ ! -f "$OS_SCRIPT" ]]; then
color_red
echo
echo "ERROR: OS script not found: $OS_SCRIPT"
color_reset
exit 1
fi
if [[ ! -x "$OS_SCRIPT" ]]; then
chmod +x "$OS_SCRIPT"
fi
echo
color_cyan
echo "Running OS script: $OS_SCRIPT"
color_reset
bash "$OS_SCRIPT" || {
color_red
echo
echo "ERROR: OS script failed: $OS_SCRIPT"
color_reset
exit 1
}
echo
color_yellow
echo "################################################################"
echo "End Detection"
echo "################################################################"
color_reset
+18 -13
View File
@@ -35,7 +35,7 @@ INSTALL_LEVEL="${INSTALL_LEVEL:-minimal}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo
say_cyan "Starting Debian setup..."
say_cyan "Starting Arch setup..."
echo
say_gray "DE: $DE, TWM: $TWM, Install Level: $INSTALL_LEVEL"
@@ -177,15 +177,20 @@ case "$INSTALL_LEVEL" in
esac
say_green "Arch setup complete."
say_red "The installation has finished. A reboot is recommended before continuing."
read -rp "Reboot now? [y/N]: " reboot_choice
case "${reboot_choice,,}" in
y|yes)
say_red "Rebooting now."
sudo reboot
;;
*)
say_yellow "Skipping reboot. Make sure to reboot manually before continuing upgrades."
exit 0
;;
esac
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
+17 -12
View File
@@ -228,15 +228,20 @@ case "$INSTALL_LEVEL" in
esac
say_green "Debian setup complete."
say_red "The installation has finished. A reboot is recommended before continuing."
read -rp "Reboot now? [y/N]: " reboot_choice
case "${reboot_choice,,}" in
y|yes)
say_red "Rebooting now."
sudo reboot
;;
*)
say_yellow "Skipping reboot. Make sure to reboot manually before continuing upgrades."
exit 0
;;
esac
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
+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