fix colors

This commit is contained in:
[yuri]
2025-11-10 15:27:58 +01:00
parent aa7f8e97d0
commit 30bf2ac3a3

View File

@@ -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
@@ -35,18 +35,15 @@ INSTALL_LEVEL="${INSTALL_LEVEL:-minimal}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo
echo "${CYAN}Starting Debian setup...${RESET}"
say_cyan "Starting Debian setup..."
echo
echo "DE: $DE, TWM: $TWM, Install Level: $INSTALL_LEVEL"
say_gray "DE: $DE, TWM: $TWM, Install Level: $INSTALL_LEVEL"
##########################
# 0. Ensure curl is installed
##########################
if ! command -v curl >/dev/null 2>&1; then
echo
echo "${YELLOW}curl is not installed. Installing...${RESET}"
say_yellow "curl is not installed. Installing..."
sudo apt update
sudo apt -y install curl
fi
@@ -54,12 +51,10 @@ fi
##########################
# 1. Add contrib and non-free if missing
##########################
echo
echo "${YELLOW}Checking /etc/apt/sources.list for contrib/non-free...${RESET}"
say_yellow "Checking /etc/apt/sources.list for contrib/non-free..."
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak.$(date +%s)
sudo sed -i -r 's/^(deb\s+\S+\s+\S+)\s+(main)$/\1 main contrib non-free/' /etc/apt/sources.list
echo
echo "${GREEN}Updated sources.list to include contrib/non-free where needed.${RESET}"
say_green "Updated sources.list to include contrib/non-free where needed."
##########################
# 1a. Update archive.debian.org if needed
@@ -79,60 +74,48 @@ CURRENT_INDEX=$(codename_index "$CURRENT_CODENAME")
BULLSEYE_INDEX=$(codename_index "bullseye")
if [[ "$CURRENT_INDEX" -ge "$BULLSEYE_INDEX" ]] && grep -q "archive.debian.org" /etc/apt/sources.list; then
echo
echo "${YELLOW}Found archive.debian.org in sources.list and system is Bullseye or newer, updating to deb.debian.org...${RESET}"
say_yellow "Found archive.debian.org in sources.list and system is Bullseye or newer, updating to deb.debian.org..."
sudo sed -i -r 's|archive\.debian\.org|deb.debian.org|g' /etc/apt/sources.list
echo
echo "${GREEN}Updated sources.list to use deb.debian.org.${RESET}"
say_green "Updated sources.list to use deb.debian.org."
fi
##########################
# 2. Full update and upgrade
##########################
echo
echo "${YELLOW}Updating package lists...${RESET}"
say_yellow "Updating package lists..."
sudo apt update
# Autoremove before full-upgrade
AUTOREMOVE_PENDING=$(apt -s autoremove | grep -E 'Remv' || true)
if [[ -n "$AUTOREMOVE_PENDING" ]]; then
echo
echo "${YELLOW}Removing packages that are no longer required before upgrade...${RESET}"
say_yellow "Removing packages that are no longer required before upgrade..."
sudo apt -y autoremove
fi
echo
echo "${YELLOW}Upgrading installed packages...${RESET}"
say_yellow "Upgrading installed packages..."
sudo apt -y full-upgrade
# Autoremove after full-upgrade
AUTOREMOVE_PENDING=$(apt -s autoremove | grep -E 'Remv' || true)
if [[ -n "$AUTOREMOVE_PENDING" ]]; then
echo
echo "${YELLOW}Removing packages that are no longer required after upgrade...${RESET}"
say_yellow "Removing packages that are no longer required after upgrade..."
sudo apt -y autoremove
fi
UPGRADE_PENDING=$(apt list --upgradable 2>/dev/null | grep -v Listing || true)
if [[ -n "$UPGRADE_PENDING" ]]; then
echo
echo "${RED}Some packages were upgraded. A reboot is recommended before continuing.${RESET}"
say_red "Some packages were upgraded. A reboot is recommended before continuing."
read -rp "Reboot now? [y/N]: " reboot_choice
case "${reboot_choice,,}" in
y|yes)
echo
echo "${RED}Rebooting now. After reboot, please restart this script to continue...${RESET}"
say_red "Rebooting now. After reboot, please restart this script to continue..."
sudo reboot
;;
*)
echo
echo "${YELLOW}Skipping reboot. Make sure to reboot manually before continuing upgrades.${RESET}"
say_yellow "Skipping reboot. Make sure to reboot manually before continuing upgrades."
exit 0
;;
esac
else
echo
echo "${GREEN}All packages are up to date. Continuing to Debian major version check...${RESET}"
say_green "All packages are up to date. Continuing to Debian major version check..."
fi
##########################
@@ -142,9 +125,8 @@ DEBIAN_SEQUENCE=(buster bullseye bookworm trixie)
CURRENT_CODENAME=$(grep -Po 'deb\s+\S+\s+\K\S+' /etc/apt/sources.list | grep -E '^(buster|bullseye|bookworm|trixie)$' | head -n1)
LATEST_CODENAME=${DEBIAN_SEQUENCE[-1]}
echo
echo "${CYAN}Current codename: $CURRENT_CODENAME"
echo "Latest stable codename: $LATEST_CODENAME${RESET}"
say_cyan "Current codename: $CURRENT_CODENAME"
say_cyan "Latest stable codename: $LATEST_CODENAME"
while [[ "$CURRENT_CODENAME" != "$LATEST_CODENAME" ]]; do
NEXT_CODENAME=""
@@ -156,48 +138,29 @@ while [[ "$CURRENT_CODENAME" != "$LATEST_CODENAME" ]]; do
done
if [[ -z "$NEXT_CODENAME" ]]; then
echo
echo "${RED}Error: Cannot determine next codename after $CURRENT_CODENAME${RESET}"
say_red "Error: Cannot determine next codename after $CURRENT_CODENAME"
exit 1
fi
echo
echo "${YELLOW}Detected codename $CURRENT_CODENAME, next stable version: $NEXT_CODENAME${RESET}"
say_yellow "Detected codename $CURRENT_CODENAME, next stable version: $NEXT_CODENAME"
read -rp "Do you want to upgrade to $NEXT_CODENAME? [y/N]: " choice
case "${choice,,}" in
y|yes)
echo
echo "${YELLOW}Updating sources.list to $NEXT_CODENAME...${RESET}"
say_yellow "Updating sources.list to $NEXT_CODENAME..."
sudo sed -i -r "s/\b$CURRENT_CODENAME\b/$NEXT_CODENAME/g" /etc/apt/sources.list
echo
echo "${YELLOW}Updating packages...${RESET}"
say_yellow "Updating packages..."
sudo apt update
AUTOREMOVE_PENDING=$(apt -s autoremove | grep -E 'Remv' || true)
if [[ -n "$AUTOREMOVE_PENDING" ]]; then
echo
echo "${YELLOW}Removing packages that are no longer required before upgrade...${RESET}"
sudo apt -y autoremove
fi
sudo apt -y autoremove || true
sudo apt -y full-upgrade
sudo apt -y autoremove || true
AUTOREMOVE_PENDING=$(apt -s autoremove | grep -E 'Remv' || true)
if [[ -n "$AUTOREMOVE_PENDING" ]]; then
echo
echo "${YELLOW}Removing packages that are no longer required after upgrade...${RESET}"
sudo apt -y autoremove
fi
echo
echo "${GREEN}Upgrade to $NEXT_CODENAME complete. A reboot is recommended.${RESET}"
say_green "Upgrade to $NEXT_CODENAME complete. A reboot is recommended."
read -rp "Press Enter to reboot..." _
sudo reboot
;;
*)
echo
echo "${YELLOW}Skipping upgrade to $NEXT_CODENAME. Continuing with current version.${RESET}"
say_yellow "Skipping upgrade to $NEXT_CODENAME. Continuing with current version."
break
;;
esac
@@ -205,31 +168,25 @@ while [[ "$CURRENT_CODENAME" != "$LATEST_CODENAME" ]]; do
CURRENT_CODENAME=$(grep -Po 'deb\s+\S+\s+\K\S+' /etc/apt/sources.list | grep -E '^(buster|bullseye|bookworm|trixie)$' | head -n1)
done
echo
echo "${GREEN}Debian is now at codename $CURRENT_CODENAME. Continuing with DE/TWM installation...${RESET}"
say_green "Debian is now at codename $CURRENT_CODENAME. Continuing with DE/TWM installation..."
##########################
# 4. Desktop Environment installation
##########################
case "$DE" in
xfce|plasma|gnome)
echo
echo "${YELLOW}Preparing to install $DE...${RESET}"
say_yellow "Preparing to install $DE..."
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${DE}.sh"
if [[ -f "$SCRIPT_NAME" ]]; then
echo
echo "${CYAN}Running $SCRIPT_NAME...${RESET}"
say_cyan "Running $SCRIPT_NAME..."
bash "$SCRIPT_NAME"
else
echo
echo "${RED}Error: $SCRIPT_NAME not found!${RESET}"
say_red "Error: $SCRIPT_NAME not found!"
exit 1
fi
;;
none)
echo
echo "${GRAY}No Desktop Environment selected, skipping DE installation.${RESET}"
say_gray "No Desktop Environment selected, skipping DE installation."
;;
esac
@@ -238,23 +195,18 @@ esac
##########################
case "$TWM" in
chadwm|hyprland)
echo
echo "${YELLOW}Installing $TWM...${RESET}"
say_yellow "Installing $TWM..."
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${TWM}.sh"
if [[ -f "$SCRIPT_NAME" ]]; then
echo
echo "${CYAN}Running $SCRIPT_NAME...${RESET}"
say_cyan "Running $SCRIPT_NAME..."
bash "$SCRIPT_NAME"
else
echo
echo "${RED}Error: $SCRIPT_NAME not found!${RESET}"
say_red "Error: $SCRIPT_NAME not found!"
exit 1
fi
;;
none)
echo
echo "${GRAY}No tiling window manager selected.${RESET}"
say_gray "No tiling window manager selected."
;;
esac
@@ -263,40 +215,28 @@ esac
##########################
case "$INSTALL_LEVEL" in
minimal|full|workstation|server)
echo
echo "${CYAN}Installation level: $INSTALL_LEVEL${RESET}"
say_cyan "Installation level: $INSTALL_LEVEL"
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${INSTALL_LEVEL}.sh"
if [[ -f "$SCRIPT_NAME" ]]; then
echo
echo "${CYAN}Running $SCRIPT_NAME...${RESET}"
say_cyan "Running $SCRIPT_NAME..."
bash "$SCRIPT_NAME"
else
echo
echo "${RED}Error: $SCRIPT_NAME not found!${RESET}"
say_red "Error: $SCRIPT_NAME not found!"
exit 1
fi
;;
esac
echo
echo "${GREEN}Debian setup complete.${RESET}"
##########################
# 7. Installation Finished
##########################
echo
echo "${RED}The installation has finished. A reboot is recommended before continuing.${RESET}"
read -rp "Reboot now? [y/N]: " reboot_choice
case "${reboot_choice,,}" in
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)
echo
echo "${RED}Rebooting now.${RESET}"
say_red "Rebooting now."
sudo reboot
;;
*)
echo
echo "${YELLOW}Skipping reboot. Make sure to reboot manually before continuing upgrades.${RESET}"
say_yellow "Skipping reboot. Make sure to reboot manually before continuing upgrades."
exit 0
;;
esac
esac