From 600e73900576a28c446cb3c9732daea9be72a2f3 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 15 Sep 2025 11:19:52 +0200 Subject: [PATCH] Refactor pv installation into ensure_pv function (#7642) Moved pv installation logic into a reusable ensure_pv function in both haos-vm.sh and umbrel-os-vm.sh. This improves code clarity and avoids duplicate code for checking and installing the pv package. --- vm/haos-vm.sh | 15 ++++++++++----- vm/umbrel-os-vm.sh | 14 ++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/vm/haos-vm.sh b/vm/haos-vm.sh index 30c71efbc..6789696d2 100644 --- a/vm/haos-vm.sh +++ b/vm/haos-vm.sh @@ -205,6 +205,15 @@ function exit-script() { exit } +function ensure_pv() { + if ! command -v pv &>/dev/null; then + msg_info "Installing required package: pv" + apt-get update -qq &>/dev/null + apt-get install -y pv &>/dev/null + msg_ok "Installed pv" + fi +} + function default_settings() { BRANCH="$stable" VMID=$(get_valid_nextid) @@ -448,8 +457,8 @@ check_root arch_check pve_check ssh_check +ensure_pv start_script - post_to_api_vm msg_info "Validating Storage" @@ -505,10 +514,6 @@ else msg_ok "Using cached image ${CL}${BL}$(basename "$CACHE_FILE")${CL}" fi -if ! command -v pv &>/dev/null; then - apt-get update -qq &>/dev/null && apt-get install -y pv &>/dev/null -fi - set -o pipefail msg_info "Creating Home Assistant OS VM shell" qm create "$VMID" -machine q35 -bios ovmf -agent 1 -tablet 0 -localtime 1 ${CPU_TYPE} \ diff --git a/vm/umbrel-os-vm.sh b/vm/umbrel-os-vm.sh index 6d232dcf4..8ff15620b 100644 --- a/vm/umbrel-os-vm.sh +++ b/vm/umbrel-os-vm.sh @@ -201,6 +201,15 @@ function exit-script() { exit } +function ensure_pv() { + if ! command -v pv &>/dev/null; then + msg_info "Installing required package: pv" + apt-get update -qq &>/dev/null + apt-get install -y pv &>/dev/null + msg_ok "Installed pv" + fi +} + function default_settings() { VMID=$(get_valid_nextid) MACHINE="q35" @@ -432,6 +441,7 @@ check_root arch_check pve_check ssh_check +ensure_pv start_script msg_info "Validating Storage" @@ -472,10 +482,6 @@ else msg_ok "Using cached Umbrel OS image" fi -if ! command -v pv &>/dev/null; then - apt-get update -qq &>/dev/null && apt-get install -y pv &>/dev/null -fi - set -o pipefail qm create "$VMID" -machine q35 -bios ovmf -agent 1 -tablet 0 -localtime 1 ${CPU_TYPE} \ -cores "$CORE_COUNT" -memory "$RAM_SIZE" -name "$HN" -tags community-script \