From 26948f63d00d3d2db3ead393b670753c6cfa5cf7 Mon Sep 17 00:00:00 2001 From: "[yuri]" <[yuri.kuit@gmail.com]> Date: Mon, 10 Nov 2025 10:33:22 +0100 Subject: [PATCH] cleanup launch script --- 0-setup-linux.sh | 117 ++++++++++++++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 43 deletions(-) diff --git a/0-setup-linux.sh b/0-setup-linux.sh index aafbc8f..068a613 100755 --- a/0-setup-linux.sh +++ b/0-setup-linux.sh @@ -2,24 +2,42 @@ set -euo pipefail ########################## -# Color helpers +# Color helpers (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' +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_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 -tput_yellow +color_yellow echo "################################################################" echo "################### Start OS Detection" echo "################################################################" -tput_reset +color_reset echo ########################## @@ -40,7 +58,6 @@ case "$OS_ID" in ubuntu) OS="ubuntu" ;; fedora) OS="fedora" ;; *) - # fallback for derivatives if [[ "$OS_LIKE" == *"ubuntu"* ]]; then OS="ubuntu" elif [[ "$OS_LIKE" == *"arch"* ]]; then @@ -54,19 +71,19 @@ case "$OS_ID" in esac if [[ -n "$OS" ]]; then - tput_cyan + color_cyan echo "################################################################################" echo "Detected OS: $OS ($OS_PRETTY)" echo "Version: $OS_VERSION" echo "################################################################################" - tput_reset + color_reset else - tput_red + color_red echo "################################################################################" echo "ERROR: Unsupported or unknown Linux distribution." echo "Detected: ID=$OS_ID, ID_LIKE=${OS_LIKE:-empty}" echo "################################################################################" - tput_reset + color_reset exit 1 fi @@ -74,11 +91,11 @@ fi # Desktop Environment Detection / Selection ########################## echo -tput_yellow +color_yellow echo "################################################################" echo "################### Desktop Environment Selection" echo "################################################################" -tput_reset +color_reset echo DE_RAW="${XDG_CURRENT_DESKTOP:-${DESKTOP_SESSION:-}}" @@ -88,18 +105,17 @@ case "${DE_RAW,,}" in *xfce*) DE="xfce" ;; *plasma*|*kde*) DE="plasma" ;; *gnome*) DE="gnome" ;; - ""|none) DE="" ;; # trigger menu + ""|none) DE="" ;; esac if [[ -n "$DE" ]]; then echo - tput_cyan + color_cyan echo "################################################################################" echo "Detected Desktop Environment: $DE (${DE_RAW})" echo "################################################################################" - tput_reset + color_reset else - # No DE detected — ask user echo echo "No Desktop Environment detected. Select one to install:" while true; do @@ -117,22 +133,22 @@ else esac done echo - tput_cyan + color_cyan echo "################################################################################" echo "Selected Desktop Environment: $DE" echo "################################################################################" - tput_reset + color_reset fi ########################## # Tiling Window Manager Selection ########################## echo -tput_yellow +color_yellow echo "################################################################" echo "################### Tiling WM Selection" echo "################################################################" -tput_reset +color_reset echo TWM="none" @@ -152,21 +168,21 @@ while true; do done echo -tput_cyan +color_cyan echo "################################################################################" echo "Selected Tiling WM: $TWM" echo "################################################################################" -tput_reset +color_reset ########################## # Installation Level Selection ########################## echo -tput_yellow +color_yellow echo "################################################################" echo "################### Installation Level Selection" echo "################################################################" -tput_reset +color_reset echo INSTALL_LEVEL="minimal" # default @@ -189,11 +205,11 @@ while true; do done echo -tput_cyan +color_cyan echo "################################################################################" echo "Selected Installation Level: $INSTALL_LEVEL" echo "################################################################################" -tput_reset +color_reset ########################## # Export selections for OS script @@ -213,10 +229,10 @@ case "$OS" in arch) OS_SCRIPT="./arch.sh" ;; fedora) OS_SCRIPT="./fedora.sh" ;; *) - tput_red + color_red echo echo "No OS script available for $OS" - tput_reset + color_reset exit 1 ;; esac @@ -224,24 +240,39 @@ esac ########################## # Preflight check ########################## -if [[ ! -x "$OS_SCRIPT" ]]; then - tput_red +if [[ ! -f "$OS_SCRIPT" ]]; then + color_red echo - echo "ERROR: OS script not found or not executable: $OS_SCRIPT" - tput_reset + echo "ERROR: OS script not found: $OS_SCRIPT" + color_reset exit 1 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 +color_cyan 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 -tput_yellow +color_yellow echo "################################################################" echo "End Detection" echo "################################################################" -tput_reset +color_reset +echo +echo "Logs saved to: $LOG_FILE"