2020-11-27 03:15:34 +01:00
|
|
|
#!/bin/bash --
|
|
|
|
set -eu
|
2019-05-07 13:54:29 +02:00
|
|
|
print_usage() {
|
|
|
|
cat >&2 << USAGE
|
2020-11-27 03:15:34 +01:00
|
|
|
Usage: $0 [--autostart] [--] vmname
|
2019-05-07 13:54:29 +02:00
|
|
|
Connects to VM console throught DispVM using the qubes.ShowInTerminal RPC service.
|
2020-11-27 03:15:34 +01:00
|
|
|
With --autostart, start the VM first.
|
2019-05-07 13:54:29 +02:00
|
|
|
USAGE
|
|
|
|
}
|
|
|
|
|
2020-11-27 03:15:34 +01:00
|
|
|
do_start=false
|
|
|
|
if [[ $# -ge 2 ]] && [[ "$1" = '--autostart' ]]; then
|
|
|
|
do_start=:
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
if [[ $# -eq 2 ]] && [[ "$1" = '--' ]]; then
|
|
|
|
shift
|
|
|
|
elif [ $# -ne 1 ]; then
|
2019-05-07 13:54:29 +02:00
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
QREXEC_REQUESTED_TARGET="$1"
|
|
|
|
|
2020-11-27 03:15:34 +01:00
|
|
|
[[ "$QREXEC_REQUESTED_TARGET" =~ ^[A-Za-z][A-Za-z0-9_-]*$ ]] || { printf 'Invalid qube name %q\n' "$QREXEC_REQUESTED_TARGET">&2; exit 1; }
|
|
|
|
|
|
|
|
if "$do_start"; then
|
|
|
|
msg='cannot be started'
|
|
|
|
qvm-start --skip-if-running -- "$QREXEC_REQUESTED_TARGET"
|
|
|
|
else
|
|
|
|
msg='is not running'
|
|
|
|
qvm-check --quiet --running -- "$QREXEC_REQUESTED_TARGET"
|
|
|
|
fi > /dev/null 2>&1 || { echo "Error: domain '$QREXEC_REQUESTED_TARGET' does not exist or $msg">&2; exit 1; }
|
2019-05-07 13:54:29 +02:00
|
|
|
|
2020-11-27 03:15:34 +01:00
|
|
|
DISPVM="$(qvm-prefs -- "$QREXEC_REQUESTED_TARGET" management_dispvm)"
|
2019-05-07 13:54:29 +02:00
|
|
|
|
2020-11-27 03:15:34 +01:00
|
|
|
[[ "x$DISPVM" == "x" ]] && { echo "Error: cannot determine management DispVM of domain '$QREXEC_REQUESTED_TARGET'">&2; exit 1; }
|
2019-05-07 13:54:29 +02:00
|
|
|
|
2019-10-01 04:38:58 +02:00
|
|
|
sudo qvm-run -p --localcmd="QREXEC_REQUESTED_TARGET=$QREXEC_REQUESTED_TARGET QREXEC_REMOTE_DOMAIN=dom0 /etc/qubes-rpc/admin.vm.Console" --service --dispvm="$DISPVM" -- qubes.ShowInTerminal
|