From 868b40508228e5860a3c4acce17b7f8893650952 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Fri, 26 Jun 2026 21:56:23 +0200 Subject: [PATCH] Fix clean-lxcs exclude matching and set -e cancel handling (#15413) - Replace the array-style exclude check (`${excluded_containers[@]}` on a plain string) with an explicit per-VMID loop, resolving the ShellCheck SC2199/SC2076 errors and avoiding accidental substring matches. - Abort cleanly when the checklist dialog is cancelled instead of relying on an unreachable `$?` test under `set -eEuo pipefail`. - Exit gracefully on a declined confirmation prompt. - Use `pct exec ... -- hostname` for consistent argument handling. --- tools/pve/clean-lxcs.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/pve/clean-lxcs.sh b/tools/pve/clean-lxcs.sh index 9702c1ca5..a4a9567e1 100644 --- a/tools/pve/clean-lxcs.sh +++ b/tools/pve/clean-lxcs.sh @@ -30,7 +30,7 @@ declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "clean-lxcs" " header_info echo "Loading..." -whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE LXC Updater" --yesno "This will clean logs, cache and update package lists on selected LXC Containers. Proceed?" 10 58 +whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE LXC Updater" --yesno "This will clean logs, cache and update package lists on selected LXC Containers. Proceed?" 10 58 || exit 0 NODE=$(hostname) EXCLUDE_MENU=() @@ -42,17 +42,17 @@ while read -r TAG ITEM; do EXCLUDE_MENU+=("$TAG" "$ITEM " "OFF") done < <(pct list | awk 'NR>1') -excluded_containers=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --checklist "\nSelect containers to skip from cleaning:\n" \ - 16 $((MSG_MAX_LENGTH + 23)) 6 "${EXCLUDE_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') - -if [ $? -ne 0 ]; then - exit +# Capture the selection; abort cleanly if the user cancels the dialog +# (set -e would otherwise terminate on the failing command substitution). +if ! excluded_containers=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --checklist "\nSelect containers to skip from cleaning:\n" \ + 16 $((MSG_MAX_LENGTH + 23)) 6 "${EXCLUDE_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"'); then + exit 0 fi function run_lxc_clean() { local container=$1 header_info - name=$(pct exec "$container" hostname) + name=$(pct exec "$container" -- hostname) pct exec "$container" -- bash -c ' BL="\033[36m"; GN="\033[1;92m"; CL="\033[m" @@ -84,7 +84,14 @@ function run_lxc_clean() { } for container in $(pct list | awk '{if(NR>1) print $1}'); do - if [[ " ${excluded_containers[@]} " =~ " $container " ]]; then + excluded=0 + for ex in $excluded_containers; do + if [[ "$ex" == "$container" ]]; then + excluded=1 + break + fi + done + if [[ "$excluded" -eq 1 ]]; then header_info echo -e "${BL}[Info]${GN} Skipping ${BL}$container${CL}" sleep 1