mirror of
https://github.com/oSoWoSo/DistroHopper.git
synced 2024-08-14 22:46:53 +00:00
Quote all file/directory variables. Closes #12
File handling is more robust and will support filename and directories with spaces in them.
This commit is contained in:
parent
142eac3001
commit
735e3a4ee8
1 changed files with 66 additions and 29 deletions
69
quickemu
69
quickemu
|
@ -87,8 +87,8 @@ function get_port() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function vm_boot() {
|
function vm_boot() {
|
||||||
local VMNAME=$(basename ${VM} .conf)
|
local VMNAME=$(basename "${VM}" .conf)
|
||||||
local VMDIR=$(dirname ${disk_img})
|
local VMDIR=$(dirname "${disk_img}")
|
||||||
local BIOS=""
|
local BIOS=""
|
||||||
local CPU="-cpu host,kvm=on"
|
local CPU="-cpu host,kvm=on"
|
||||||
local GUEST_TWEAKS=""
|
local GUEST_TWEAKS=""
|
||||||
|
@ -106,10 +106,11 @@ function vm_boot() {
|
||||||
boot=$(echo ${boot,,})
|
boot=$(echo ${boot,,})
|
||||||
if [ "${boot}" == "efi" ] || [ "${boot}" == "uefi" ]; then
|
if [ "${boot}" == "efi" ] || [ "${boot}" == "uefi" ]; then
|
||||||
if [ -e "${VIRGIL_PATH}/usr/share/qemu/edk2-x86_64-code.fd" ] ; then
|
if [ -e "${VIRGIL_PATH}/usr/share/qemu/edk2-x86_64-code.fd" ] ; then
|
||||||
if [ ! -e "${VMDIR}/${VMNAME}-vars.fd" ]; then
|
local EFI_CODE="${VIRGIL_PATH}/usr/share/qemu/edk2-x86_64-code.fd"
|
||||||
cp "${VIRGIL_PATH}/usr/share/qemu/edk2-i386-vars.fd" "${VMDIR}/${VMNAME}-vars.fd"
|
local EFI_VARS="${VMDIR}/${VMNAME}-vars.fd"
|
||||||
|
if [ ! -e "${EFI_VARS}" ]; then
|
||||||
|
cp "${VIRGIL_PATH}/usr/share/qemu/edk2-i386-vars.fd" "${EFI_VARS}"
|
||||||
fi
|
fi
|
||||||
BIOS="-drive if=pflash,format=raw,readonly,file=${VIRGIL_PATH}/usr/share/qemu/edk2-x86_64-code.fd -drive if=pflash,format=raw,file=${VMDIR}/${VMNAME}-vars.fd"
|
|
||||||
echo " - BOOT: EFI"
|
echo " - BOOT: EFI"
|
||||||
else
|
else
|
||||||
echo " - BOOT: Legacy BIOS"
|
echo " - BOOT: Legacy BIOS"
|
||||||
|
@ -141,7 +142,12 @@ function vm_boot() {
|
||||||
echo " - Disk: ${disk_img} (${disk})"
|
echo " - Disk: ${disk_img} (${disk})"
|
||||||
if [ ! -f "${disk_img}" ]; then
|
if [ ! -f "${disk_img}" ]; then
|
||||||
# If there is no disk image, create a new image.
|
# If there is no disk image, create a new image.
|
||||||
|
mkdir -p "${VMDIR}" 2>/dev/null
|
||||||
${QEMU_IMG} create -q -f qcow2 "${disk_img}" "${disk}"
|
${QEMU_IMG} create -q -f qcow2 "${disk_img}" "${disk}"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "ERROR! Failed to create ${disk_img}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
if [ -z "${iso}" ]; then
|
if [ -z "${iso}" ]; then
|
||||||
echo "ERROR! You haven't specified a .iso image to boot from."
|
echo "ERROR! You haven't specified a .iso image to boot from."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -151,9 +157,9 @@ function vm_boot() {
|
||||||
echo "ERROR! Failed to create ${disk_img} of ${disk}. Stopping here."
|
echo "ERROR! Failed to create ${disk_img} of ${disk}. Stopping here."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif [ -e ${disk_img} ]; then
|
elif [ -e "${disk_img}" ]; then
|
||||||
# Check there isn't already a process attached to the disk image.
|
# Check there isn't already a process attached to the disk image.
|
||||||
QEMU_LOCK_TEST=$(${QEMU_IMG} info ${disk_img} 2>/dev/null)
|
QEMU_LOCK_TEST=$(${QEMU_IMG} info "${disk_img}" 2>/dev/null)
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo " Failed to get "write" lock. Is another process using the disk?"
|
echo " Failed to get "write" lock. Is another process using the disk?"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -179,12 +185,10 @@ function vm_boot() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${iso}" ] && [ -e "${iso}" ]; then
|
if [ -n "${iso}" ] && [ -e "${iso}" ]; then
|
||||||
local ISO_BOOT="-drive media=cdrom,file=${iso},index=0"
|
|
||||||
echo " - Boot: ${iso}"
|
echo " - Boot: ${iso}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${driver_iso}" ] && [ -e "${driver_iso}" ]; then
|
if [ -n "${driver_iso}" ] && [ -e "${driver_iso}" ]; then
|
||||||
local ISO_DRIVER="-drive media=cdrom,file=${driver_iso},index=1"
|
|
||||||
echo " - Drivers: ${driver_iso}"
|
echo " - Drivers: ${driver_iso}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -272,24 +276,57 @@ function vm_boot() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Boot the iso image
|
# Boot the iso image
|
||||||
|
if [ "${boot}" == "efi" ] || [ "${boot}" == "uefi" ]; then
|
||||||
${QEMU} \
|
${QEMU} \
|
||||||
-name ${VMNAME},process=${VMNAME} \
|
-name ${VMNAME},process=${VMNAME} \
|
||||||
-enable-kvm -machine q35 ${BIOS} ${GUEST_TWEAKS} \
|
-enable-kvm -machine q35 ${GUEST_TWEAKS} \
|
||||||
${CPU} -smp ${CORES_VM} \
|
${CPU} -smp ${CORES_VM} \
|
||||||
-m ${RAM_VM} -device virtio-balloon \
|
-m ${RAM_VM} -device virtio-balloon \
|
||||||
-drive if=none,id=drive0,cache=directsync,aio=native,format=qcow2,file=${disk_img} \
|
-drive if=pflash,format=raw,readonly,file="${EFI_CODE}" \
|
||||||
|
-drive if=pflash,format=raw,file="${EFI_VARS}" \
|
||||||
|
-drive media=cdrom,index=0,file="${iso}" \
|
||||||
|
-drive media=cdrom,index=1,file="${driver_iso}" \
|
||||||
|
-drive if=none,id=drive0,cache=directsync,aio=native,format=qcow2,file="${disk_img}" \
|
||||||
-device virtio-blk-pci,drive=drive0,scsi=off ${STATUS_QUO} \
|
-device virtio-blk-pci,drive=drive0,scsi=off ${STATUS_QUO} \
|
||||||
${ISO_BOOT} ${ISO_DRIVER} \
|
|
||||||
${VIDEO} -display ${OUTPUT},gl=${GL}${OUTPUT_EXTRA} \
|
${VIDEO} -display ${OUTPUT},gl=${GL}${OUTPUT_EXTRA} \
|
||||||
-device qemu-xhci,id=xhci,p2=8,p3=8 -device usb-kbd,bus=xhci.0 -device usb-tablet,bus=xhci.0 \
|
-device qemu-xhci,id=xhci,p2=8,p3=8 -device usb-kbd,bus=xhci.0 -device usb-tablet,bus=xhci.0 ${USB_PASSTHROUGH} \
|
||||||
-device virtio-net,netdev=nic -netdev ${NET},id=nic \
|
-device virtio-net,netdev=nic -netdev ${NET},id=nic \
|
||||||
-audiodev pa,id=pa,server=unix:${XDG_RUNTIME_DIR}/pulse/native,out.stream-name=${LAUNCHER}-${VMNAME},in.stream-name=${LAUNCHER}-${VMNAME} \
|
-audiodev pa,id=pa,server=unix:${XDG_RUNTIME_DIR}/pulse/native,out.stream-name=${LAUNCHER}-${VMNAME},in.stream-name=${LAUNCHER}-${VMNAME} \
|
||||||
-device intel-hda -device hda-duplex,audiodev=pa,mixer=off \
|
-device intel-hda -device hda-duplex,audiodev=pa,mixer=off \
|
||||||
-rtc base=localtime,clock=host \
|
-rtc base=localtime,clock=host \
|
||||||
-object rng-random,id=rng0,filename=/dev/urandom \
|
-object rng-random,id=rng0,filename=/dev/urandom \
|
||||||
-device virtio-rng-pci,rng=rng0 \
|
-device virtio-rng-pci,rng=rng0 \
|
||||||
|
-spice port=5930,disable-ticketing \
|
||||||
|
-device virtio-serial-pci \
|
||||||
|
-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
|
||||||
|
-chardev spicevmc,id=spicechannel0,name=vdagent \
|
||||||
-serial mon:stdio \
|
-serial mon:stdio \
|
||||||
"$@"
|
"${@}"
|
||||||
|
else
|
||||||
|
${QEMU} \
|
||||||
|
-name ${VMNAME},process=${VMNAME} \
|
||||||
|
-enable-kvm -machine q35 ${GUEST_TWEAKS} \
|
||||||
|
${CPU} -smp ${CORES_VM} \
|
||||||
|
-m ${RAM_VM} -device virtio-balloon \
|
||||||
|
-drive media=cdrom,index=0,file="${iso}" \
|
||||||
|
-drive media=cdrom,index=1,file="${driver_iso}" \
|
||||||
|
-drive if=none,id=drive0,cache=directsync,aio=native,format=qcow2,file="${disk_img}" \
|
||||||
|
-device virtio-blk-pci,drive=drive0,scsi=off ${STATUS_QUO} \
|
||||||
|
${VIDEO} -display ${OUTPUT},gl=${GL}${OUTPUT_EXTRA} \
|
||||||
|
-device qemu-xhci,id=xhci,p2=8,p3=8 -device usb-kbd,bus=xhci.0 -device usb-tablet,bus=xhci.0 ${USB_PASSTHROUGH} \
|
||||||
|
-device virtio-net,netdev=nic -netdev ${NET},id=nic \
|
||||||
|
-audiodev pa,id=pa,server=unix:${XDG_RUNTIME_DIR}/pulse/native,out.stream-name=${LAUNCHER}-${VMNAME},in.stream-name=${LAUNCHER}-${VMNAME} \
|
||||||
|
-device intel-hda -device hda-duplex,audiodev=pa,mixer=off \
|
||||||
|
-rtc base=localtime,clock=host \
|
||||||
|
-object rng-random,id=rng0,filename=/dev/urandom \
|
||||||
|
-device virtio-rng-pci,rng=rng0 \
|
||||||
|
-spice port=5930,disable-ticketing \
|
||||||
|
-device virtio-serial-pci \
|
||||||
|
-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
|
||||||
|
-chardev spicevmc,id=spicechannel0,name=vdagent \
|
||||||
|
-serial mon:stdio \
|
||||||
|
"${@}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
|
@ -322,7 +359,7 @@ SNAPSHOT_TAG=""
|
||||||
STATUS_QUO=""
|
STATUS_QUO=""
|
||||||
VM=""
|
VM=""
|
||||||
|
|
||||||
readonly LAUNCHER=$(basename $0)
|
readonly LAUNCHER=$(basename "${0}")
|
||||||
readonly DISK_MIN_SIZE=$((197632 * 8))
|
readonly DISK_MIN_SIZE=$((197632 * 8))
|
||||||
readonly QEMU="/snap/bin/qemu-virgil"
|
readonly QEMU="/snap/bin/qemu-virgil"
|
||||||
readonly QEMU_IMG="/snap/bin/qemu-virgil.qemu-img"
|
readonly QEMU_IMG="/snap/bin/qemu-virgil.qemu-img"
|
||||||
|
@ -351,7 +388,7 @@ while [ $# -gt 0 ]; do
|
||||||
STATUS_QUO="-snapshot"
|
STATUS_QUO="-snapshot"
|
||||||
shift;;
|
shift;;
|
||||||
-vm|--vm)
|
-vm|--vm)
|
||||||
VM="$2"
|
VM="${2}"
|
||||||
shift
|
shift
|
||||||
shift;;
|
shift;;
|
||||||
-h|--h|-help|--help)
|
-h|--h|-help|--help)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue