summaryrefslogtreecommitdiff
path: root/qmenu/qmenu_vm/fq_pm
blob: 313a6b0c27137153d44ab05e57250e1e815b529a (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
qubes=$(qvm-ls --no-spinner --all --exclude=dom0 -O name,label,template,netvm,default_dispvm,kernel | dmenu-unlinked -l 50 | cut -f1 -d\ )

if [ -n "$qubes" ]; then

	property=$(printf 'Default_DispVM\nKernel\nLabel\nTemplate\nNetVM' | dmenu-unlinked -i -l 5 -p "Select the property you wish to change:" | awk '{print tolower($0)}')

	if [ -n "$property" ]; then

		case $property in

			default_dispvm)

 				if [ -z "$LIST_DISPTEMP" ]; then

					# [mediocre] Look up disposable templates in a very slow way because qvm-ls does not offer a flag for them
					for n in $(qvm-ls --raw-data -O NAME,FLAGS | grep '|a.....-.$' | cut -d '|' -f1); do

						qvm-prefs "$n" template_for_dispvms | grep -q True &&

							LIST_DISPTEMP="$LIST_DISPTEMP\n$n"
					done
				fi

				value=$(printf "(Default)\n(None)$LIST_DISPTEMP" | dmenu-unlinked -l 50 -p "Select default dispvm:")

				if [ "$value" = '(None)' ]; then value=None
				elif [ "$value" = '(Default)' ]; then value=--default; fi;;

			kernel)

				value=$(echo --default | dmenu-unlinked -p "Enter kernel:");;

			label)

				value=$(printf 'Purple\nBlue\nGray\nGreen\nYellow\nOrange\nRed\nBlack' | dmenu-unlinked -i -l 8 -p "Select label:" | awk '{print tolower($0)}');;

			template)

				get_list template

				value=$(printf "(Default)\n$list" | dmenu-unlinked -l 50 -p "Select template:")

				[ "$value" = '(Default)' ] && value=--default;;

			netvm)

				get_list netvm

				value=$(printf "(Default)\n(None)\n$list" | dmenu-unlinked -l 50 -p "Select netvm:")

				if [ "$value" = '(None)' ]; then value=None
				elif [ "$value" = '(Default)' ]; then value=--default; fi;;

			*)
		esac

		if [ -n "$value" ]; then

			if nyprompt "Do you want to change the $property of all selected qubes to $value?"; then

				for qube in $qubes; do

					if [ "$property" = label ] || [ "$property" = template ] && qvm-check -q --running "$qube"; then

						echo Proceed... | dmenu-unlinked -p "Warning: Unable to change $property of $qube because it is not shut down." > /dev/null 2>&1
					else
						qvm-prefs "$qube" "$property" "$value" ||

							echo Proceed... | dmenu-unlinked -p "Error: Failed to set $property of $qube to '$value'!" > /dev/null 2>&1
					fi
				done
			fi
		fi
	fi
fi