mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-02 10:52:22 +00:00
fix(update): confirm with Yes focused and keep the package list aligned
This commit is contained in:
@@ -445,19 +445,68 @@ cleanup_duplicate_repos() {
|
||||
# an operator reads the log days later to find out what moved.
|
||||
|
||||
# Reads `apt list --upgradable` on stdin and writes one aligned
|
||||
# `name old → new` line per package. Lines that do not carry the
|
||||
# `name old → new` line per package, never wider than the dialog that
|
||||
# shows it (70 columns by default): a package whose versions do not fit
|
||||
# continues on indented lines. Lines that do not carry the
|
||||
# "[upgradable from: …]" part are passed through as they came.
|
||||
pmx_format_upgradable() {
|
||||
awk 'NF == 0 { next }
|
||||
awk -v width="${1:-70}" 'NF == 0 { next }
|
||||
$0 ~ /\[upgradable from: / {
|
||||
name = $1; sub(/\/.*/, "", name)
|
||||
from = $6; sub(/\]$/, "", from)
|
||||
printf " %-30s %s → %s\n", name, from, $2
|
||||
# Widths are counted by hand: " → " is three columns but more
|
||||
# bytes, and mawk measures bytes.
|
||||
if (2 + 30 + 1 + length(from) + 3 + length($2) <= width && length(name) <= 30)
|
||||
printf " %-30s %s → %s\n", name, from, $2
|
||||
else if (6 + length(from) + 3 + length($2) <= width)
|
||||
printf " %s\n %s → %s\n", name, from, $2
|
||||
else
|
||||
printf " %s\n %s\n → %s\n", name, from, $2
|
||||
next
|
||||
}
|
||||
{ print " " $0 }'
|
||||
}
|
||||
|
||||
# Asks whether to go ahead with an update, with Yes focused so Enter
|
||||
# confirms. whiptail cannot focus a button while its text scrolls, so the
|
||||
# box takes the height of the terminal and a list that does not fit ends
|
||||
# with a line counting the packages left out; the update log keeps them all.
|
||||
#
|
||||
# pmx_confirm_update TITLE TEXT LIST QUESTION
|
||||
pmx_confirm_update() {
|
||||
local title="$1" text="$2" list="$3" question="$4"
|
||||
local rows height room shown more
|
||||
rows=$(tput lines 2>/dev/null)
|
||||
[[ "$rows" =~ ^[0-9]+$ ]] || rows=24
|
||||
height=$(( rows > 50 ? 48 : rows - 2 ))
|
||||
(( height < 16 )) && height=16
|
||||
# Frame, padding, the heading, the question and the buttons.
|
||||
room=$(( height - 9 - $(printf '%b' "$text" | grep -c '') ))
|
||||
(( room < 3 )) && room=3
|
||||
|
||||
# A package that spans several lines is shown whole or counted.
|
||||
shown=$(printf '%s\n' "$list" | awk -v room="$room" '
|
||||
/^ [^ ]/ { package++ }
|
||||
{ lines[NR] = $0; owner[NR] = package }
|
||||
END {
|
||||
if (NR <= room) { for (i = 1; i <= NR; i++) print lines[i]; exit }
|
||||
# One line is kept for the count of the packages left out.
|
||||
cap = room - 1
|
||||
last = owner[cap]
|
||||
if (owner[cap + 1] == last) last--
|
||||
for (i = 1; i <= NR && owner[i] <= last; i++) print lines[i]
|
||||
printf "\n%d\n", package - last
|
||||
}')
|
||||
more="${shown##*$'\n'}"
|
||||
if [[ "$shown" == *$'\n\n'"$more" && "$more" =~ ^[0-9]+$ ]]; then
|
||||
shown="${shown%$'\n\n'"$more"}"
|
||||
shown+="\n … ${more} $(translate "more packages; the full list is in the update log")"
|
||||
fi
|
||||
|
||||
whiptail --title "$title" --yesno \
|
||||
"${text}$(translate "Packages to be upgraded"):\n${shown}\n\n${question}" "$height" 78
|
||||
}
|
||||
|
||||
# Writes what dpkg actually did since `$1` (a "YYYY-MM-DD HH:MM:SS"
|
||||
# stamp taken before the upgrade). dpkg's own log is the authoritative
|
||||
# record of the transaction — it carries both versions of every package
|
||||
|
||||
@@ -110,10 +110,9 @@ update_pbs() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
menu_text+="$(translate "Packages to be upgraded"):\n$upgradable_list\n\n"
|
||||
menu_text+="$(translate "Do you want to proceed with the system update?")"
|
||||
local proceed=0
|
||||
whiptail --title "$(translate "Proxmox Backup Server Update")" --scrolltext --yesno "$menu_text" 24 78 || proceed=1
|
||||
pmx_confirm_update "$(translate "Proxmox Backup Server Update")" "$menu_text" "$upgradable_list" \
|
||||
"$(translate "Do you want to proceed with the system update?")" || proceed=1
|
||||
|
||||
clear
|
||||
show_proxmenux_logo
|
||||
|
||||
@@ -205,12 +205,9 @@ update_pve_safe() {
|
||||
fi
|
||||
|
||||
# The package list rides in the same dialog as the summary, so the
|
||||
# decision is taken knowing what is about to be replaced. Keep Yes focused
|
||||
# while the list remains scrollable; --keep-tite restores the execution screen.
|
||||
menu_text+="$(translate "Packages to be upgraded"):\n$upgradable_list\n\n"
|
||||
menu_text+="$(translate "Do you want to proceed with the system update?")"
|
||||
if ! dialog --keep-tite --title "$(translate "Proxmox Update")" \
|
||||
--default-button yes --no-collapse --scrollbar --yesno "$menu_text" 24 78; then
|
||||
# decision is taken knowing what is about to be replaced.
|
||||
if ! pmx_confirm_update "$(translate "Proxmox Update")" "$menu_text" "$upgradable_list" \
|
||||
"$(translate "Do you want to proceed with the system update?")"; then
|
||||
msg_info2 "$(translate "Update cancelled by user")"
|
||||
apt-get -y autoremove >/dev/null 2>&1 || true
|
||||
apt-get -y autoclean >/dev/null 2>&1 || true
|
||||
|
||||
@@ -169,12 +169,8 @@ EOF
|
||||
else
|
||||
# The package list rides in the same dialog as the summary, so
|
||||
# the decision is taken knowing what is about to be replaced.
|
||||
# Keep Yes focused while the full package list remains scrollable.
|
||||
# --keep-tite restores the execution screen after confirmation.
|
||||
menu_text+="$(translate "Packages to be upgraded"):\n$upgradable_list\n\n"
|
||||
menu_text+="$(translate "Do you want to proceed with the system update?")"
|
||||
if dialog --keep-tite --title "$(translate "Proxmox Update")" \
|
||||
--default-button yes --no-collapse --scrollbar --yesno "$menu_text" 24 78; then
|
||||
if pmx_confirm_update "$(translate "Proxmox Update")" "$menu_text" "$upgradable_list" \
|
||||
"$(translate "Do you want to proceed with the system update?")"; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
|
||||
@@ -272,12 +272,8 @@ EOF
|
||||
else
|
||||
# The package list rides in the same dialog as the summary, so
|
||||
# the decision is taken knowing what is about to be replaced.
|
||||
# Keep Yes focused while the full package list remains scrollable.
|
||||
# --keep-tite restores the execution screen after confirmation.
|
||||
menu_text+="$(translate "Packages to be upgraded"):\n$upgradable_list\n\n"
|
||||
menu_text+="$(translate "Do you want to proceed with the system update?")"
|
||||
if dialog --keep-tite --title "$(translate "Proxmox Update")" \
|
||||
--default-button yes --no-collapse --scrollbar --yesno "$menu_text" 24 78; then
|
||||
if pmx_confirm_update "$(translate "Proxmox Update")" "$menu_text" "$upgradable_list" \
|
||||
"$(translate "Do you want to proceed with the system update?")"; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user