diff --git a/README.md b/README.md index 81cdf8e..47cf60f 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,7 @@ need it - `coreutils` - used for basic OS operations - `sudo` - execute commands as `qemu` - `socat` - monitor machines via Unix sockets -- `diskpath` and `sockpath` - see [Installation -instructions](#installation-instructions) +- `pathof` - see [Installation instructions](#installation-instructions) - any text editor - used for builtin function to edit launching scripts ## Installation instructions diff --git a/bin/qemush b/bin/qemush index 96d0cad..77cad28 100755 --- a/bin/qemush +++ b/bin/qemush @@ -66,7 +66,7 @@ public_start() { QEMUSH_NAME="$1" set -- "$@" \ - -monitor "unix:$(sockpath),server,nowait" \ + -monitor "unix:$(pathof socket),server,nowait" \ -daemonize if ! "$@"; then perror "error launching virtual machine \"${QEMUSH_NAME}\"" @@ -80,7 +80,7 @@ public_attach() { QEMUSH_NAME="$1" shift - exec socat -,echo=0,icanon=0 "UNIX-CONNECT:$(sockpath)" + exec socat -,echo=0,icanon=0 "UNIX-CONNECT:$(pathof socket)" } # List running virtual machines @@ -103,14 +103,14 @@ public_ls() { public_diskadd() { QEMUSH_NAME="$1" shift - exec qemu-img create -f qcow2 "$(diskpath)" "$1" + exec qemu-img create -f qcow2 "$(pathof disk)" "$1" } # Delete a disk public_diskrm() { for disk in "$@"; do QEMUSH_NAME="$disk" - rm -vi -- "$(diskpath)" + rm -vi -- "$(pathof disk)" done } diff --git a/qemu/bin/diskpath b/qemu/bin/diskpath deleted file mode 100755 index 85a74aa..0000000 --- a/qemu/bin/diskpath +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -e - -# Invoked on termination if the last command failed -error() { >&2 echo "$(basename "$0"): failed"; } - -# Trap errors -trap error EXIT - -# Assert that the QEMUSH_NAME variable is not null -[ -n "$QEMUSH_NAME" ] - -# Release the trap -trap - EXIT - -# Print the actual string -printf %s/%s.qcow2\\n ~/disks "$QEMUSH_NAME" diff --git a/qemu/bin/pathof b/qemu/bin/pathof new file mode 100755 index 0000000..470a66a --- /dev/null +++ b/qemu/bin/pathof @@ -0,0 +1,37 @@ +#!/bin/sh -e + +# Invoked on termination if the last command failed +error() { >&2 echo "$(basename "$0"): ${*}"; } +error_envvar() { error "missing environment variable QEMUSH_NAME"; } +error_arg() { error "invalid argument \"${*}\""; } + +# Assert that the QEMUSH_NAME variable is not null +trap error_envvar EXIT +[ -n "$QEMUSH_NAME" ] + +# Determine the base dir to use +trap 'error_arg "$*"' EXIT +case "$1" in + disk) + basedir=disks + extension=qcow2 + ;; + socket) + basedir=sockets + ;; + spice) + basedir=spice + extension=sock + ;; + *) + false + ;; +esac + +# Release the trap +trap - EXIT + +# Print the actual string +basedir="${HOME}/${basedir}" +[ -n "$extension" ] && extension=".${extension}" +printf %s/%s%s\\n "$basedir" "$QEMUSH_NAME" "$extension" diff --git a/qemu/bin/sockpath b/qemu/bin/sockpath deleted file mode 100755 index a840abe..0000000 --- a/qemu/bin/sockpath +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -e - -# Invoked on termination if the last command failed -error() { >&2 echo "$(basename "$0"): failed"; } - -# Trap errors -trap error EXIT - -# Assert that the QEMUSH_NAME variable is not null -[ -n "$QEMUSH_NAME" ] - -# Release the trap -trap - EXIT - -# Print the actual string -printf %s/%s ~/sockets "$QEMUSH_NAME" diff --git a/qemu/launchers/windows10 b/qemu/launchers/windows10 index 2dd6771..b1013ff 100755 --- a/qemu/launchers/windows10 +++ b/qemu/launchers/windows10 @@ -7,7 +7,7 @@ export QEMUSH_RAM=4G # Launch the virtual machine exec kvm-spice \ - -drive file="$(diskpath)",if=virtio \ + -drive file="$(pathof disk)",if=virtio \ -net user,hostname="${QEMUSH_NAME}" \ -usbdevice tablet \ -name "$QEMUSH_NAME" \