ca9a496e42
- use `/run` instead of deprecated symlink `/var/run` - add `--autostart` option to automatically start the qube - check for invalid qube name before querying qubesd - use `--fail` option of qubesd-query instead of parsing its output file - add `--` and double quotes in various places - allow `--` to be passed to `qvm-console-dispvm` to mark end of options
40 lines
1.3 KiB
Bash
Executable File
40 lines
1.3 KiB
Bash
Executable File
#!/bin/bash --
|
|
set -eu
|
|
print_usage() {
|
|
cat >&2 << USAGE
|
|
Usage: $0 [--autostart] [--] vmname
|
|
Connects to VM console throught DispVM using the qubes.ShowInTerminal RPC service.
|
|
With --autostart, start the VM first.
|
|
USAGE
|
|
}
|
|
|
|
do_start=false
|
|
if [[ $# -ge 2 ]] && [[ "$1" = '--autostart' ]]; then
|
|
do_start=:
|
|
shift
|
|
fi
|
|
if [[ $# -eq 2 ]] && [[ "$1" = '--' ]]; then
|
|
shift
|
|
elif [ $# -ne 1 ]; then
|
|
print_usage
|
|
exit 1
|
|
fi
|
|
|
|
QREXEC_REQUESTED_TARGET="$1"
|
|
|
|
[[ "$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; }
|
|
|
|
DISPVM="$(qvm-prefs -- "$QREXEC_REQUESTED_TARGET" management_dispvm)"
|
|
|
|
[[ "x$DISPVM" == "x" ]] && { echo "Error: cannot determine management DispVM of domain '$QREXEC_REQUESTED_TARGET'">&2; exit 1; }
|
|
|
|
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
|