summaryrefslogtreecommitdiff
path: root/qmenu/qmenu-vm
blob: ce587a06f511c97ebd61e1b08e51e4b65065dbac (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/sh

fmenu_dom0() (

while :; do

	[ -z "$loop" ] && chosefrom=$(printf 'Global preferences\nLogs\nNew qube\nNotes\nProperty Manager' | dmenu-unlinked -l 5 -i -p "dom0:")

	case $chosefrom in

		Global*) . /lib/qmenu_vm/fqubes_prefs;;

		Logs) . /lib/qmenu_vm/fqubes_logs;;

		New*) . /lib/qmenu_vm/fqvm_create;;

		Notes) . /lib/qmenu_vm/f_notes;;

		Property*) . /lib/qmenu_vm/fq_pm;;

		*) exit
	esac

	[ -z "$loop" ] || break
done
)

fmenu_domu() (

dmenu() (

command dmenu-unlinked -sb "$qube_label" "$@"
)

qube_label=$(grep -s "^$(qvm-prefs "$qube" label)=" "$HOME"/.config/qmenu.conf | cut -d= -f2)

[ -z "$qube_label" ] && qube_label='#000000'

while :; do

	[ -z "$loop" ] && chosefrom=$(printf 'Applications\nAudio input devices\nBlock devices\nBoot\nBootfrom\nClone\nCommand\nDisk\nFirewall\nKeyboard\nKill\nLogs\nNotes\nPause\nPCI devices\nPreferences\nReboot\nRemove\nScreenshot\nServices\nShutdown\nTags\nUnpause\nUSB devices' | dmenu-unlinked -l 24 -i -p "$qube:")

	case $chosefrom in

		Applications) . /lib/qmenu_vm/fqvm_appmenus;;

		Audio*|Block*|USB*) . /lib/qmenu_vm/fqvm_device;;

		Boot) qvm-start --skip-if-running "$qube"&;;

		Bootfrom) qubes-vm-boot-from-device "$qube";;

		Clone) . /lib/qmenu_vm/fqvm_clone;;

		Command) . /lib/qmenu_vm/fqvm_run;;

		Disk) . /lib/qmenu_vm/fqvm_volume;;

		Firewall) . /lib/qmenu_vm/fqvm_firewall;;

		Keyboard) . /lib/qmenu_vm/fq_keyboard;;

		Kill) nyprompt "Kill $qube?" && (qvm-kill "$qube"&);;

		Logs) . /lib/qmenu_vm/fqubes_logs;;

		Notes) . /lib/qmenu_vm/f_notes;;

		Pause) nyprompt "Pause $qube?" && (qvm-pause "$qube"&);;

		PCI*) . /lib/qmenu_vm/fqvm_pci;;

		Preferences) . /lib/qmenu_vm/fqvm_prefs;;

		Reboot)	nyprompt "Reboot $qube?" && qvm-check -q --running "$qube" && (qvm-shutdown --wait "$qube" && qvm-start "$qube"&);;

		Remove) . /lib/qmenu_vm/fqvm_remove;;

		Screenshot) . /lib/qmenu_vm/f_screenshot;;

		Services) . /lib/qmenu_vm/fqvm_service;;

		Shutdown) nyprompt "Shutdown $qube?" && (qvm-shutdown "$qube"&);;

		Tags) . /lib/qmenu_vm/fqvm_tags;;

		Unpause) qvm-unpause "$qube"&;;

		*) exit
	esac

	[ -z "$loop" ] || break
done
)

get_list() {

case $1 in

	mgmt_disptemp) flags='|a.....D.$';;

	netvm) flags='|...N....$';;

	template) flags='|t.......$'
esac

list=$(qvm-ls --raw-data -O name,flags | grep "$flags" | cut -d '|' -f1)
}

nyprompt() (

[ "$(printf 'No\nYes' | dmenu-unlinked -i -p "$1")" = Yes ]
)


[ -n "$2" ] && chosefrom="$2" loop=0

case $1 in

	--all|--halted|--paused|--running|--tags=*)

		while :; do

			# Load 'qvm-ls' into a variable so that the list doesnt
			# need to be reloaded after every user operation.
			qube_list=$(qvm-ls --no-spinner "$1" -O name,state,label,maxmem,class,template,netvm,default_dispvm,ip,priv-max,priv-curr,priv-used,root-max,root-curr,root-used,kernel | sed 's/ LABEL/ 0\@ /g; s/ red/ 1\@ /g; s/ orange/ 2\@ /g; s/ yellow/ 3\@ /g; s/ green/ 4\@ /g; s/ gray/ 5\@ /g; s/ blue/ 6\@ /g; s/ purple/ 7\@ /g; s/ black/ 8\@ /g' | sort -k3,3 | sed 's/ 0\@ / LABEL/g; s/ 1\@ / red/g; s/ 2\@ / orange/g; s/ 3\@ / yellow/g; s/ 4\@ / green/g; s/ 5\@ / gray/g; s/ 6\@ / blue/g; s/ 7\@ / purple/g; s/ 8\@ / black/g')

			# Get out of the while loop and reload the list by loading 'qvm-ls' again
			# into $qube_list, whenever the user selects the 'qvm-ls' top row (NAME).
			# Essentially making the top row a refresh button.
			while [ "$qubes" != NAME ]; do

				qubes=$(echo "$qube_list" | dmenu-unlinked -l 50 | cut -f1 -d\ )

				[ -z "$qubes" ] && exit 1

				for qube in $qubes; do

					if [ "$qube" = dom0 ]; then fmenu_dom0
					elif [ "$qube" != NAME ]; then fmenu_domu
					fi
				done
			done

			unset qubes
		done;;

	--focused)

		qube=$(xprop -id "$(xdotool getwindowfocus)" _QUBES_VMNAME | cut -d\" -f2)

		if [ "$qube" = '_QUBES_VMNAME:  not found.' ]; then qube=dom0; fmenu_dom0; else fmenu_domu; fi;;

	--qube=*)

		qube=$(echo "$1" | cut -d= -f2)

		if [ "$qube" = dom0 ]; then fmenu_dom0; else fmenu_domu; fi;;

	*)

		printf "Usage: $0 [OPTION] (MENU ITEM)\nList, manage and configure your qubes via dmenu.\n\n --all\n --focused\n --halted\n --paused\n --running\n --qube=[QUBE]\n --tags=[TAG]\n\n"

		[ "$1" = --help ] && exit 0; exit 2
esac

exit 1