qemu/bin : diskpath, sockpath -> pathof

This commit is contained in:
Ahurac 2024-01-25 16:13:58 +01:00
parent 0a2de050dd
commit 9cc7cad967
6 changed files with 43 additions and 39 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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"

37
qemu/bin/pathof Executable file
View file

@ -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"

View file

@ -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"

View file

@ -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" \