mirror of
https://github.com/ben-grande/qusal.git
synced 2025-02-07 10:35:21 -05:00
bdd4c789c1
Echo can interpret operand as an option and checking every variable to be echoed is troublesome while with printf, if the format specifier is present before the operand, printing as string can be enforced.
73 lines
2.1 KiB
Bash
Executable File
73 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
## SPDX-FileCopyrightText: 2024 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))" | \
|
|
sed -e "s/ / /g;s/ /: /;s/^/ /"
|
|
}
|
|
|
|
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' "${wanted_qube} management_dispvm: ${wanted_mgmt}"
|
|
if test "${wanted_mgmt}" = "${mgmt}"; then
|
|
exit
|
|
fi
|
|
wanted_tpl_mgmt="$(qvm-prefs "${wanted_mgmt}" template)"
|
|
printf '%s\n' "${wanted_qube} management_dispvm template: ${wanted_tpl_mgmt}"
|
|
printf '%s\n' "${wanted_qube} management_dispvm template features:"
|
|
get_qube_feat "${wanted_tpl_mgmt}"
|