From 9c5dee7500a6e1ebac3d1437b205b21b8aa77fac Mon Sep 17 00:00:00 2001 From: MickLesk <47820557+MickLesk@users.noreply.github.com> Date: Tue, 15 Sep 2026 11:51:06 +0200 Subject: [PATCH 1/2] Add vm_extract_image, which two VM scripts already call haos-vm and opnsense-vm were switched over to it, but it was never added here, so both died with "vm_extract_image: command not found" right after creating the VM shell. Takes the format from the file name and leaves the archive in place, so a cached download survives. Without a target the image lands in the tmp dir with the suffix removed, and VM_IMAGE_FILE names the result either way. --- pve/vm-core.func | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pve/vm-core.func b/pve/vm-core.func index a533663..889d254 100644 --- a/pve/vm-core.func +++ b/pve/vm-core.func @@ -1711,6 +1711,57 @@ _vm_root_fs() { ' | sort -rn | head -1 } +# Unpack a downloaded image; the format comes from the file name. Without a +# target it lands in the tmp dir with the suffix removed. Sets VM_IMAGE_FILE +# and leaves the archive alone, so a cached download survives. +vm_extract_image() { + local src="${1:?image}" target="${2:-}" tool rc + + if [[ ! -r "$src" ]]; then + msg_error "Cannot read ${src}" + return 1 + fi + + case "$src" in + *.xz) tool=xz ;; + *.gz) tool=gzip ;; + *.bz2) tool=bzip2 ;; + *.zst) tool=zstd ;; + *) + VM_IMAGE_FILE="$src" + return 0 + ;; + esac + + if ! command -v "$tool" >/dev/null 2>&1; then + msg_error "${tool} is needed to unpack $(basename "$src")" + return 1 + fi + + [[ -n "$target" ]] || target="${VM_IMAGE_TMP_DIR:-/var/lib/vz/template/tmp}/$(basename "${src%.*}")" + mkdir -p "$(dirname "$target")" + + msg_info "Extracting $(basename "$src")" + if command -v pv >/dev/null 2>&1; then + # pv draws its own progress, so the spinner has to go first. + stop_spinner 2>/dev/null || true + "$tool" -dc "$src" | pv -N Extracting >"$target" + rc=${PIPESTATUS[0]} + else + "$tool" -dc "$src" >"$target" + rc=$? + fi + + if ((rc != 0)); then + rm -f "$target" + msg_error "Failed to unpack $(basename "$src")" + return 1 + fi + + msg_ok "Extracted ${CL}${BL}$(basename "$target")${CL}" + VM_IMAGE_FILE="$target" +} + vm_expand_image() { local src="${1:?image}" size="${2:?size}" part out before after From 92abc5ca2ed3d98172a68c5e96c7eddcf91fe6b7 Mon Sep 17 00:00:00 2001 From: MickLesk <47820557+MickLesk@users.noreply.github.com> Date: Tue, 15 Sep 2026 11:52:06 +0200 Subject: [PATCH 2/2] Export VM_IMAGE_FILE; the callers read it --- pve/vm-core.func | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pve/vm-core.func b/pve/vm-core.func index 889d254..eee353e 100644 --- a/pve/vm-core.func +++ b/pve/vm-core.func @@ -1759,7 +1759,7 @@ vm_extract_image() { fi msg_ok "Extracted ${CL}${BL}$(basename "$target")${CL}" - VM_IMAGE_FILE="$target" + export VM_IMAGE_FILE="$target" } vm_expand_image() {