2024-03-08 23:41:32 +01:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
set -e
|
2024-01-25 16:13:58 +01:00
|
|
|
|
|
|
|
# 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)
|
2024-03-08 23:45:51 +01:00
|
|
|
basedir=sockets/monitors
|
2024-01-25 16:13:58 +01:00
|
|
|
;;
|
|
|
|
spice)
|
2024-03-08 23:45:51 +01:00
|
|
|
basedir=sockets/spice
|
2024-01-25 16:13:58 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
false
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Release the trap
|
|
|
|
trap - EXIT
|
|
|
|
|
|
|
|
# Print the actual string
|
|
|
|
basedir="${HOME}/${basedir}"
|
2024-03-08 23:41:50 +01:00
|
|
|
name="$QEMUSH_NAME"
|
|
|
|
[ -n "$2" ] && name="${name}-${2}"
|
2024-01-25 16:13:58 +01:00
|
|
|
[ -n "$extension" ] && extension=".${extension}"
|
2024-03-08 23:41:50 +01:00
|
|
|
printf %s/%s%s\\n "$basedir" "$name" "$extension"
|