echo "[${level}] ${message}"
}
+cmd() {
+ local cmd=$@
+ local ret
+
+ log DEBUG "Running command: ${cmd}"
+
+ ${cmd}
+ ret=$?
+
+ case "${ret}" in
+ ${EXIT_OK})
+ return ${EXIT_OK}
+ ;;
+ *)
+ log DEBUG "Returned with code '${ret}'"
+ return ${ret}
+ ;;
+ esac
+}
+
cleanup() {
# Unmount image
umount ${IMAGE_MOUNT_DIR}
log ERROR "Failed to compress the image. The file already exists"
return ${EXIT_ERROR}
fi
- xz "-${level}" "${image_file}"
+ cmd xz "-${level}" "${image_file}"
;;
"zip")
# Check that the file does not exist yet
return ${EXIT_ERROR}
fi
- zip "-${level}" "${image_file}.zip" "${image_file}"
+ cmd zip "-${level}" "${image_file}.zip" "${image_file}"
# Remove the file which we compressed+
rm -f "${image_file}"
;;
fi
if [[ ${type} = "qcow2" ]]; then
- local cmd="qemu-img convert -c -O ${type} ${from} ${to}.${type}"
+ local command="qemu-img convert -c -O ${type} ${from} ${to}.${type}"
else
- local cmd="qemu-img convert -O ${type} ${from} ${to}.${type}"
+ local command="qemu-img convert -O ${type} ${from} ${to}.${type}"
fi
- log debug "${cmd}"
-
- # Execute the command to convert the image
- ${cmd}
+ cmd ${command}
}
get_compression_type() {