40 lines
883 B
Bash
Executable file
40 lines
883 B
Bash
Executable file
#!/usr/bin/env sh
|
|
set -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}"
|
|
name="$QEMUSH_NAME"
|
|
[ -n "$2" ] && name="${name}-${2}"
|
|
[ -n "$extension" ] && extension=".${extension}"
|
|
printf %s/%s%s\\n "$basedir" "$name" "$extension"
|