diff --git a/debianito.sh b/debianito.sh index d25ec6f..0aa5c22 100644 --- a/debianito.sh +++ b/debianito.sh @@ -142,7 +142,7 @@ if ! _check_network; then echo -e "${YELLOW} other offline features.${NC}" echo -e "${YELLOW}──────────────────────────────────────────${NC}" fi -check_system_time +_ensure_time_synced detect_debian_version detect_cpu_ram diff --git a/modules/extras.sh b/modules/extras.sh index 959f42a..053ab85 100644 --- a/modules/extras.sh +++ b/modules/extras.sh @@ -39,11 +39,12 @@ install_extras() { "7" "Code Editors & IDEs" \ "8" "Servers & Dev Tools" \ "9" "Security & Networking" \ - "10" "Software Centers" \ + "10" "Software Center & Flatpak" \ "11" "Office & Productivity" \ "12" "System Tools" \ "13" "Fetch / System Info" \ - "14" "Back to main menu") + "14" "Audio & Sound" \ + "15" "Back to main menu") [ -z "$cat_choice" ] && return clear @@ -63,7 +64,8 @@ install_extras() { 11) _cat_office ;; 12) _cat_general ;; 13) _cat_fetch ;; - 14) return ;; + 14) _cat_audio ;; + 15) return ;; esac clear done diff --git a/modules/extras/audio/audio.sh b/modules/extras/audio/audio.sh new file mode 100644 index 0000000..df18e6e --- /dev/null +++ b/modules/extras/audio/audio.sh @@ -0,0 +1,169 @@ +#!/usr/bin/env bash +# audio.sh — Audio & Sound (PipeWire, ALSA, PulseAudio tools) + +_cat_audio() { + local headless=false + _is_headless && headless=true + + local -a items=() + + local pw_state; pw_state=$(_state "pipewire") + items+=( + "pipewire-standard" "PipeWire Audio Stack (Recommended)" "$pw_state" + ) + + if [ "$DEBIAN_VERSION" = "13" ]; then + local bpo_state; bpo_state=$(_state "pipewire") + items+=( + "pipewire-backports" "PipeWire from Backports (v1.4.9)" "off" + ) + fi + + local alsa_state; alsa_state=$(_state "alsa-utils") + items+=( + "alsa-utils" "ALSA Utilities (alsa-utils, alsa-ucm-conf)" "$alsa_state" + ) + + if ! $headless; then + local pavu_state; pavu_state=$(_state "pavucontrol") + items+=( + "pavucontrol" "Volume Control GUI (pavucontrol)" "$pavu_state" + ) + fi + + local pulsemixer_state; pulsemixer_state=$(_state "pulsemixer") + local playerctl_state; playerctl_state=$(_state "playerctl") + items+=( + "pulsemixer" "Terminal audio mixer (pulsemixer)" "$pulsemixer_state" + "playerctl" "Multimedia key controller (playerctl)" "$playerctl_state" + ) + + local item_count=${#items[@]} + local lista_alto=$((item_count > TUI_ALTO_LISTA ? TUI_ALTO_LISTA : item_count)) + local choices + choices=$(_checklist "Audio & Sound" "Check [*] the packages you want installed.\n" \ + $TUI_ALTO $TUI_ANCHO $lista_alto "${items[@]}") + clear + [ -z "$choices" ] && return + + local cleaned; cleaned=$(echo "$choices" | tr -d '"') + + local do_pipewire_standard=false + local do_pipewire_backports=false + + for pkg in $cleaned; do + case $pkg in + pipewire-standard) do_pipewire_standard=true ;; + pipewire-backports) do_pipewire_backports=true ;; + esac + done + + for pkg in $cleaned; do + case $pkg in + pipewire-standard) + if $do_pipewire_backports; then + continue + fi + _install_pipewire_standard + ;; + pipewire-backports) + _install_pipewire_backports + ;; + alsa-utils) + if ! is_installed "alsa-utils"; then + _run_install "alsa-utils alsa-ucm-conf" + else + echo "alsa-utils already installed." + fi + ;; + pavucontrol) + if ! is_installed "pavucontrol"; then + _run_install "pavucontrol" + else + echo "pavucontrol already installed." + fi + ;; + pulsemixer) + if ! is_installed "pulsemixer"; then + _run_install "pulsemixer" + else + echo "pulsemixer already installed." + fi + ;; + playerctl) + if ! is_installed "playerctl"; then + _run_install "playerctl" + else + echo "playerctl already installed." + fi + ;; + esac + done + + if $do_pipewire_standard || $do_pipewire_backports; then + if [ "$DEBIAN_VERSION" != "11" ]; then + echo "Restarting PipeWire services..." + systemctl --user restart wireplumber pipewire pipewire-pulse 2>/dev/null || true + echo -e "${GREEN}PipeWire services restarted.${NC}" + fi + fi + + echo -e "${GREEN}Audio & Sound setup complete.${NC}" +} + +_install_pipewire_standard() { + case "$DEBIAN_VERSION" in + 11) + if ! is_installed "pipewire"; then + _run_cmd "PipeWire" \ + "sudo apt install -y pipewire libspa-0.2-bluetooth pipewire-alsa libspa-0.2-jack" \ + "Installing PipeWire (Bullseye basic mode)..." + echo -e "${GREEN}PipeWire installed (Bullseye basic mode).${NC}" + else + echo "PipeWire already installed." + fi + ;; + 12) + if ! is_installed "pipewire-audio"; then + _run_cmd "PipeWire" \ + "sudo apt install -y pipewire-audio" \ + "Installing pipewire-audio meta-package (Bookworm)..." + echo -e "${GREEN}PipeWire audio stack installed.${NC}" + else + echo "pipewire-audio already installed." + fi + ;; + 13) + if ! is_installed "pipewire-audio"; then + _run_cmd "PipeWire" \ + "sudo apt install -y pipewire-audio" \ + "Installing pipewire-audio meta-package (Trixie)..." + echo -e "${GREEN}PipeWire audio stack installed.${NC}" + else + echo "pipewire-audio already installed." + fi + ;; + esac +} + +_install_pipewire_backports() { + if [ "$DEBIAN_VERSION" != "13" ]; then + echo -e "${YELLOW}Backports install is only available on Debian 13 (Trixie). Skipping.${NC}" + return + fi + + if ! is_backports_enabled; then + _msg "Backports Required" \ + "Trixie-backports is not enabled.\n\nEnable it first via:\n Main Menu → 3 → Configure Repositories" 12 65 + echo -e "${YELLOW}Skipping PipeWire from backports.${NC}" + return + fi + + if ! is_installed "pipewire-audio"; then + _run_cmd "PipeWire Backports" \ + "sudo apt install -y -t ${DEBIAN_CODENAME}-backports pipewire-audio" \ + "Installing PipeWire from trixie-backports (v1.4.9)..." + else + echo "pipewire-audio already installed." + fi +} diff --git a/modules/extras/system/software_centers.sh b/modules/extras/system/software_centers.sh index 3b3dda9..50d07e3 100644 --- a/modules/extras/system/software_centers.sh +++ b/modules/extras/system/software_centers.sh @@ -1,4 +1,4 @@ -# software_centers.sh — Standalone Software Center installer +# software_centers.sh — Standalone Software Center + Flatpak installer _cat_software_centers() { local headless=false @@ -7,46 +7,94 @@ _cat_software_centers() { echo "Software centers require a GUI — skipping." return fi + local de_type de_type=$(_detect_desktop_type) - local sc_choice - sc_choice=$(_menu "Software Centers" "Choose a software store to install:" 12 65 3 \ - "gnome-software" "Software Center for GNOME" \ - "plasma-discover" "Software manager for Plasma" \ - "synaptic" "Classic APT package manager (GTK)" \ - ) - [ -z "$sc_choice" ] && return - if [ "$sc_choice" = "synaptic" ]; then - _run_cmd "Install" "sudo apt install -y synaptic" "Installing synaptic..." - echo -e "${GREEN}synaptic installed.${NC}" - return - fi + local -a items=() + local gs_state; gs_state=$(_state "gnome-software") + local pd_state; pd_state=$(_state "plasma-discover") + local sy_state; sy_state=$(_state "synaptic") + local fp_state; fp_state=$(_state "flatpak") + items+=( + "gnome-software" "Software Center for GNOME" "$gs_state" + "plasma-discover" "Software manager for Plasma" "$pd_state" + "synaptic" "Classic APT package manager (GTK)" "$sy_state" + "flatpak" "Flatpak sandbox + Flathub" "$fp_state" + ) - if { [ "$de_type" = "qt" ] && [ "$sc_choice" = "gnome-software" ]; } || \ - { [ "$de_type" = "gtk" ] && [ "$sc_choice" = "plasma-discover" ]; }; then - _msg "Warning" "Warning: This store requires extra background libraries \ + local item_count=${#items[@]} + local lista_alto=$((item_count > TUI_ALTO_LISTA ? TUI_ALTO_LISTA : item_count)) + local choices + choices=$(_checklist "Software Center & Flatpak" \ + "Check [*] the packages you want installed.\n" \ + $TUI_ALTO $TUI_ANCHO $lista_alto "${items[@]}") + clear + [ -z "$choices" ] && return + + local cleaned; cleaned=$(echo "$choices" | tr -d '"') + + for pkg in $cleaned; do + case $pkg in + gnome-software) + if [ "$de_type" = "qt" ]; then + _msg "Warning" "Warning: This store requires extra background libraries \ and may look visually inconsistent with your current desktop environment." - ! _confirm "Continue?" "Install anyway?" && return - fi + ! _confirm "Continue?" "Install anyway?" && continue + fi + _run_cmd "Install" "sudo apt install -y gnome-software" "Installing GNOME Software..." + echo -e "${GREEN}gnome-software installed.${NC}" + ;; + plasma-discover) + if [ "$de_type" = "gtk" ]; then + _msg "Warning" "Warning: This store requires extra background libraries \ +and may look visually inconsistent with your current desktop environment." + ! _confirm "Continue?" "Install anyway?" && continue + fi + _run_cmd "Install" "sudo apt install -y plasma-discover" "Installing Plasma Discover..." + echo -e "${GREEN}plasma-discover installed.${NC}" + ;; + synaptic) + _run_cmd "Install" "sudo apt install -y synaptic" "Installing synaptic..." + echo -e "${GREEN}synaptic installed.${NC}" + ;; + flatpak) + if ! is_installed "flatpak"; then + _run_cmd "Flatpak" "sudo apt install -y flatpak" "Installing Flatpak..." + else + echo "Flatpak already installed." + fi + flatpak remote-add --if-not-exists flathub \ + https://dl.flathub.org/repo/flathub.flatpakrepo + echo "Flathub repository added." - _run_cmd "Install" "sudo apt install -y $sc_choice" "Installing ${sc_choice}..." + if command -v plasma-discover &>/dev/null; then + if ! is_installed "plasma-discover-backend-flatpak" 2>/dev/null; then + if _confirm "Discover Backend" "Install Flatpak backend for Plasma Discover?"; then + _run_cmd "Backend" "sudo apt install -y plasma-discover-backend-flatpak" "Installing Flatpak backend..." + fi + fi + elif command -v gnome-software &>/dev/null; then + if ! is_installed "gnome-software-plugin-flatpak" 2>/dev/null; then + if _confirm "GNOME Plugin" "Install Flatpak plugin for GNOME Software?"; then + _run_cmd "Plugin" "sudo apt install -y gnome-software-plugin-flatpak" "Installing Flatpak plugin..." + fi + fi + else + if [ "$de_type" = "qt" ]; then + if _confirm "Software Center" "Install Plasma Discover for Flatpak management?"; then + _run_cmd "Discover" "sudo apt install -y plasma-discover plasma-discover-backend-flatpak" "Installing Discover..." + fi + else + if _confirm "Software Center" "Install GNOME Software for Flatpak management?"; then + _run_cmd "GNOME Software" "sudo apt install -y gnome-software gnome-software-plugin-flatpak" "Installing GNOME Software..." + fi + fi + fi + echo -e "${GREEN}A reboot is recommended.${NC}" + ;; + esac + done - if _confirm "Flatpak Support" "Do you want to enable Flatpak support for this software center?"; then - local bpkg - if [ "$sc_choice" = "gnome-software" ]; then - bpkg="gnome-software-plugin-flatpak" - else - bpkg="plasma-discover-backend-flatpak" - fi - if ! is_installed "flatpak"; then - _run_cmd "Flatpak" "sudo apt install -y flatpak" "Installing Flatpak..." - fi - _run_cmd "Plugin" "sudo apt install -y $bpkg" "Installing $bpkg..." - flatpak remote-add --if-not-exists flathub \ - https://dl.flathub.org/repo/flathub.flatpakrepo - echo "Flathub repository added." - fi - - echo -e "${GREEN}Software store installed.${NC}" + echo -e "${GREEN}Software center & Flatpak setup complete.${NC}" } diff --git a/modules/extras/system/system.sh b/modules/extras/system/system.sh index e3491a6..f58f0fa 100644 --- a/modules/extras/system/system.sh +++ b/modules/extras/system/system.sh @@ -36,7 +36,6 @@ _cat_general() { curl_wget_state="OFF" fi local extrepo_state; extrepo_state=$(_state "extrepo") - local flatpak_state; flatpak_state=$(_state "flatpak") local fwupd_state; fwupd_state=$(_state "fwupd") local htop_state; htop_state=$(_state "htop") local inxi_state; inxi_state=$(_state "inxi") @@ -56,7 +55,6 @@ _cat_general() { "cpu-x" "CPU-X (alternative to CPU-Z)" "$cpu_x_state" "curl-wget" "HTTP transfer tools (curl, wget)" "$curl_wget_state" "extrepo" "External repository manager" "$extrepo_state" - "flatpak" "Flatpak sandbox + Flathub" "$flatpak_state" "fwupd" "Firmware update daemon" "$fwupd_state" "htop" "Interactive process viewer" "$htop_state" "inxi" "System information tool" "$inxi_state" @@ -137,43 +135,6 @@ _cat_general() { extrepo) install_backports_or_stable extrepo ;; - flatpak) - if ! is_installed "flatpak"; then - _run_cmd "Flatpak" "sudo apt install -y flatpak" "Installing Flatpak..." - else - echo "Flatpak already installed." - fi - flatpak remote-add --if-not-exists flathub \ - https://dl.flathub.org/repo/flathub.flatpakrepo - echo "Flathub repository added." - - if command -v plasma-discover &>/dev/null; then - if ! is_installed "plasma-discover-backend-flatpak" 2>/dev/null; then - if _confirm "Discover Backend" "Install Flatpak backend for Plasma Discover?"; then - _run_cmd "Backend" "sudo apt install -y plasma-discover-backend-flatpak" "Installing Flatpak backend..." - fi - fi - elif command -v gnome-software &>/dev/null; then - if ! is_installed "gnome-software-plugin-flatpak" 2>/dev/null; then - if _confirm "GNOME Plugin" "Install Flatpak plugin for GNOME Software?"; then - _run_cmd "Plugin" "sudo apt install -y gnome-software-plugin-flatpak" "Installing Flatpak plugin..." - fi - fi - else - local de_type - de_type=$(_detect_desktop_type) - if [ "$de_type" = "qt" ]; then - if _confirm "Software Center" "Install Plasma Discover for Flatpak management?"; then - _run_cmd "Discover" "sudo apt install -y plasma-discover plasma-discover-backend-flatpak" "Installing Discover..." - fi - else - if _confirm "Software Center" "Install GNOME Software for Flatpak management?"; then - _run_cmd "GNOME Software" "sudo apt install -y gnome-software gnome-software-plugin-flatpak" "Installing GNOME Software..." - fi - fi - fi - echo -e "${GREEN}A reboot is recommended.${NC}" - ;; fwupd) if ! is_installed "fwupd"; then _run_cmd "fwupd" "sudo apt install -y fwupd" "Installing fwupd..." diff --git a/modules/gpu/nvidia.sh b/modules/gpu/nvidia.sh index 58ce9c8..952f31c 100644 --- a/modules/gpu/nvidia.sh +++ b/modules/gpu/nvidia.sh @@ -139,7 +139,7 @@ _install_nvidia_bookworm_bpo() { nv_pkg="nvidia-tesla-470-driver" else local nd_ver - nd_ver=$(apt-cache policy nvidia-detect 2>/dev/null | awk 'NR==3 {print $2; exit}') + nd_ver=$(apt-cache policy nvidia-detect 2>/dev/null | awk 'NR==3 {print $2; exit}') || true if _confirm "NVIDIA Detect" "Install nvidia-detect to determine the correct driver?\n\n nvidia-detect ${nd_ver:-unknown}" 12 70; then _run_cmd "NVIDIA" "sudo apt install -y nvidia-detect" "Installing nvidia-detect..." else @@ -148,7 +148,7 @@ _install_nvidia_bookworm_bpo() { return 0 fi local recommended - recommended=$(nvidia-detect 2>/dev/null | grep -oP 'nvidia[\w-]+(?= package)') + recommended=$(nvidia-detect 2>/dev/null | grep -oP 'nvidia[\w-]+(?= package)') || true if [ -z "$recommended" ]; then echo -e "${RED}nvidia-detect could not determine a suitable driver.${NC}" return 1 @@ -161,7 +161,7 @@ _install_nvidia_bookworm_bpo() { fi local nv_ver - nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') + nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true local msg="Source: Debian Bookworm-Backports\n" msg+="NVIDIA Driver: ${nv_pkg} ${nv_ver:-unknown}\n" msg+=" (Compatible with Kernel v6.12+)\n" @@ -200,7 +200,7 @@ _install_nvidia_bookworm_bpo() { _install_nvidia_bookworm_kepler() { local nv_pkg="nvidia-legacy-470xx-driver" local nv_ver - nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') + nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true echo -e "${YELLOW}Kepler GPU detected — forcing ${nv_pkg}.${NC}" @@ -229,7 +229,7 @@ _install_nvidia_bookworm_kepler() { if [ "$(is_backports_enabled)" == "true" ]; then local bpo_ver bpo_ver=$(apt-cache madison "$nv_pkg" 2>/dev/null | \ - grep "bookworm-backports" | awk '{print $3}' | head -1) + grep "bookworm-backports" | awk '{print $3}' | head -1) || true if [ -n "$bpo_ver" ]; then local msg="Hay una versión en backports: ${bpo_ver}\n" msg+="Instalar desde bookworm-backports?" @@ -279,7 +279,7 @@ _install_nvidia_standard() { echo -e "${YELLOW}Kepler GPU detected. Will use ${nv_pkg}.${NC}" else local nd_ver - nd_ver=$(apt-cache policy nvidia-detect 2>/dev/null | awk 'NR==3 {print $2; exit}') + nd_ver=$(apt-cache policy nvidia-detect 2>/dev/null | awk 'NR==3 {print $2; exit}') || true if _confirm "NVIDIA Detect" "Install nvidia-detect to determine the correct driver?\n\n nvidia-detect ${nd_ver:-unknown}" 12 70; then _run_cmd "NVIDIA" "sudo apt install -y nvidia-detect" "Installing nvidia-detect..." else @@ -287,7 +287,7 @@ _install_nvidia_standard() { return 0 fi local recommended - recommended=$(nvidia-detect 2>/dev/null | grep -oP 'nvidia[\w-]+(?= package)') + recommended=$(nvidia-detect 2>/dev/null | grep -oP 'nvidia[\w-]+(?= package)') || true if [ -z "$recommended" ]; then echo -e "${RED}nvidia-detect could not determine a suitable driver.${NC}" return 1 @@ -301,11 +301,11 @@ _install_nvidia_standard() { # Check for backports (optional, if repo enabled) local stable_nv_ver - stable_nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') + stable_nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true if [ "$(is_backports_enabled)" == "true" ]; then local bpo_nv_ver bpo_nv_ver=$(apt-cache madison "$nv_pkg" 2>/dev/null | \ - grep "${DEBIAN_CODENAME}-backports" | awk '{print $3}' | head -1) + grep "${DEBIAN_CODENAME}-backports" | awk '{print $3}' | head -1) || true if [ -n "$bpo_nv_ver" ]; then local msg="Source: Debian ${DEBIAN_CODENAME^} (Backports available)\n" msg+="NVIDIA Driver: ${nv_pkg}\n\n" diff --git a/modules/sysinfo.sh b/modules/sysinfo.sh index e88fb91..6cb6f55 100644 --- a/modules/sysinfo.sh +++ b/modules/sysinfo.sh @@ -27,13 +27,13 @@ _show_sysinfo() { if echo "$gpu_line" | grep -qi "nvidia"; then local nv_ver="" - nv_ver=$(timeout 3 nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null | head -1) - [ -z "$nv_ver" ] && nv_ver=$(dpkg -l nvidia-driver 2>/dev/null | awk '/^ii/ {print $3}' | sed 's/-.*//') + nv_ver=$(timeout 3 nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null | head -1) || true + [ -z "$nv_ver" ] && nv_ver=$(dpkg -l nvidia-driver 2>/dev/null | awk '/^ii/ {print $3}' | sed 's/-.*//') || true msg+="GPU ${gpu_count}: ${desc}\n" msg+=" Driver: ${nv_ver:+NVIDIA }${nv_ver:-not installed}\n" else local mesa_ver="" - mesa_ver=$(dpkg -l libgl1-mesa-dri 2>/dev/null | awk '/^ii/ {print $3; exit}' | sed 's/-.*//') + mesa_ver=$(dpkg -l libgl1-mesa-dri 2>/dev/null | awk '/^ii/ {print $3; exit}' | sed 's/-.*//') || true msg+="GPU ${gpu_count}: ${desc}\n" msg+=" Driver: ${mesa_ver:+Mesa }${mesa_ver:-unknown}\n" fi @@ -99,6 +99,8 @@ _show_sysinfo() { local -a shown_eth_descs=() local -a shown_wifi_descs=() local has_eth=false has_wifi=false has_other=false + local eth_idx=0 + local wifi_idx=0 if ! command -v ip &>/dev/null; then msg+="(install iproute2 for interface details)\n" @@ -121,13 +123,15 @@ _show_sysinfo() { case "$pci_class" in 0x0200*) has_eth=true - desc="${eth_descs[0]:-Unknown Ethernet chipset}" - shown_eth_descs+=("${eth_descs[0]}") + desc="${eth_descs[$eth_idx]:-Unknown Ethernet chipset}" + shown_eth_descs+=("${eth_descs[$eth_idx]:-$desc}") + eth_idx=$((eth_idx + 1)) ;; 0x0280*) has_wifi=true - desc="${wifi_descs[0]:-Unknown WiFi chipset}" - shown_wifi_descs+=("${wifi_descs[0]}") + desc="${wifi_descs[$wifi_idx]:-Unknown WiFi chipset}" + shown_wifi_descs+=("${wifi_descs[$wifi_idx]:-$desc}") + wifi_idx=$((wifi_idx + 1)) ssid="" [ "$state" = "UP" ] && ssid=$(timeout 2 iwgetid -r "$iface" 2>/dev/null || true) ;; @@ -136,15 +140,17 @@ _show_sysinfo() { case "$iface" in wl*|wlp*|wlo*|wlan*) has_wifi=true - desc="${wifi_descs[0]:-Unknown WiFi chipset}" - shown_wifi_descs+=("${wifi_descs[0]}") + desc="${wifi_descs[$wifi_idx]:-Unknown WiFi chipset}" + shown_wifi_descs+=("${wifi_descs[$wifi_idx]:-$desc}") + wifi_idx=$((wifi_idx + 1)) ssid="" [ "$state" = "UP" ] && ssid=$(timeout 2 iwgetid -r "$iface" 2>/dev/null || true) ;; eth*|enp*|ens*|enx*|eno*) has_eth=true - desc="${eth_descs[0]:-Unknown Ethernet chipset}" - shown_eth_descs+=("${eth_descs[0]}") + desc="${eth_descs[$eth_idx]:-Unknown Ethernet chipset}" + shown_eth_descs+=("${eth_descs[$eth_idx]:-$desc}") + eth_idx=$((eth_idx + 1)) ;; *) has_other=true @@ -233,7 +239,8 @@ _show_sysinfo() { local lines lines=$(echo -e "$truncated" | wc -l) local height=$(( lines + 6 )) - [ "$height" -gt 22 ] && height=22 + local max_height=$(( ${LINES:-24} - 4 > 10 ? ${LINES:-24} - 4 : 10 )) + [ "$height" -gt "$max_height" ] && height=$max_height [ "$height" -lt 10 ] && height=10 _msg "System Information" "$truncated" "$height" "$width" diff --git a/modules/utils.sh b/modules/utils.sh index 110b651..3e6eb9a 100644 --- a/modules/utils.sh +++ b/modules/utils.sh @@ -93,6 +93,45 @@ sync_system_time() { fi } +# ------------------------------------------------------------------- +# Robust time sync: NTP + timezone validation + service restart +# ------------------------------------------------------------------- +_ensure_time_synced() { + command -v timedatectl &>/dev/null || return + + # ── Paso 1: Forzar NTP activo ── + sudo timedatectl set-ntp true --no-ask-password 2>/dev/null || true + + # ── Paso 2: Validar zona horaria ── + local tz + tz=$(timedatectl show -p Timezone --value 2>/dev/null || echo "") + if [ -z "$tz" ] || [ "$tz" = "n/a" ] || [ "$tz" = "Etc/UTC" ]; then + if [ -n "${DISPLAY:-}" ] || [ -n "${SSH_TTY:-}" ]; then + _msg "Timezone" \ + "Your system timezone is not set or is set to UTC.\n\nThe script will now open the timezone\nconfiguration tool to set your local timezone." 12 60 + sudo dpkg-reconfigure tzdata + echo -e "${GREEN}Timezone configured: $(timedatectl show -p Timezone --value 2>/dev/null)${NC}" + else + echo -e "${YELLOW}Timezone not set. Run 'sudo dpkg-reconfigure tzdata' later.${NC}" + fi + fi + + # ── Paso 3: Instalar/asegurar systemd-timesyncd ── + if ! is_installed systemd-timesyncd; then + sudo DEBIAN_FRONTEND=noninteractive apt install -y systemd-timesyncd || true + fi + sudo systemctl enable systemd-timesyncd 2>/dev/null || true + sudo systemctl restart systemd-timesyncd 2>/dev/null || true + + # ── Paso 4: Verificar resultado ── + sleep 2 + if timedatectl show --property=NTPSynchronized --value 2>/dev/null | grep -q yes; then + echo -e "${GREEN}Time synchronized: $(date '+%Y-%m-%d %H:%M')${NC}" + else + echo -e "${YELLOW}NTP sync did not complete yet (may need a moment).${NC}" + fi +} + # -------------------------------- # Debian version detection # --------------------------------