blob: bc906808e9548fa55aa2550237c677bc202f9870 (
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
|
#!/bin/sh
# Select action
choice=$(printf "virt-manager\nstart\nshutdown" | dmenu -i -p "Choose an action:")
[ -z "$choice" ] && exit 1
# Get list of VMs based on state
case "$choice" in
virt-manager) setsid -f virt-manager && exit ;;
start) vmlist=$(virsh --connect qemu:///system list --all | awk '/shut off/ {print $2}') ;;
shutdown) vmlist=$(virsh --connect qemu:///system list --all | awk '/running/ {print $2}') ;;
*) exit 1 ;;
esac
# Select a VM from the list
vm=$(printf "%s\n" "$vmlist" | dmenu -i -p "$choice which VM?")
[ -z "$vm" ] && exit 1
# Perform the action
case "$choice" in
start)
virsh --connect qemu:///system start "$vm" &&
setsid -f virt-viewer --connect qemu:///system "$vm" >/dev/null 2>&1
;;
shutdown)
virsh --connect qemu:///system shutdown "$vm"
;;
esac
|