diff --git a/bin/qemush b/bin/qemush index 1774c05..eb8fa9b 100755 --- a/bin/qemush +++ b/bin/qemush @@ -14,7 +14,49 @@ exec_as() { exec_as qemu "$@" || exit PATH="./bin:${PATH}" -vm_name="$1" +perror() { + >&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$*" +} + +public_help() { + local name + name="$(basename "$0")" + cat << EOF +${name}: usage: + ${name} start - start a VM + ${name} watch - attach VM screen session + ${name} active - (default behaviour) list active VMs + ${name} list - list available VMs + ${name} help - show this help +EOF +} + +error_usage() { + perror "Invalid usage" + >&2 public_help + return 1 +} + +public_start() { + local vm_name="$1" + shift + + screen -d -m -S "$vm_name" "$vm_name" "$@" +} + +public_watch() { + screen -dr "$1" +} + +public_list() { + screen -ls +} + +function="$1" shift -"$vm_name" "$@" +if declare -F | cut -d \ -f 3- | grep '^public_' | sed 's/^public_//' | grep -q "^${function}$"; then + "public_${function}" "$@" +else + error_usage +fi diff --git a/share/qemu/bin/linux b/qemu/bin/linux similarity index 71% rename from share/qemu/bin/linux rename to qemu/bin/linux index 50e9f72..1cc1d29 100755 --- a/share/qemu/bin/linux +++ b/qemu/bin/linux @@ -1,7 +1,6 @@ #!/bin/sh -ex name="$(basename "$0")" -cd "$(dirname "$(readlink -f "$0")")/.." -exec screen -S "QEMU : ${name}" -d -m qemu-system-x86_64 \ +qemu-system-x86_64 \ -monitor stdio -enable-kvm \ -cpu host -smp "$(nproc)" \ -m 4G \ diff --git a/share/qemu/bin/windows10 b/qemu/bin/windows10 similarity index 82% rename from share/qemu/bin/windows10 rename to qemu/bin/windows10 index e758bf4..9bbac80 100755 --- a/share/qemu/bin/windows10 +++ b/qemu/bin/windows10 @@ -1,7 +1,6 @@ #!/bin/sh -ex name="$(basename "$0")" -cd "$(dirname "$(readlink -f "$0")")/.." -exec screen -S "QEMU : ${name}" -d -m qemu-system-x86_64 \ +qemu-system-x86_64 \ -monitor stdio -enable-kvm \ -bios /usr/share/edk2/x64/OVMF_CODE.fd \ -usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=1452 \