Use specific exit codes in VM scripts

Replace generic exit 1 with distinct exit codes across vm/*.sh to make failures more actionable for callers. Changes include: use 226 for missing imported-disk references, 237 for pv installation failures, 115 for download/extract/ISO-related failures, 214 for insufficient disk space during FreeBSD decompression, and 119 for missing storage detection. Updated scripts: archlinux-vm.sh, docker-vm.sh, haos-vm.sh, openwrt-vm.sh, opnsense-vm.sh, truenas-vm.sh, umbrel-os-vm.sh.
This commit is contained in:
CanbiZ (MickLesk)
2026-03-02 10:18:44 +01:00
parent 592f0d1f53
commit 55ebf5cd90
7 changed files with 20 additions and 20 deletions

View File

@@ -513,7 +513,7 @@ DISK_REF_IMPORTED="$(printf '%s\n' "$IMPORT_OUT" | sed -n "s/.*successfully impo
[[ -z "$DISK_REF_IMPORTED" ]] && {
msg_error "Unable to determine imported disk reference."
echo "$IMPORT_OUT"
exit 1
exit 226
}
msg_ok "Imported disk (${CL}${BL}${DISK_REF_IMPORTED}${CL})"

View File

@@ -638,7 +638,7 @@ DISK_REF_IMPORTED="$(printf '%s\n' "$IMPORT_OUT" | sed -n "s/.*successfully impo
[[ -z "$DISK_REF_IMPORTED" ]] && {
msg_error "Unable to determine imported disk reference."
echo "$IMPORT_OUT"
exit 1
exit 226
}
msg_ok "Imported disk (${CL}${BL}${DISK_REF_IMPORTED}${CL})"

View File

@@ -221,7 +221,7 @@ function ensure_pv() {
if ! apt-get update -qq &>/dev/null || ! apt-get install -y pv &>/dev/null; then
msg_error "Failed to install pv automatically."
echo -e "\nPlease run manually on the Proxmox host:\n apt install pv\n"
exit 1
exit 237
fi
msg_ok "Installed pv"
fi
@@ -249,14 +249,14 @@ function download_and_validate_xz() {
if ! curl -fSL -o "$file" "$url"; then
msg_error "Download failed: $url"
rm -f "$file"
exit 1
exit 115
fi
# Validate again
if ! xz -t "$file" &>/dev/null; then
msg_error "Downloaded file $(basename "$file") is corrupted. Please try again later."
rm -f "$file"
exit 1
exit 115
fi
msg_ok "Downloaded and validated $(basename "$file")"
}
@@ -272,7 +272,7 @@ function extract_xz_with_pv() {
if ! xz -dc "$file" | pv -N "Extracting" >"$target"; then
msg_error "Failed to extract $file"
rm -f "$target"
exit 1
exit 115
fi
msg_ok "Decompressed to $target"
}
@@ -592,7 +592,7 @@ DISK_REF="$(printf '%s\n' "$IMPORT_OUT" | sed -n "s/.*successfully imported disk
[[ -z "$DISK_REF" ]] && {
msg_error "Unable to determine imported disk reference."
echo "$IMPORT_OUT"
exit 1
exit 226
}
msg_ok "Imported disk (${CL}${BL}${DISK_REF}${CL})"

View File

@@ -556,7 +556,7 @@ fi
if [[ -z "$DISK_REF" ]]; then
msg_error "Unable to determine imported disk reference."
echo "$IMPORT_OUT"
exit 1
exit 226
fi
qm set $VMID \
@@ -635,7 +635,7 @@ if qm status "$VMID" | grep -q "running"; then
msg_ok "Network interfaces configured in OpenWrt"
else
msg_error "VM is not running"
exit 1
exit 226
fi
msg_info "Waiting for OpenWrt to shut down..."

View File

@@ -616,7 +616,7 @@ for ver in $RELEASE_LIST; do
done
if [ -z "$URL" ]; then
msg_error "Could not find generic FreeBSD amd64 qcow2 image (non-UFS/ZFS)."
exit 1
exit 115
fi
msg_ok "Download URL: ${CL}${BL}${URL}${CL}"
@@ -626,7 +626,7 @@ if ! check_disk_space "$TEMP_DIR" 20; then
msg_error "Insufficient disk space in temporary directory ($TEMP_DIR)."
msg_error "Available: ${AVAILABLE_GB}, Required: ~20GB for FreeBSD image decompression."
msg_error "Please free up space or ensure /tmp has sufficient storage."
exit 1
exit 214
fi
msg_info "Downloading FreeBSD Image"
@@ -639,7 +639,7 @@ if ! check_disk_space "$TEMP_DIR" 15; then
AVAILABLE_GB=$(df -h "$TEMP_DIR" | awk 'NR==2 {print $4}')
msg_error "Insufficient disk space for decompression."
msg_error "Available: ${AVAILABLE_GB}, Required: ~15GB for decompressed image."
exit 1
exit 214
fi
msg_info "Decompressing FreeBSD Image (this may take a few minutes)"
@@ -648,7 +648,7 @@ if ! unxz -cv $(basename $URL) >${FILE}; then
msg_error "Failed to decompress FreeBSD image."
msg_error "This is usually caused by insufficient disk space."
df -h "$TEMP_DIR"
exit 1
exit 115
fi
# Remove the compressed file to save space

View File

@@ -305,7 +305,7 @@ function advanced_settings() {
if [ $ISO_COUNT -eq 0 ]; then
echo "No ISOs found."
exit 1
exit 115
fi
# Identify the index of the last stable release
@@ -529,7 +529,7 @@ if [ -z "${SELECTED_ISO:-}" ]; then
if [ -z "$SELECTED_ISO" ]; then
msg_error "Could not find a stable ISO for fallback."
exit 1
exit 115
fi
fi

View File

@@ -215,7 +215,7 @@ function ensure_pv() {
if ! apt-get update -qq &>/dev/null || ! apt-get install -y pv &>/dev/null; then
msg_error "Failed to install pv automatically."
echo -e "\nPlease run manually on the Proxmox host:\n apt install pv\n"
exit 1
exit 237
fi
msg_ok "Installed pv"
fi
@@ -243,14 +243,14 @@ function download_and_validate_xz() {
if ! curl -fSL -o "$file" "$url"; then
msg_error "Download failed: $url"
rm -f "$file"
exit 1
exit 115
fi
# Validate again
if ! xz -t "$file" &>/dev/null; then
msg_error "Downloaded file $(basename "$file") is corrupted. Please try again later."
rm -f "$file"
exit 1
exit 115
fi
msg_ok "Downloaded and validated $(basename "$file")"
}
@@ -266,7 +266,7 @@ function extract_xz_with_pv() {
if ! xz -dc "$file" | pv -N "Extracting" >"$target"; then
msg_error "Failed to extract $file"
rm -f "$target"
exit 1
exit 115
fi
msg_ok "Decompressed to $target"
}
@@ -514,7 +514,7 @@ done < <(pvesm status -content images | awk 'NR>1 {printf "%s %s %s\n", $1, $2,
if [ ${#STORAGE_MENU[@]} -eq 0 ]; then
msg_error "Unable to detect a valid storage location."
exit 1
exit 119
elif [ $((${#STORAGE_MENU[@]} / 3)) -eq 1 ]; then
STORAGE=${STORAGE_MENU[0]}
else