From ea55b1524b36c4562bd13f3ffdc9e4242af97813 Mon Sep 17 00:00:00 2001 From: "[yuri]" <[yuri.kuit@gmail.com]> Date: Mon, 10 Nov 2025 15:54:48 +0100 Subject: [PATCH] fix colors --- v2/debian-chadwm.sh | 39 ++++++++++++++++---------------- v2/debian-full.sh | 32 ++++++++++++++++++-------- v2/debian-gnome.sh | 44 ++++++++++++++++++++++-------------- v2/debian-hyprland.sh | 32 ++++++++++++++++++-------- v2/debian-minimal.sh | 35 ++++++++++++++++++---------- v2/debian-plasma.sh | 43 +++++++++++++++++++++-------------- v2/debian-server.sh | 32 ++++++++++++++++++-------- v2/debian-workstation.sh | 32 ++++++++++++++++++-------- v2/debian-xfce.sh | 49 ++++++++++++++++++++++------------------ 9 files changed, 214 insertions(+), 124 deletions(-) diff --git a/v2/debian-chadwm.sh b/v2/debian-chadwm.sh index 5c1d458..04a80e0 100755 --- a/v2/debian-chadwm.sh +++ b/v2/debian-chadwm.sh @@ -2,27 +2,27 @@ set -euo pipefail ########################## -# Color helpers (no tput) +# Color helpers (printf-safe, no tput) ########################## -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' +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='' + RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" fi -color_red() { printf '%b' "$RED"; } -color_green() { printf '%b' "$GREEN"; } -color_yellow() { printf '%b' "$YELLOW"; } -color_cyan() { printf '%b' "$CYAN"; } -color_gray() { printf '%b' "$GRAY"; } -color_reset() { printf '%b' "$RESET"; } +say_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } +say_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } +say_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } +say_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } +say_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } +say_bold() { printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } ########################## # Use exported variables from main detection script @@ -33,15 +33,14 @@ DE="${SELECTED_DE:-none}" TWM="${SELECTED_TWM:-none}" INSTALL_LEVEL="${INSTALL_LEVEL:-minimal}" -color_cyan + echo -echo "Starting Debian Chadwm setup..." -color_reset -echo "DE: $DE, TWM: $TWM, Install Level: $INSTALL_LEVEL" +say_cyan "Starting Debian Chadwm setup..." +say_cyan "DE: $DE, TWM: $TWM, Install Level: $INSTALL_LEVEL" echo # End of script -color_green; echo "Chadwm setup completed."; color_reset +say_green "Chadwm setup completed." # Pause read -n 1 -s -r -p "Press any key to continue" diff --git a/v2/debian-full.sh b/v2/debian-full.sh index 64e7732..5e1a00e 100755 --- a/v2/debian-full.sh +++ b/v2/debian-full.sh @@ -1,14 +1,28 @@ #!/bin/bash set -euo pipefail -# Colors + logging same as others -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' -[ ! -t 1 ] && RED='' GREEN='' YELLOW='' CYAN='' GRAY='' BOLD='' RESET='' +########################## +# Color helpers (printf-safe, no tput) +########################## +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" -color_yellow() { printf '%b' "$YELLOW"; } -color_green() { printf '%b' "$GREEN"; } -color_reset() { printf '%b' "$RESET"; } +# Disable colors if output is not a terminal +if [ ! -t 1 ]; then + RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" +fi + +say_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } +say_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } +say_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } +say_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } +say_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } +say_bold() { printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" OS="${DETECTED_OS:-debian}" @@ -19,7 +33,7 @@ OS="${DETECTED_OS:-debian}" install_packages() { sudo apt update; sudo apt install -y --no-install-recommends "$@"; } is_package_installed() { dpkg -s "$1" &>/dev/null; } -color_yellow; echo "Starting full setup..."; color_reset +say_yellow "Starting full setup..." # Run minimal first bash "$SCRIPT_DIR/debian-minimal.sh" @@ -39,4 +53,4 @@ sudo sed -i 's/^managed=.*/managed=true/' /etc/NetworkManager/NetworkManager.con sudo systemctl restart NetworkManager # End of script -color_green; echo "Full setup completed."; color_reset +say_green "Full setup completed." diff --git a/v2/debian-gnome.sh b/v2/debian-gnome.sh index d04bd11..0c013b5 100755 --- a/v2/debian-gnome.sh +++ b/v2/debian-gnome.sh @@ -1,18 +1,28 @@ #!/bin/bash set -euo pipefail -# Color helpers, logging, variables identical to plasma/xfce scripts +########################## +# Color helpers (printf-safe, no tput) +########################## +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" -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' -[ ! -t 1 ] && RED='' GREEN='' YELLOW='' CYAN='' GRAY='' BOLD='' RESET='' +# Disable colors if output is not a terminal +if [ ! -t 1 ]; then + RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" +fi -color_red() { printf '%b' "$RED"; } -color_green() { printf '%b' "$GREEN"; } -color_yellow() { printf '%b' "$YELLOW"; } -color_cyan() { printf '%b' "$CYAN"; } -color_gray() { printf '%b' "$GRAY"; } -color_reset() { printf '%b' "$RESET"; } +say_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } +say_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } +say_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } +say_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } +say_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } +say_bold() { printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" OS="${DETECTED_OS:-debian}" @@ -30,26 +40,26 @@ detect_de() { command -v gnome-session >/dev/null 2>&1 && echo "gnome" || echo " detect_display_manager() { [ -f /etc/X11/default-display-manager ] && basename "$(cat /etc/X11/default-display-manager)" || echo ""; } enable_graphical_target() { sudo systemctl enable sddm; sudo systemctl set-default graphical.target; } -color_yellow; echo "Starting Gnome installation..."; color_reset +say_yellow "Starting Gnome installation..." CURRENT_DE="$(detect_de)" CURRENT_DM="$(detect_display_manager)" if [[ -z "$CURRENT_DE" ]]; then - color_cyan; echo "No DE detected. Installing Gnome with SDDM..."; color_reset + say_cyan "No DE detected. Installing Gnome with SDDM..." install_packages sddm gnome-shell gnome-terminal nautilus gnome-control-center gnome-system-monitor gnome-tweaks network-manager-gnome gnome-keyring gnome-session enable_graphical_target - color_green; echo "Gnome with SDDM installed successfully."; color_reset + say_green "Gnome with SDDM installed successfully." else - color_cyan; echo "Detected existing DE: $CURRENT_DE"; color_reset + say_cyan "Detected existing DE: $CURRENT_DE" if [[ "$CURRENT_DM" == "lightdm" ]]; then - color_yellow; echo "Replacing LightDM with SDDM..."; color_reset + say_yellow "Replacing LightDM with SDDM..." sudo systemctl disable lightdm sudo apt purge -y lightdm lightdm-gtk-greeter install_packages sddm enable_graphical_target - color_green; echo "LightDM replaced with SDDM."; color_reset + say_green "LightDM replaced with SDDM." else - color_cyan; echo "Current DM: ${CURRENT_DM:-none}, leaving unchanged."; color_reset + say_cyan "Current DM: ${CURRENT_DM:-none}, leaving unchanged." fi fi diff --git a/v2/debian-hyprland.sh b/v2/debian-hyprland.sh index 8a14323..24f10dc 100755 --- a/v2/debian-hyprland.sh +++ b/v2/debian-hyprland.sh @@ -1,14 +1,28 @@ #!/bin/bash set -euo pipefail -# Colors + logging same pattern -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' -[ ! -t 1 ] && RED='' GREEN='' YELLOW='' CYAN='' GRAY='' BOLD='' RESET='' +########################## +# Color helpers (printf-safe, no tput) +########################## +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" -color_yellow() { printf '%b' "$YELLOW"; } -color_green() { printf '%b' "$GREEN"; } -color_reset() { printf '%b' "$RESET"; } +# Disable colors if output is not a terminal +if [ ! -t 1 ]; then + RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" +fi + +say_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } +say_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } +say_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } +say_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } +say_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } +say_bold() { printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" OS="${DETECTED_OS:-debian}" @@ -19,13 +33,13 @@ OS="${DETECTED_OS:-debian}" install_packages() { sudo apt update; sudo apt install -y --no-install-recommends "$@"; } is_package_installed() { dpkg -s "$1" &>/dev/null; } -color_yellow; echo "Starting hyprland setup..."; color_reset +say_yellow "Starting hyprland setup..." # Optionally add hyprland-specific packages here #install_packages ???? # End of script -color_green; echo "hyprland setup completed."; color_reset +say_green "hyprland setup completed." # Pause read -n 1 -s -r -p "Press any key to continue" diff --git a/v2/debian-minimal.sh b/v2/debian-minimal.sh index 9e27b78..90f61be 100755 --- a/v2/debian-minimal.sh +++ b/v2/debian-minimal.sh @@ -1,17 +1,28 @@ #!/bin/bash set -euo pipefail -# Colors + logging same pattern -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' -[ ! -t 1 ] && RED='' GREEN='' YELLOW='' CYAN='' GRAY='' BOLD='' RESET='' +########################## +# Color helpers (printf-safe, no tput) +########################## +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" -color_red() { printf '%b' "$RED"; } -color_green() { printf '%b' "$GREEN"; } -color_yellow() { printf '%b' "$YELLOW"; } -color_cyan() { printf '%b' "$CYAN"; } -color_gray() { printf '%b' "$GRAY"; } -color_reset() { printf '%b' "$RESET"; } +# Disable colors if output is not a terminal +if [ ! -t 1 ]; then + RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" +fi + +say_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } +say_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } +say_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } +say_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } +say_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } +say_bold() { printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" OS="${DETECTED_OS:-debian}" @@ -23,7 +34,7 @@ DE="${SELECTED_DE:-none}" install_packages() { sudo apt update; sudo apt install -y --no-install-recommends "$@"; } is_package_installed() { dpkg -s "$1" &>/dev/null; } -color_yellow; echo "Starting minimal setup..."; color_reset +say_yellow "Starting minimal setup..." # Create user directories mkdir -p "$HOME"/{.bin,.fonts,.icons,.themes,DATA} "$HOME/.local/share/"{icons,themes,applications} "$HOME/.config/"{autostart,gtk-{3.0,4.0},variety,fish,neofetch} @@ -43,4 +54,4 @@ sudo systemctl enable chrony sudo systemctl enable fstrim.timer # End of script -color_green; echo "Minimal setup completed."; color_reset \ No newline at end of file +say_green "Minimal setup completed." \ No newline at end of file diff --git a/v2/debian-plasma.sh b/v2/debian-plasma.sh index f40f41d..66d0340 100755 --- a/v2/debian-plasma.sh +++ b/v2/debian-plasma.sh @@ -2,18 +2,27 @@ set -euo pipefail ########################## -# Color helpers +# Color helpers (printf-safe, no tput) ########################## -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' -[ ! -t 1 ] && RED='' GREEN='' YELLOW='' CYAN='' GRAY='' BOLD='' RESET='' +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" -color_red() { printf '%b' "$RED"; } -color_green() { printf '%b' "$GREEN"; } -color_yellow() { printf '%b' "$YELLOW"; } -color_cyan() { printf '%b' "$CYAN"; } -color_gray() { printf '%b' "$GRAY"; } -color_reset() { printf '%b' "$RESET"; } +# Disable colors if output is not a terminal +if [ ! -t 1 ]; then + RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" +fi + +say_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } +say_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } +say_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } +say_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } +say_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } +say_bold() { printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } ########################## # Variables @@ -37,27 +46,27 @@ enable_graphical_target() { sudo systemctl enable sddm; sudo systemctl set-defau ########################## # Install Plasma ########################## -color_yellow; echo "Starting KDE Plasma installation..."; color_reset +say_yellow "Starting KDE Plasma installation..." CURRENT_DE="$(detect_de)" CURRENT_DM="$(detect_display_manager)" if [[ -z "$CURRENT_DE" ]]; then - color_cyan; echo "No DE detected. Installing KDE Plasma with SDDM..."; color_reset + say_cyan "No DE detected. Installing KDE Plasma with SDDM..." install_packages sddm plasma-desktop dolphin konsole kate plasma-nm plasma-workspace kde-config-gtk-style kde-config-sddm plasma-discover kscreen enable_graphical_target - color_green; echo "KDE Plasma with SDDM installed successfully."; color_reset + say_green "KDE Plasma with SDDM installed successfully." else - color_cyan; echo "Detected existing DE: $CURRENT_DE"; color_reset + say_cyan "Detected existing DE: $CURRENT_DE" if [[ "$CURRENT_DM" == "lightdm" ]]; then - color_yellow; echo "Replacing LightDM with SDDM..."; color_reset + colosay_yellow "Replacing LightDM with SDDM..." sudo systemctl disable lightdm sudo apt purge -y lightdm lightdm-gtk-greeter install_packages sddm enable_graphical_target - color_green; echo "LightDM replaced with SDDM."; color_reset + say_green "LightDM replaced with SDDM." else - color_cyan; echo "Current DM: ${CURRENT_DM:-none}, leaving unchanged."; color_reset + say_cyan "Current DM: ${CURRENT_DM:-none}, leaving unchanged." fi fi diff --git a/v2/debian-server.sh b/v2/debian-server.sh index cccd337..b5cab87 100755 --- a/v2/debian-server.sh +++ b/v2/debian-server.sh @@ -1,14 +1,28 @@ #!/bin/bash set -euo pipefail -# Colors + logging same pattern -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' -[ ! -t 1 ] && RED='' GREEN='' YELLOW='' CYAN='' GRAY='' BOLD='' RESET='' +########################## +# Color helpers (printf-safe, no tput) +########################## +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" -color_yellow() { printf '%b' "$YELLOW"; } -color_green() { printf '%b' "$GREEN"; } -color_reset() { printf '%b' "$RESET"; } +# Disable colors if output is not a terminal +if [ ! -t 1 ]; then + RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" +fi + +say_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } +say_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } +say_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } +say_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } +say_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } +say_bold() { printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" OS="${DETECTED_OS:-debian}" @@ -19,13 +33,13 @@ OS="${DETECTED_OS:-debian}" install_packages() { sudo apt update; sudo apt install -y --no-install-recommends "$@"; } is_package_installed() { dpkg -s "$1" &>/dev/null; } -color_yellow; echo "Starting Server setup..."; color_reset +say_yellow "Starting Server setup..." # Optionally add Server-specific packages here install_packages linux-headers-$(uname -r) # End of script -color_green; echo "Server setup completed."; color_reset +say_green "Server setup completed." # Pause read -n 1 -s -r -p "Press any key to continue" diff --git a/v2/debian-workstation.sh b/v2/debian-workstation.sh index 9e7df81..158ff68 100755 --- a/v2/debian-workstation.sh +++ b/v2/debian-workstation.sh @@ -1,14 +1,28 @@ #!/bin/bash set -euo pipefail -# Colors + logging same pattern -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' -[ ! -t 1 ] && RED='' GREEN='' YELLOW='' CYAN='' GRAY='' BOLD='' RESET='' +########################## +# Color helpers (printf-safe, no tput) +########################## +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" -color_yellow() { printf '%b' "$YELLOW"; } -color_green() { printf '%b' "$GREEN"; } -color_reset() { printf '%b' "$RESET"; } +# Disable colors if output is not a terminal +if [ ! -t 1 ]; then + RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" +fi + +say_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } +say_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } +say_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } +say_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } +say_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } +say_bold() { printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" OS="${DETECTED_OS:-debian}" @@ -19,7 +33,7 @@ OS="${DETECTED_OS:-debian}" install_packages() { sudo apt update; sudo apt install -y --no-install-recommends "$@"; } is_package_installed() { dpkg -s "$1" &>/dev/null; } -color_yellow; echo "Starting workstation setup..."; color_reset +say_yellow "Starting workstation setup..." # Run full setup first bash "$SCRIPT_DIR/debian-full.sh" @@ -28,7 +42,7 @@ bash "$SCRIPT_DIR/debian-full.sh" install_packages git vlc libreoffice # End of script -color_green; echo "Workstation setup completed."; color_reset +say_green "Workstation setup completed." # Pause read -n 1 -s -r -p "Press any key to continue" diff --git a/v2/debian-xfce.sh b/v2/debian-xfce.sh index 7d991f7..7421d45 100755 --- a/v2/debian-xfce.sh +++ b/v2/debian-xfce.sh @@ -2,22 +2,27 @@ set -euo pipefail ########################## -# Color helpers (no tput) +# Color helpers (printf-safe, no tput) ########################## -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' +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" -color_red() { printf '%b' "$RED"; } -color_green() { printf '%b' "$GREEN"; } -color_yellow() { printf '%b' "$YELLOW"; } -color_cyan() { printf '%b' "$CYAN"; } -color_gray() { printf '%b' "$GRAY"; } -color_reset() { printf '%b' "$RESET"; } +# Disable colors if output is not a terminal +if [ ! -t 1 ]; then + RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET="" +fi + +say_red() { printf "%b%s%b\n" "$RED" "$*" "$RESET"; } +say_green() { printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; } +say_yellow() { printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; } +say_cyan() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; } +say_gray() { printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; } +say_bold() { printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; } ########################## # Paths and variables @@ -65,23 +70,23 @@ enable_graphical_target() { ########################## # Start installation ########################## -echo -e "${YELLOW}Starting XFCE installation...${RESET}" +say_yellow -e "Starting XFCE installation..." CURRENT_DE="$(detect_de)" CURRENT_DM="$(detect_display_manager)" if [[ -z "$CURRENT_DE" ]]; then - echo -e "${CYAN}No Desktop Environment detected. Installing XFCE (light setup with SDDM)...${RESET}" + say_cyan -e "No Desktop Environment detected. Installing XFCE (light setup with SDDM)..." install_packages sddm xfce4 xfce4-goodies enable_graphical_target - echo -e "${GREEN}XFCE with SDDM installed successfully. You can reboot now to start XFCE.${RESET}" + say_green -e "XFCE with SDDM installed successfully. You can reboot now to start XFCE." else - echo -e "${CYAN}Detected existing Desktop Environment: $CURRENT_DE${RESET}" + say_cyan -e "Detected existing Desktop Environment: $CURRENT_DE" if [[ "$CURRENT_DM" == "lightdm" ]]; then - echo -e "${YELLOW}LightDM is currently active. Replacing with SDDM...${RESET}" + say_yellow -e "LightDM is currently active. Replacing with SDDM..." sudo systemctl disable lightdm sudo apt purge -y lightdm lightdm-gtk-greeter @@ -89,9 +94,9 @@ else install_packages sddm enable_graphical_target - echo -e "${GREEN}LightDM removed and replaced with SDDM.${RESET}" + say_green -e "LightDM removed and replaced with SDDM." else - echo -e "${CYAN}Current display manager: ${CURRENT_DM:-none}. Leaving unchanged.${RESET}" + say_cyan -e "Current display manager: ${CURRENT_DM:-none}. Leaving unchanged." fi fi @@ -101,4 +106,4 @@ echo -e "[Autologin]\nSession=xfce.desktop" | sudo tee /etc/sddm.conf.d/10-xfce. echo -e "[General]\nSession=xfce.desktop" | sudo tee /etc/sddm.conf.d/10-xfce-session.conf >/dev/null # End of script -echo -e "${GREEN}XFCE / SDDM setup completed.${RESET}" +say_green -e "XFCE / SDDM setup completed."