From 7a5433f8fcf195a262696e7d72a234d14c3397a6 Mon Sep 17 00:00:00 2001 From: Mark Crouch Date: Thu, 2 Apr 2020 23:23:12 +0100 Subject: [PATCH] Add create .desktop shortcut feature. Deleted debug messages. Use `quemu-virgil` icon from the 'current' directory, not a specified version's directory. Tidied some code. --- README.md | 8 +++++++- quickemu | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 909c95c..3e1db4e 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,11 @@ Starting /media/martin/Quickemu/ubuntu-focal-desktop.conf * Complete the installation as normal. + * A Desktop shortcut can be created (in ~/.local/share/applications): +``` +./quickemu --shortcut --vm ubuntu-focal-desktop.conf +``` + ### Windows 10 You can use `quickemu` to run a Windows 10 virtual machine. @@ -160,6 +165,7 @@ Usage You can also pass optional parameters --delete : Delete the disk image. + --shortcut : Create a desktop shortcut --snapshot apply : Apply/restore a snapshot. --snapshot create : Create a snapshot. --snapshot delete : Delete a snapshot. @@ -169,7 +175,7 @@ You can also pass optional parameters ## TODO - - [ ] Create desktop launcher for a VM + - [x] Create desktop launcher for a VM - [ ] Improve disk management - [x] Add USB pass-through support - [x] Fix Virgil 3D on EFI boot diff --git a/quickemu b/quickemu index d941f08..9c6872f 100755 --- a/quickemu +++ b/quickemu @@ -8,6 +8,12 @@ function disk_delete() { else echo "NOTE! ${disk_img} not found. Doing nothing." fi + local VMNAME=$(basename "${VM}" .conf) + local SHORTCUT_DIR="/home/${USER}/.local/share/applications/" + if [ -e ${SHORTCUT_DIR}/${VMNAME}.desktop ]; then + rm -v "${SHORTCUT_DIR}/${VMNAME}.desktop" + echo "Deleted ${VM} desktop shortcut" + fi } function snapshot_apply() { @@ -377,6 +383,22 @@ function vm_boot() { fi } +function shortcut_create { + local VMNAME=$(basename "${VM}" .conf) + local LAUNCHER_DIR="$(dirname "$(realpath "$0")")" + local filename="/home/${USER}/.local/share/applications/${VMNAME}.desktop" + cat << EOF > ${filename} +[Desktop Entry] +Version=1.0 +Type=Application +Terminal=true +Exec=${LAUNCHER_DIR}/${LAUNCHER} --vm ${VM} +Name=${VMNAME} +Icon=/snap/qemu-virgil/current/meta/gui/icon.png +EOF + echo "Created ${VMNAME}.desktop file" +} + function usage() { echo echo "Usage" @@ -384,6 +406,7 @@ function usage() { echo echo "You can also pass optional parameters" echo " --delete : Delete the disk image." + echo " --shortcut : Create a desktop shortcut" echo " --snapshot apply : Apply/restore a snapshot." echo " --snapshot create : Create a snapshot." echo " --snapshot delete : Delete a snapshot." @@ -408,6 +431,7 @@ SNAPSHOT_TAG="" STATUS_QUO="" USB_PASSTHOUGH="" VM="" +SHORTCUT=0 readonly LAUNCHER=$(basename "${0}") readonly DISK_MIN_SIZE=$((197632 * 8)) @@ -441,6 +465,9 @@ while [ $# -gt 0 ]; do VM="${2}" shift shift;; + -shortcut|--shortcut) + SHORTCUT=1 + shift;; -h|--h|-help|--help) usage;; *) @@ -495,4 +522,10 @@ if [ -n "${SNAPSHOT_ACTION}" ]; then esac fi -vm_boot \ No newline at end of file +if [ ${SHORTCUT} -eq 1 ]; then + # echo "VM=" ${VM} + shortcut_create + exit +fi + +vm_boot