fix(tui): fix whiptail dialog progression, output descriptor handling and terminal scaling

Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
2026-09-06 16:54:17 +02:00
co-authored by Junie
parent 2f02c1b74a
commit 174014cae0
3 changed files with 107 additions and 35 deletions
+3 -4
View File
@@ -59,7 +59,7 @@ trap cleanup EXIT INT TERM
main() {
local repo_url="${REPO_URL:-https://gitea.creative-dragonslayer.de/Scripts/Setup.git}"
local repo_branch="${REPO_BRANCH:-}"
local repo_branch="${REPO_BRANCH:-dev}"
log_step "Debian Unstable & Hyprland Setup Framework Installer"
log_info "Repository: $repo_url ${repo_branch:+(Branch: $repo_branch)}"
@@ -132,10 +132,9 @@ main() {
# Reconnect stdin to /dev/tty if stdin is currently piped and /dev/tty is accessible (for interactive prompts/TUI)
if [[ ! -t 0 ]] && [[ -e /dev/tty ]] && ( : < /dev/tty ) 2>/dev/null; then
"${setup_cmd[@]}" < /dev/tty
else
"${setup_cmd[@]}"
exec < /dev/tty
fi
"${setup_cmd[@]}"
}
main "$@"
+93 -23
View File
@@ -15,18 +15,51 @@ tui_check_whiptail() {
# Display welcome message
tui_welcome() {
local term_lines
term_lines=$(tput lines 2>/dev/null || echo 24)
local term_cols
term_cols=$(tput cols 2>/dev/null || echo 80)
local height=14
local width=70
if (( term_lines < 16 )); then
height=$(( term_lines - 2 > 8 ? term_lines - 2 : 8 ))
fi
if (( term_cols < 72 )); then
width=$(( term_cols - 4 > 40 ? term_cols - 4 : 40 ))
fi
whiptail --title "Debian Unstable Setup & Hyprland Installer" \
--msgbox "Willkommen beim Debian Unstable & Desktop Setup!\n\nDieses Skript führt dich durch die modulare Einrichtung deines Debian Sid Systems mit XanMod-Kernel, Hyprland und Optimierungen.\n\nDrücke ENTER um zur Modulauswahl zu gelangen." \
14 70
"$height" "$width" || true
}
# Present stage checklist to user
# Returns space-separated list of selected stage numbers (e.g., "01 02 03 04 05 06 07 08 09")
# Sets TUI_SELECTION and returns 0 on success, 1 on cancel
tui_select_stages() {
local choices
choices=$(whiptail --title "Modulauswahl / Stages" \
local tmp_file
tmp_file="$(mktemp)"
local term_lines
term_lines=$(tput lines 2>/dev/null || echo 24)
local term_cols
term_cols=$(tput cols 2>/dev/null || echo 80)
local height=20
local width=74
local list_height=10
if (( term_lines < 22 )); then
height=$(( term_lines - 2 > 12 ? term_lines - 2 : 12 ))
list_height=$(( height - 8 > 4 ? height - 8 : 4 ))
fi
if (( term_cols < 76 )); then
width=$(( term_cols - 4 > 40 ? term_cols - 4 : 40 ))
fi
if whiptail --output-fd 3 --title "Modulauswahl / Stages" \
--checklist "Wähle die gewünschten Installations-Phasen mit der LEERTASTE aus:" \
23 78 10 \
"$height" "$width" "$list_height" \
"01" "Debian Unstable (Deb822, Pinning, Upgrade)" ON \
"02" "Kernel & Hardware (XanMod, P-State, Microcode)" ON \
"03" "Bootloader & Theme (GRUB, Vimix, Plymouth)" ON \
@@ -37,15 +70,18 @@ tui_select_stages() {
"08" "Flatpaks (Flathub Repository & Flatpaks)" ON \
"09" "Zusatz-Apps & MIME (Spotify, Waydroid, OpenDeck, MIME)" ON \
"10" "Hyprland Desktop (LinuxBeginnings Debian-Hyprland Installer)" ON \
3>&1 1>&2 2>&3) || {
log_info "Setup durch Benutzer abgebrochen."
exit 0
}
3> "$tmp_file"; then
# Clean quotes from whiptail output (e.g. '"01" "02"' -> '01 02')
local cleaned_choices
cleaned_choices=$(echo "$choices" | tr -d '"')
echo "$cleaned_choices"
TUI_SELECTION="$(tr -d '"' < "$tmp_file")"
export TUI_SELECTION
rm -f "$tmp_file"
return 0
else
rm -f "$tmp_file"
TUI_SELECTION=""
export TUI_SELECTION
return 1
fi
}
# Prompt user for target user via Whiptail dialog
@@ -53,6 +89,19 @@ tui_prompt_target_user() {
local default_user="${1:-}"
local chosen=""
# Detect candidate user if not provided or root
if [[ -z "$default_user" || "$default_user" == "root" ]]; then
if [[ -n "${SUDO_USER:-}" && "${SUDO_USER}" != "root" ]]; then
default_user="$SUDO_USER"
elif [[ -n "${PKEXEC_UID:-}" ]]; then
default_user="$(id -nu "$PKEXEC_UID" 2>/dev/null || true)"
elif [[ "$(id -u)" -ne 0 ]]; then
default_user="$(id -un)"
else
default_user="$(awk -F: '$3 >= 1000 && $3 < 60000 && $1 != "nobody" {print $1; exit}' /etc/passwd 2>/dev/null || true)"
fi
fi
if [[ -n "$default_user" && "$default_user" != "root" ]]; then
if whiptail --title "Ziel-Benutzer bestätigen" \
--yes-button "Verwenden" \
@@ -63,27 +112,34 @@ tui_prompt_target_user() {
fi
fi
local tmp_file
tmp_file="$(mktemp)"
while [[ -z "$chosen" ]]; do
local input_user
input_user=$(whiptail --title "Ziel-Benutzer eingeben" \
if whiptail --output-fd 3 --title "Ziel-Benutzer eingeben" \
--inputbox "Bitte gib den Benutzernamen des Desktop-Benutzers ein:" \
10 60 "$default_user" \
3>&1 1>&2 2>&3) || {
log_info "Setup durch Benutzer abgebrochen."
exit 0
}
input_user="$(echo "$input_user" | tr -d '[:space:]')"
3> "$tmp_file"; then
local input_user
input_user="$(tr -d '[:space:]' < "$tmp_file")"
if [[ -z "$input_user" || "$input_user" == "root" ]]; then
whiptail --title "Ungültiger Benutzer" --msgbox "Ungültiger Benutzername (darf nicht leer oder root sein)." 8 50
whiptail --title "Ungültiger Benutzer" --msgbox "Ungültiger Benutzername (darf nicht leer oder root sein)." 8 55
continue
fi
if ! id "$input_user" >/dev/null 2>&1; then
whiptail --title "Benutzer nicht gefunden" --msgbox "Benutzer '$input_user' existiert nicht im System." 8 50
whiptail --title "Benutzer nicht gefunden" --msgbox "Benutzer '$input_user' existiert nicht im System." 8 55
continue
fi
chosen="$input_user"
else
rm -f "$tmp_file"
log_info "Setup durch Benutzer abgebrochen."
exit 0
fi
done
rm -f "$tmp_file"
export TARGET_USER="$chosen"
}
@@ -92,7 +148,21 @@ tui_confirm_execution() {
local selected_stages="$1"
local target_user="$2"
local term_lines
term_lines=$(tput lines 2>/dev/null || echo 24)
local term_cols
term_cols=$(tput cols 2>/dev/null || echo 80)
local height=14
local width=70
if (( term_lines < 16 )); then
height=$(( term_lines - 2 > 10 ? term_lines - 2 : 10 ))
fi
if (( term_cols < 72 )); then
width=$(( term_cols - 4 > 40 ? term_cols - 4 : 40 ))
fi
whiptail --title "Installation starten" \
--yesno "Folgende Konfiguration wird ausgeführt:\n\n- Ziel-Benutzer: $target_user\n- Ausgewählte Stages: $selected_stages\n\nMöchtest du die Installation jetzt starten?" \
14 70
"$height" "$width"
}
+5 -2
View File
@@ -133,9 +133,12 @@ else
if [[ -t 0 && -t 1 ]]; then
tui_check_whiptail
tui_welcome
TUI_SELECTION=$(tui_select_stages)
if ! tui_select_stages; then
log_info "Setup aborted by user."
exit 0
fi
if [[ -z "$TUI_SELECTION" ]]; then
if [[ -z "${TUI_SELECTION:-}" ]]; then
log_warn "No stages selected. Exiting."
exit 0
fi