Quiet dnf transactions: spinner + one-line summary, log on failure

ui_quiet_run wraps every install_packages/install_optional/group
install/remove and the system update: while gum is available and the
run is interactive, dnf output is hidden behind a spinner, then a
single 'Installing: <pkgs> (N packages)' line. Full output is appended
to $SETUP_DNF_LOG (/tmp/fedora-setup-dnf-<uid>.log); on failure the
last 20 lines print in red so nothing is lost. Unattended and no-gum
runs keep plain full output (logs/cron contract).

Also: fallback ui_choose accepts 'x' to exit (muscle memory from the
old menu), fixed a stray stdout newline leaking into captured answers
(same class as the earlier '\nno' bug), fixed pluralization.

Harness: piped fallback, pty gum run incl. a failing VirtualBox pick
(red failure + log tail, menu survives, subsequent qemu install ok),
unattended regression.
This commit is contained in:
Pathfinder
2026-10-27 19:20:31 +01:00
parent c6e41cbf1e
commit 9dd1ecada8
3 changed files with 63 additions and 19 deletions
+7 -11
View File
@@ -16,16 +16,7 @@ if [[ -n "${_SB_UI_LOADED:-}" ]]; then
fi
_SB_UI_LOADED=1
have_gum() {
command -v gum >/dev/null 2>&1 || return 1
# stdin must be interactive — it is inherited by $(...) subshells, so
# menus still get the real terminal. stdout must NOT be checked: it is
# a pipe by definition inside $(ui_choose ...). gum draws its UI on
# /dev/tty and prints only the answer to stdout (which we capture).
[ -t 0 ] || return 1
[ -w /dev/tty ] || return 1
return 0
}
# have_gum lives in lib/common.sh (install_packages needs it too).
# Single choice from a list.
# ui_choose "<header>" "<prompt>" "<default>" item1 item2 ...
@@ -62,7 +53,8 @@ ui_choose() {
local n=${#items[@]} answer
while true; do
if ! read -t 90 -rp "$prompt [1-$n] (default: shown above): " answer; then
printf "\n"; answer=""
printf "\n" >&2
answer=""
fi
# empty/timeout -> the default item (its position in the list)
if [[ -z "$answer" ]]; then
@@ -74,6 +66,10 @@ ui_choose() {
echo "${items[-1]}"
return 0
fi
if [[ "${answer,,}" == "x" ]]; then
echo "$default"
return 0
fi
if [[ "$answer" =~ ^[0-9]+$ ]] && (( answer >= 1 && answer <= n )); then
echo "${items[$((answer-1))]}"
return 0