forked from QubesOS/qubes-remote-support
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qubes-remote-support-receiver-status
executable file
·75 lines (58 loc) · 1.81 KB
/
qubes-remote-support-receiver-status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -e
set -o errtrace
vm_name="$2"
if [ "$vm_name" = "" ]; then
vm_name="sys-whonix"
fi
error_handler() {
local exit_code="$?"
echo "INFO: BASH_COMMAND '$BASH_COMMAND' terminated with exit_code '$exit_code'. Remote support will not work." >&2
exit "$exit_code"
}
trap error_handler ERR
no_root_check() {
if [ "$(id -u)" = "0" ]; then
echo "ERROR: Do not run $0 as root / with sudo!" >&2
exit 100
fi
}
dom0_check_rpc_policy() {
local append_string
if ! test -f /etc/qubes-rpc/policy/qubes.ConnectTCP+22 ; then
exit 2
fi
append_string="$vm_name dom0 allow,target=dom0"
if grep -q "$append_string" /etc/qubes-rpc/policy/qubes.ConnectTCP+22 ; then
echo "INFO: /etc/qubes-rpc/policy/qubes.ConnectTCP+22 looks OK."
else
echo "INFO: /etc/qubes-rpc/policy/qubes.ConnectTCP+22 missing line
$append_string
remote support will not work." >&2
exit 3
fi
}
check_vm_started() {
if qvm-check --running "$vm_name" ; then
echo "INFO: VM '$vm_name' already running, ok."
else
exit 3
fi
}
check_vm_status() {
## --pass-io is optional but useful for gathering debug output.
qvm-run --user root --pass-io "$vm_name" "systemctl status --no-pager --no-block qubes-whonix-remote-support.service"
qvm-run --user root --pass-io "$vm_name" "systemctl status --no-pager --no-block [email protected]"
}
dom0_check_sshd_status() {
sudo --non-interactive systemctl --no-pager --no-block status sshd.service
}
no_root_check
## If dom0 SSH server is not running, there is no way to remote administrate dom0.
## However, the onion v3 service might still be running inside $vm_name in case
## of a race condition.
dom0_check_sshd_status
dom0_check_rpc_policy
check_vm_started
check_vm_status
echo "INFO: Success."