-
Notifications
You must be signed in to change notification settings - Fork 4
/
qubes-keepass-dom0.sh
executable file
·85 lines (67 loc) · 1.76 KB
/
qubes-keepass-dom0.sh
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
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/bash
VAULT='vault'
VERSION='qubes-keepass v1.2.1'
function get_id() {
# Get the id of the currently focused window. This function
# was copied from the default resources that are shipped with
# Qubes OS.
#
# Parameters:
# None
#
# Returns:
# currently focused window id
#
local ID=$(xprop -root _NET_ACTIVE_WINDOW)
echo ${ID##* }
}
function get_xprop() {
# Get the specified xproperty from the specified window ID.
#
# Parameters:
# ID the window ID to obtain the property from
# PROP the property to obtain
# TYPE the type to obtain (str, int)
#
# Returns:
# the requested property
#
local ID=${1}
local PROP=${2}
local TYPE=${3}
local VALUE=$(xprop -id "${ID}" | grep "${PROP}")
if [ "${TYPE}" == "str" ]; then
VALUE=${VALUE#*\"}
echo ${VALUE%\"*}
elif [ "${TYPE}" == "int" ]; then
echo ${VALUE#*= }
else
echo ''
fi
}
function main() {
# Obtain the required properties from the currently focused window and call
# qubes-keepass with them.
#
# Parameters:
# None
#
# Returns:
# None
#
set -e
set -x
qvm-check --running -q "${VAULT}"
if [ $? -ne 0 ]; then
echo "[-] Your vault qube ${VAULT} is not running yet."
echo "[-] Aborting to prevent unwanted qube startup."
return
fi
local ID=$(get_id)
local VM=$(get_xprop "${ID}" '_QUBES_VMNAME(STRING)' 'str')
local LABEL=$(get_xprop "${ID}" '_QUBES_LABEL(CARDINAL)' 'int')
if [ -n "${VM}" ] && [ -n "${LABEL}" ]; then
qvm-run --no-shell "${VAULT}" '/home/user/.local/bin/qubes-keepass.py' "${VM}" --trust-level "${LABEL}"
fi
}
main