qusal/salt/dom0/files/bin/qvm-mgmt

72 lines
1.9 KiB
Plaintext
Raw Normal View History

#!/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(){
echo "Usage: ${0##*/} QUBE" >&2
exit "${1:-1}"
}
get_qube_feat(){
qube="${1}"
qvm-features "${qube}" | \
grep -E "^(os-(distribution|version)|template-(release|name))" | \
sed "s/ / /g;s/ /: /;s/^/ /"
}
case "${1-}" in
-h|--?help) usage 0;;
-*|"") usage 1;;
*) wanted_qube="${1}";;
esac
mgmt="$(qubes-prefs management_dispvm)"
echo "GLOBAL"
echo "management_dispvm: ${mgmt}"
tpl_mgmt="$(qvm-prefs "${mgmt}" template)"
echo "management_dispvm template: ${tpl_mgmt}"
echo "management_dispvm template features:"
get_qube_feat "${tpl_mgmt}"
if ! qvm-check -q -- "${wanted_qube}"; then
echo "error: qube '${wanted_qube}' does not exist" >&2
exit 1
fi
echo ""
echo "WANTED"
echo "qube: ${wanted_qube}"
class="$(qvm-prefs "${wanted_qube}" klass)"
echo "class: ${class}"
case "${class}" in
AppVM)
tpl_wanted_qube="$(qvm-prefs "${wanted_qube}" template)"
echo "template: ${tpl_wanted_qube}"
echo "template features:"
get_qube_feat "${tpl_wanted_qube}"
;;
DispVM)
dvm_wanted_qube="$(qvm-prefs "${wanted_qube}" template)"
echo "disposable template: ${dvm_wanted_qube}"
tpl_wanted_qube="$(qvm-prefs "${dvm_wanted_qube}" template)"
echo "template: ${tpl_wanted_qube}"
echo "template features:"
get_qube_feat "${tpl_wanted_qube}"
;;
AdminVM) ;;
StandaloneVM|TemplateVM)
get_qube_feat "${wanted_qube}"
;;
esac
wanted_mgmt="$(qvm-prefs "${wanted_qube}" management_dispvm)"
echo "${wanted_qube} management_dispvm: ${wanted_mgmt}"
if test "${wanted_mgmt}" = "${mgmt}"; then
exit
fi
wanted_tpl_mgmt="$(qvm-prefs "${wanted_mgmt}" template)"
echo "${wanted_qube} management_dispvm template: ${wanted_tpl_mgmt}"
echo "${wanted_qube} management_dispvm template features:"
get_qube_feat "${wanted_tpl_mgmt}"