refactor: process all single run actions; make output consistent
This commit is contained in:
parent
70055b746e
commit
054f471f18
88
quickemu
88
quickemu
|
@ -40,33 +40,52 @@ function delete_shortcut() {
|
||||||
local SHORTCUT_DIR="${HOME}/.local/share/applications/"
|
local SHORTCUT_DIR="${HOME}/.local/share/applications/"
|
||||||
if [ -e "${SHORTCUT_DIR}/${VMNAME}.desktop" ]; then
|
if [ -e "${SHORTCUT_DIR}/${VMNAME}.desktop" ]; then
|
||||||
rm "${SHORTCUT_DIR}/${VMNAME}.desktop"
|
rm "${SHORTCUT_DIR}/${VMNAME}.desktop"
|
||||||
echo "Deleted ${VM} desktop shortcut"
|
echo " - Deleted ${SHORTCUT_DIR}/${VMNAME}.desktop"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_disk() {
|
function delete_disk() {
|
||||||
|
echo "Deleting ${VMNAME} virtual hard disk"
|
||||||
if [ -e "${disk_img}" ]; then
|
if [ -e "${disk_img}" ]; then
|
||||||
rm "${disk_img}"
|
rm "${disk_img}" >/dev/null 2>&1
|
||||||
# Remove any EFI vars, but not for macOS
|
# Remove any EFI vars, but not for macOS
|
||||||
rm "${VMDIR}"/OVMF_VARS*.fd >/dev/null 2>&1
|
rm "${VMDIR}"/OVMF_VARS*.fd >/dev/null 2>&1
|
||||||
rm "${VMPATH}/${VMDIR}"/OVMF_VARS*.fd >/dev/null 2>&1
|
rm "${VMPATH}/${VMDIR}"/OVMF_VARS*.fd >/dev/null 2>&1
|
||||||
rm "${VMDIR}/${VMNAME}-vars.fd" >/dev/null 2>&1
|
rm "${VMDIR}/${VMNAME}-vars.fd" >/dev/null 2>&1
|
||||||
rm "${VMPATH}/${VMDIR}/${VMNAME}-vars.fd" >/dev/null 2>&1
|
rm "${VMPATH}/${VMDIR}/${VMNAME}-vars.fd" >/dev/null 2>&1
|
||||||
echo "SUCCESS! Deleted ${disk_img}"
|
echo " - Deleted ${disk_img}"
|
||||||
delete_shortcut
|
delete_shortcut
|
||||||
else
|
else
|
||||||
echo "NOTE! ${disk_img} not found. Doing nothing."
|
echo " - ${disk_img} not found. Doing nothing."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_vm() {
|
function delete_vm() {
|
||||||
|
echo "Deleting ${VMNAME} completely"
|
||||||
if [ -d "${VMDIR}" ]; then
|
if [ -d "${VMDIR}" ]; then
|
||||||
rm -rf "${VMDIR}"
|
rm -rf "${VMDIR}"
|
||||||
rm "${VM}"
|
rm "${VM}"
|
||||||
echo "SUCCESS! Deleted ${VM} and ${VMDIR}"
|
echo " - Deleted ${VM} and ${VMDIR}/"
|
||||||
delete_shortcut
|
delete_shortcut
|
||||||
else
|
else
|
||||||
echo "NOTE! ${VMDIR} not found. Doing nothing."
|
echo " - ${VMDIR} not found. Doing nothing."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function kill_vm() {
|
||||||
|
echo "Killing ${VMNAME}"
|
||||||
|
if [ -z "${VM_PID}" ]; then
|
||||||
|
echo " - ${VMNAME} is not running."
|
||||||
|
rm -f "${VMDIR}/${VMNAME}.pid"
|
||||||
|
elif [ -n "${VM_PID}" ]; then
|
||||||
|
if kill -9 "${VM_PID}" > /dev/null 2>&1; then
|
||||||
|
echo " - ${VMNAME} (${VM_PID}) killed."
|
||||||
|
rm -f "${VMDIR}/${VMNAME}.pid"
|
||||||
|
else
|
||||||
|
echo " - ${VMNAME} (${VM_PID}) was not killed."
|
||||||
|
fi
|
||||||
|
elif [ ! -r "${VMDIR}/${VMNAME}.pid" ]; then
|
||||||
|
echo " - ${VMNAME} has no ${VMDIR}/${VMNAME}.pid"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1335,6 +1354,7 @@ function start_viewer {
|
||||||
function shortcut_create {
|
function shortcut_create {
|
||||||
local dirname="${HOME}/.local/share/applications"
|
local dirname="${HOME}/.local/share/applications"
|
||||||
local filename="${HOME}/.local/share/applications/${VMNAME}.desktop"
|
local filename="${HOME}/.local/share/applications/${VMNAME}.desktop"
|
||||||
|
echo "Creating ${VMNAME} desktop shortcut file"
|
||||||
|
|
||||||
if [ ! -d "${dirname}" ]; then
|
if [ ! -d "${dirname}" ]; then
|
||||||
mkdir -p "${dirname}"
|
mkdir -p "${dirname}"
|
||||||
|
@ -1349,7 +1369,7 @@ Path=${VMPATH}
|
||||||
Name=${VMNAME}
|
Name=${VMNAME}
|
||||||
Icon=/usr/share/icons/hicolor/scalable/apps/qemu.svg
|
Icon=/usr/share/icons/hicolor/scalable/apps/qemu.svg
|
||||||
EOF
|
EOF
|
||||||
echo "Created ${VMNAME}.desktop file"
|
echo " - ${filename} created."
|
||||||
}
|
}
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
|
@ -1535,16 +1555,13 @@ mouse="${mouse:-tablet}"
|
||||||
sound_card="${sound_card:-intel-hda}"
|
sound_card="${sound_card:-intel-hda}"
|
||||||
|
|
||||||
ACCESS=""
|
ACCESS=""
|
||||||
|
ACTIONS=()
|
||||||
BRAILLE=""
|
BRAILLE=""
|
||||||
DELETE_DISK=0
|
|
||||||
DELETE_VM=0
|
|
||||||
FULLSCREEN=""
|
FULLSCREEN=""
|
||||||
KILL_VM=0
|
|
||||||
MONITOR_CMD=""
|
MONITOR_CMD=""
|
||||||
PUBLIC=""
|
PUBLIC=""
|
||||||
PUBLIC_PERMS=""
|
PUBLIC_PERMS=""
|
||||||
PUBLIC_TAG=""
|
PUBLIC_TAG=""
|
||||||
SHORTCUT=0
|
|
||||||
SNAPSHOT_ACTION=""
|
SNAPSHOT_ACTION=""
|
||||||
SNAPSHOT_TAG=""
|
SNAPSHOT_TAG=""
|
||||||
SOCKET_MONITOR=""
|
SOCKET_MONITOR=""
|
||||||
|
@ -1589,10 +1606,10 @@ else
|
||||||
BRAILLE="on"
|
BRAILLE="on"
|
||||||
shift;;
|
shift;;
|
||||||
-delete|--delete|-delete-disk|--delete-disk)
|
-delete|--delete|-delete-disk|--delete-disk)
|
||||||
DELETE_DISK=1
|
ACTIONS+=(delete_disk)
|
||||||
shift;;
|
shift;;
|
||||||
-delete-vm|--delete-vm)
|
-delete-vm|--delete-vm)
|
||||||
DELETE_VM=1
|
ACTIONS+=(delete_vm)
|
||||||
shift;;
|
shift;;
|
||||||
-display|--display)
|
-display|--display)
|
||||||
display="${2}"
|
display="${2}"
|
||||||
|
@ -1605,7 +1622,7 @@ else
|
||||||
ignore_msrs_always
|
ignore_msrs_always
|
||||||
exit;;
|
exit;;
|
||||||
-kill|--kill)
|
-kill|--kill)
|
||||||
KILL_VM=1
|
ACTIONS+=(kill_vm)
|
||||||
shift;;
|
shift;;
|
||||||
-offline|--offline)
|
-offline|--offline)
|
||||||
network="none"
|
network="none"
|
||||||
|
@ -1627,7 +1644,7 @@ else
|
||||||
STATUS_QUO="-snapshot"
|
STATUS_QUO="-snapshot"
|
||||||
shift;;
|
shift;;
|
||||||
-shortcut|--shortcut)
|
-shortcut|--shortcut)
|
||||||
SHORTCUT=1
|
ACTIONS+=(shortcut_create)
|
||||||
shift;;
|
shift;;
|
||||||
-vm|--vm)
|
-vm|--vm)
|
||||||
VM="${2}"
|
VM="${2}"
|
||||||
|
@ -1716,6 +1733,14 @@ if [ -n "${VM}" ] && [ -e "${VM}" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Iterate over any actions and exit.
|
||||||
|
if [ ${#ACTIONS[@]} -ge 1 ]; then
|
||||||
|
for ACTION in "${ACTIONS[@]}"; do
|
||||||
|
${ACTION}
|
||||||
|
done
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
# Backwards compatibility for ${driver_iso}
|
# Backwards compatibility for ${driver_iso}
|
||||||
if [ -n "${driver_iso}" ] && [ -z "${fixed_iso}" ]; then
|
if [ -n "${driver_iso}" ] && [ -z "${fixed_iso}" ]; then
|
||||||
fixed_iso="${driver_iso}"
|
fixed_iso="${driver_iso}"
|
||||||
|
@ -1806,34 +1831,6 @@ else
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${KILL_VM} -eq 1 ]; then
|
|
||||||
echo "Killing ${VMNAME}"
|
|
||||||
if [ -z "${VM_PID}" ]; then
|
|
||||||
echo " - ${VMNAME} is not running."
|
|
||||||
rm -f "${VMDIR}/${VMNAME}.pid"
|
|
||||||
elif [ -n "${VM_PID}" ]; then
|
|
||||||
if kill -9 "${VM_PID}" > /dev/null 2>&1; then
|
|
||||||
echo " - ${VMNAME} (${VM_PID}) killed."
|
|
||||||
rm -f "${VMDIR}/${VMNAME}.pid"
|
|
||||||
else
|
|
||||||
echo " - ${VMNAME} (${VM_PID}) was not killed."
|
|
||||||
fi
|
|
||||||
elif [ ! -r "${VMDIR}/${VMNAME}.pid" ]; then
|
|
||||||
echo " - ${VMNAME} has no ${VMDIR}/${VMNAME}.pid"
|
|
||||||
fi
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ${DELETE_DISK} -eq 1 ]; then
|
|
||||||
delete_disk
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ${DELETE_VM} -eq 1 ]; then
|
|
||||||
delete_vm
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${SNAPSHOT_ACTION}" ]; then
|
if [ -n "${SNAPSHOT_ACTION}" ]; then
|
||||||
case ${SNAPSHOT_ACTION} in
|
case ${SNAPSHOT_ACTION} in
|
||||||
apply)
|
apply)
|
||||||
|
@ -1857,11 +1854,6 @@ if [ -n "${SNAPSHOT_ACTION}" ]; then
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${SHORTCUT} -eq 1 ]; then
|
|
||||||
shortcut_create
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${VM_PID}" ]; then
|
if [ -z "${VM_PID}" ]; then
|
||||||
#TODO: double quote the args array to prevent word splitting and this can be removed
|
#TODO: double quote the args array to prevent word splitting and this can be removed
|
||||||
# Fix failing to start VM with spaces in the path
|
# Fix failing to start VM with spaces in the path
|
||||||
|
|
Loading…
Reference in New Issue