Files
starburst/0-setup-linux.sh
T
2026-07-06 16:16:45 +02:00

290 lines
8.9 KiB
Bash
Executable File

#!/bin/bash
# If debug is enabled, we remove '-e' dynamically inside the initialization so it doesn't instantly crash during debugging steps
set -uo pipefail
#------------------------------------------
# Color helpers (printf-safe, 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%s%b\n" "$YELLOW" "$*" "$RESET"; }
color_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; }
color_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; }
color_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; }
color_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; }
#------------------------------------------
# Debug Flag Initialization
#------------------------------------------
clear # Wipes the terminal history view cleanly
export DEBUG_MODE=false
if [[ "${1:-}" == "-d" || "${1:-}" == "--debug" ]]; then
export DEBUG_MODE=true
color_red "!!! DEBUG MODE ENABLED !!!"
color_red "The script will pause after each major section."
echo
else
set -e # Enable immediate exit on error only if NOT debugging step-by-step
fi
#------------------------------------------
# Debug Pause Helper
#------------------------------------------
pause_if_debug() {
if [[ "$DEBUG_MODE" == "true" ]]; then
echo
color_yellow "----------------------------------------------------------------"
read -rp "Section complete. Press [Enter] to continue, or [q] to abort: " debug_choice
if [[ "${debug_choice,,}" == "q" ]]; then
color_red "Script aborted by user."
exit 1
fi
color_yellow "----------------------------------------------------------------"
echo
fi
}
#------------------------------------------
# Script Version 3.0
#------------------------------------------
echo
color_yellow "----------------------------------------------------------------"
color_yellow " script version 3.0"
color_yellow "----------------------------------------------------------------"
echo
#------------------------------------------
# OS Detection
#------------------------------------------
echo
color_yellow "----------------------------------------------------------------"
color_yellow " Start OS Detection"
color_yellow "----------------------------------------------------------------"
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 "----------------------------------------------------------------"
color_cyan "Detected OS: %s (%s)\n" "$OS" "$OS_PRETTY"
color_cyan "Version: %s\n" "$OS_VERSION"
color_cyan "----------------------------------------------------------------"
else
color_red "----------------------------------------------------------------"
color_red "ERROR: Unsupported or unknown Linux distribution.\n"
color_red "Detected: ID=%s, ID_LIKE=%s\n" "$OS_ID" "${OS_LIKE:-empty}"
color_red "----------------------------------------------------------------"
exit 1
fi
pause_if_debug
#------------------------------------------
# Desktop Environment Detection / Selection
#------------------------------------------
echo
color_yellow "----------------------------------------------------------------"
color_yellow " Desktop Environment Selection"
color_yellow "----------------------------------------------------------------"
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 "----------------------------------------------------------------"
color_cyan "Detected Desktop Environment: %s (%s)\n" "$DE" "${DE_RAW:-unknown}"
color_cyan "----------------------------------------------------------------"
else
echo
printf "No Desktop Environment detected. Select one to install:\n"
while true; do
echo " 1) XFCE"
echo " 2) Plasma"
echo " 3) GNOME"
echo " x) None (default)"
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 ;;
3) DE="gnome"; break ;;
x|"") DE="none"; break ;;
*) echo "Invalid option. Please enter 1, 2, 3, or x." ;;
esac
done
echo
color_cyan "----------------------------------------------------------------"
color_cyan "Selected Desktop Environment: %s\n" "$DE"
color_cyan "----------------------------------------------------------------"
fi
pause_if_debug
#------------------------------------------
# Tiling Window Manager Selection
#------------------------------------------
echo
color_yellow "----------------------------------------------------------------"
color_yellow " Tiling WM Selection\n"
color_yellow "----------------------------------------------------------------"
echo
while true; do
echo
printf "Select a tiling window manager:\n"
echo " 1) CHADWM"
echo " 2) Hyprland"
echo " 3) Niri"
echo " x) None (default)"
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, 3 or x." ;;
esac
done
echo
color_cyan "----------------------------------------------------------------"
color_cyan "Selected Tiling WM: %s\n" "$TWM"
color_cyan "----------------------------------------------------------------"
pause_if_debug
#------------------------------------------
# Installation Level Selection
#------------------------------------------
echo
color_yellow "----------------------------------------------------------------"
color_yellow " Installation Level Selection\n"
color_yellow "----------------------------------------------------------------"
echo
while true; do
echo
printf "Select installation level:\n"
echo " 1) minimal"
echo " 2) full"
echo " 3) workstation"
echo " 4) server"
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 ;;
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 "----------------------------------------------------------------"
printf "Selected Installation Level: %s\n" "$INSTALL_LEVEL"
color_cyan "----------------------------------------------------------------"
pause_if_debug
#------------------------------------------
# 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="./debian/debian.sh" ;;
ubuntu) OS_SCRIPT="./ubuntu/ubuntu.sh" ;;
arch) OS_SCRIPT="./arch/arch.sh" ;;
fedora) OS_SCRIPT="./fedora/fedora.sh" ;;
*)
color_red "No OS script available for $OS"
exit 1
;;
esac
#------------------------------------------
# Preflight check & run
#------------------------------------------
if [[ ! -f "$OS_SCRIPT" ]]; then
color_red "ERROR: OS script not found: $OS_SCRIPT"
exit 1
fi
if [[ ! -x "$OS_SCRIPT" ]]; then
chmod +x "$OS_SCRIPT"
fi
echo
color_cyan "Running OS script: $OS_SCRIPT"
bash "$OS_SCRIPT" || {
color_red "ERROR: OS script failed: $OS_SCRIPT"
exit 1
}
echo
color_yellow "----------------------------------------------------------------"
printf "End Detection\n"
color_yellow "----------------------------------------------------------------"