From 7b24482dcd8672d14f82cb7ae0ad7b74b3a468a9 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Tue, 26 Mar 2024 20:14:11 +0100 Subject: [PATCH] please --- bin/qemush | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 bin/qemush diff --git a/bin/qemush b/bin/qemush new file mode 100755 index 0000000..14138e2 --- /dev/null +++ b/bin/qemush @@ -0,0 +1,42 @@ +#!/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/monitors + ;; + spice) + basedir=sockets/spice + ;; + shared) + basedir=shared + ;; + *) + 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"