cleanup launch script

This commit is contained in:
[yuri]
2025-11-10 10:33:22 +01:00
parent 8901706b27
commit 26948f63d0

View File

@@ -2,24 +2,42 @@
set -euo pipefail set -euo pipefail
########################## ##########################
# Color helpers # Color helpers (no tput)
########################## ##########################
tput_reset() { tput sgr0; } RED='\033[0;31m'
tput_black() { tput setaf 0; } GREEN='\033[0;32m'
tput_red() { tput setaf 1; } YELLOW='\033[0;33m'
tput_green() { tput setaf 2; } CYAN='\033[0;36m'
tput_yellow() { tput setaf 3; } PURPLE='\033[0;35m'
tput_blue() { tput setaf 4; } BLUE='\033[0;34m'
tput_purple() { tput setaf 5; } GRAY='\033[0;37m'
tput_cyan() { tput setaf 6; } BOLD='\033[1m'
tput_gray() { tput setaf 7; } 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_reset() { printf '%b' "$RESET"; }
##########################
# Optional logging setup
##########################
LOG_DIR="./logs"
LOG_FILE="$LOG_DIR/setup.log"
mkdir -p "$LOG_DIR"
exec > >(tee -a "$LOG_FILE") 2>&1
echo echo
tput_yellow color_yellow
echo "################################################################" echo "################################################################"
echo "################### Start OS Detection" echo "################### Start OS Detection"
echo "################################################################" echo "################################################################"
tput_reset color_reset
echo echo
########################## ##########################
@@ -40,7 +58,6 @@ case "$OS_ID" in
ubuntu) OS="ubuntu" ;; ubuntu) OS="ubuntu" ;;
fedora) OS="fedora" ;; fedora) OS="fedora" ;;
*) *)
# fallback for derivatives
if [[ "$OS_LIKE" == *"ubuntu"* ]]; then if [[ "$OS_LIKE" == *"ubuntu"* ]]; then
OS="ubuntu" OS="ubuntu"
elif [[ "$OS_LIKE" == *"arch"* ]]; then elif [[ "$OS_LIKE" == *"arch"* ]]; then
@@ -54,19 +71,19 @@ case "$OS_ID" in
esac esac
if [[ -n "$OS" ]]; then if [[ -n "$OS" ]]; then
tput_cyan color_cyan
echo "################################################################################" echo "################################################################################"
echo "Detected OS: $OS ($OS_PRETTY)" echo "Detected OS: $OS ($OS_PRETTY)"
echo "Version: $OS_VERSION" echo "Version: $OS_VERSION"
echo "################################################################################" echo "################################################################################"
tput_reset color_reset
else else
tput_red color_red
echo "################################################################################" echo "################################################################################"
echo "ERROR: Unsupported or unknown Linux distribution." echo "ERROR: Unsupported or unknown Linux distribution."
echo "Detected: ID=$OS_ID, ID_LIKE=${OS_LIKE:-empty}" echo "Detected: ID=$OS_ID, ID_LIKE=${OS_LIKE:-empty}"
echo "################################################################################" echo "################################################################################"
tput_reset color_reset
exit 1 exit 1
fi fi
@@ -74,11 +91,11 @@ fi
# Desktop Environment Detection / Selection # Desktop Environment Detection / Selection
########################## ##########################
echo echo
tput_yellow color_yellow
echo "################################################################" echo "################################################################"
echo "################### Desktop Environment Selection" echo "################### Desktop Environment Selection"
echo "################################################################" echo "################################################################"
tput_reset color_reset
echo echo
DE_RAW="${XDG_CURRENT_DESKTOP:-${DESKTOP_SESSION:-}}" DE_RAW="${XDG_CURRENT_DESKTOP:-${DESKTOP_SESSION:-}}"
@@ -88,18 +105,17 @@ case "${DE_RAW,,}" in
*xfce*) DE="xfce" ;; *xfce*) DE="xfce" ;;
*plasma*|*kde*) DE="plasma" ;; *plasma*|*kde*) DE="plasma" ;;
*gnome*) DE="gnome" ;; *gnome*) DE="gnome" ;;
""|none) DE="" ;; # trigger menu ""|none) DE="" ;;
esac esac
if [[ -n "$DE" ]]; then if [[ -n "$DE" ]]; then
echo echo
tput_cyan color_cyan
echo "################################################################################" echo "################################################################################"
echo "Detected Desktop Environment: $DE (${DE_RAW})" echo "Detected Desktop Environment: $DE (${DE_RAW})"
echo "################################################################################" echo "################################################################################"
tput_reset color_reset
else else
# No DE detected — ask user
echo echo
echo "No Desktop Environment detected. Select one to install:" echo "No Desktop Environment detected. Select one to install:"
while true; do while true; do
@@ -117,22 +133,22 @@ else
esac esac
done done
echo echo
tput_cyan color_cyan
echo "################################################################################" echo "################################################################################"
echo "Selected Desktop Environment: $DE" echo "Selected Desktop Environment: $DE"
echo "################################################################################" echo "################################################################################"
tput_reset color_reset
fi fi
########################## ##########################
# Tiling Window Manager Selection # Tiling Window Manager Selection
########################## ##########################
echo echo
tput_yellow color_yellow
echo "################################################################" echo "################################################################"
echo "################### Tiling WM Selection" echo "################### Tiling WM Selection"
echo "################################################################" echo "################################################################"
tput_reset color_reset
echo echo
TWM="none" TWM="none"
@@ -152,21 +168,21 @@ while true; do
done done
echo echo
tput_cyan color_cyan
echo "################################################################################" echo "################################################################################"
echo "Selected Tiling WM: $TWM" echo "Selected Tiling WM: $TWM"
echo "################################################################################" echo "################################################################################"
tput_reset color_reset
########################## ##########################
# Installation Level Selection # Installation Level Selection
########################## ##########################
echo echo
tput_yellow color_yellow
echo "################################################################" echo "################################################################"
echo "################### Installation Level Selection" echo "################### Installation Level Selection"
echo "################################################################" echo "################################################################"
tput_reset color_reset
echo echo
INSTALL_LEVEL="minimal" # default INSTALL_LEVEL="minimal" # default
@@ -189,11 +205,11 @@ while true; do
done done
echo echo
tput_cyan color_cyan
echo "################################################################################" echo "################################################################################"
echo "Selected Installation Level: $INSTALL_LEVEL" echo "Selected Installation Level: $INSTALL_LEVEL"
echo "################################################################################" echo "################################################################################"
tput_reset color_reset
########################## ##########################
# Export selections for OS script # Export selections for OS script
@@ -213,10 +229,10 @@ case "$OS" in
arch) OS_SCRIPT="./arch.sh" ;; arch) OS_SCRIPT="./arch.sh" ;;
fedora) OS_SCRIPT="./fedora.sh" ;; fedora) OS_SCRIPT="./fedora.sh" ;;
*) *)
tput_red color_red
echo echo
echo "No OS script available for $OS" echo "No OS script available for $OS"
tput_reset color_reset
exit 1 exit 1
;; ;;
esac esac
@@ -224,24 +240,39 @@ esac
########################## ##########################
# Preflight check # Preflight check
########################## ##########################
if [[ ! -x "$OS_SCRIPT" ]]; then if [[ ! -f "$OS_SCRIPT" ]]; then
tput_red color_red
echo echo
echo "ERROR: OS script not found or not executable: $OS_SCRIPT" echo "ERROR: OS script not found: $OS_SCRIPT"
tput_reset color_reset
exit 1 exit 1
fi fi
if [[ ! -x "$OS_SCRIPT" ]]; then
echo "Fixing permissions on $OS_SCRIPT..."
chmod +x "$OS_SCRIPT"
fi
########################## ##########################
# Run OS script # Run OS script (always via Bash)
########################## ##########################
echo echo
color_cyan
echo "Running OS script: $OS_SCRIPT" echo "Running OS script: $OS_SCRIPT"
"$OS_SCRIPT" color_reset
bash "$OS_SCRIPT" || {
color_red
echo
echo "ERROR: OS script failed: $OS_SCRIPT"
color_reset
exit 1
}
echo echo
tput_yellow color_yellow
echo "################################################################" echo "################################################################"
echo "End Detection" echo "End Detection"
echo "################################################################" echo "################################################################"
tput_reset color_reset
echo
echo "Logs saved to: $LOG_FILE"