Refactor pv installation into ensure_pv function

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.
This commit is contained in:
CanbiZ 2025-09-15 08:59:55 +02:00
parent 34b1d70762
commit d9c602696e
2 changed files with 20 additions and 9 deletions

View file

@ -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} \

View file

@ -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 \