refactor(quickget): centralise qemu-img detection into require_qemu_img

- Add require_qemu_img() to detect qemu-img and print a clear error if
missing
- Call require_qemu_img before any qemu-img operations (RecoveryImage,
.img conversions)
- Remove duplicate global qemu-img existence check to avoid repetition

Signed-off-by: Martin Wimpress <martin@wimpress.org>
This commit is contained in:
Martin Wimpress 2026-01-23 18:06:59 +00:00 committed by Martin Wimpress
parent e259ade5fa
commit a4d8329ba7
1 changed files with 10 additions and 6 deletions

View File

@ -212,6 +212,14 @@ function error_not_supported_argument() {
exit 1
}
function require_qemu_img() {
QEMU_IMG=$(command -v qemu-img)
if [ ! -x "${QEMU_IMG}" ]; then
echo "ERROR! qemu-img not found. Please make sure qemu-img is installed."
exit 1
fi
}
function is_valid_language() {
local I18N=""
local PASSED_I18N="${1}"
@ -2165,6 +2173,7 @@ function get_macos() {
fi
if [ -e "${VM_PATH}/RecoveryImage.dmg" ] && [ ! -e "${VM_PATH}/RecoveryImage.img" ]; then
require_qemu_img
echo " - Converting RecoveryImage.dmg"
${QEMU_IMG} convert "${VM_PATH}/RecoveryImage.dmg" -O raw "${VM_PATH}/RecoveryImage.img" 2>/dev/null
fi
@ -3388,6 +3397,7 @@ function create_vm() {
fi;;
easyos)
if [[ ${ISO} = *".img"* ]]; then
require_qemu_img
${QEMU_IMG} convert -f raw -O qcow2 "${VM_PATH}/${ISO}" "${VM_PATH}/disk.qcow2"
ISO="${ISO/.img/}"
fi;;
@ -3557,12 +3567,6 @@ if [ ! -x "${CURL}" ]; then
fi
CURL_VERSION=$("${CURL}" --version | head -n 1 | cut -d' ' -f2)
QEMU_IMG=$(command -v qemu-img)
if [ ! -x "${QEMU_IMG}" ]; then
echo "ERROR! qemu-img not found. Please make sure qemu-img is installed."
exit 1
fi
#TODO: Deprecate `list`, `list_csv`, and `list_json` in favor of `--list`, `--list-csv`, and `--list-json`
case "${1}" in
--download|-download)