qusal/salt/dom0/files/bin/qvm-mgmt
Ben Grande aea8438904
fix: stricter command-line parsing
- Add to qvm-run:
  - no-gui when command doesn't require a GUI
  - filter-escape-chars when pass-io is set and output is not a file,
    such as a pipe that could later be used to print information.
- Change remaining echo to printf
- Add end-of-options separator when possible
2025-01-08 16:12:31 +01:00

73 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
## SPDX-FileCopyrightText: 2024 - 2025 Benjamin Grande M. S. <ben.grande.b@gmail.com>
##
## SPDX-License-Identifier: AGPL-3.0-or-later
set -eu
usage(){
printf '%s\n' "Usage: ${0##*/} QUBE" >&2
exit "${1:-1}"
}
get_qube_feat(){
qube="${1}"
qvm-features "${qube}" | \
grep -E -e "^(os-(distribution|version)|template-(release|name))" |
awk '{print $1 ": " $2}'
}
case "${1-}" in
-h|--?help) usage 0;;
-*|"") usage 1;;
*) wanted_qube="${1}";;
esac
mgmt="$(qubes-prefs -- management_dispvm)"
printf '%s\n' "GLOBAL"
printf '%s\n' "management_dispvm: ${mgmt}"
tpl_mgmt="$(qvm-prefs -- "${mgmt}" template)"
printf '%s\n' "management_dispvm template: ${tpl_mgmt}"
printf '%s\n' "management_dispvm template features:"
get_qube_feat "${tpl_mgmt}"
if ! qvm-check -q -- "${wanted_qube}"; then
printf '%s\n' "error: qube '${wanted_qube}' does not exist" >&2
exit 1
fi
printf '%s\n' ""
printf '%s\n' "WANTED"
printf '%s\n' "qube: ${wanted_qube}"
class="$(qvm-prefs -- "${wanted_qube}" klass)"
printf '%s\n' "class: ${class}"
case "${class}" in
AppVM)
tpl_wanted_qube="$(qvm-prefs -- "${wanted_qube}" template)"
printf '%s\n' "template: ${tpl_wanted_qube}"
printf '%s\n' "template features:"
get_qube_feat "${tpl_wanted_qube}"
;;
DispVM)
dvm_wanted_qube="$(qvm-prefs -- "${wanted_qube}" template)"
printf '%s\n' "disposable template: ${dvm_wanted_qube}"
tpl_wanted_qube="$(qvm-prefs -- "${dvm_wanted_qube}" template)"
printf '%s\n' "template: ${tpl_wanted_qube}"
printf '%s\n' "template features:"
get_qube_feat "${tpl_wanted_qube}"
;;
AdminVM) ;;
StandaloneVM|TemplateVM)
get_qube_feat "${wanted_qube}"
;;
*) printf '%s\n' "Unsupported qube class" >&2; exit 1;;
esac
wanted_mgmt="$(qvm-prefs -- "${wanted_qube}" management_dispvm)"
printf '%s\n' "management_dispvm: ${wanted_mgmt}"
if test "${wanted_mgmt}" = "${mgmt}"; then
exit
fi
wanted_tpl_mgmt="$(qvm-prefs -- "${wanted_mgmt}" template)"
printf '%s\n' "management_dispvm template: ${wanted_tpl_mgmt}"
printf '%s\n' "management_dispvm template features:"
get_qube_feat "${wanted_tpl_mgmt}"