-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvm
executable file
·107 lines (91 loc) · 1.7 KB
/
vm
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
#!/bin/bash
# vmrun with fusion shits me up the wall.
# i took a deep breath, 2 vodka redbulls and bashed it.
VMRUN="/Applications/VMware Fusion.app/Contents/Public/vmrun"
VMDIR="$HOME/Documents/Virtual Machines.localized"
ACTION=$1
shift 1
VMNAME="$@"
#echo $ACTION
#echo $VMNAME
function vmrun_start
{
VM="$@"
if [[ "$(vmrun_find_running $VM)" != 0 ]]; then
echo 'VM already running'
exit
fi
echo "Starting $VMNAME..."
"$VMRUN" -T ws start "$VM" nogui
}
function vmrun_suspend
{
VM="$@"
if [[ "$(vmrun_find_running $VM)" == 0 ]]; then
echo 'VM not running'
exit
fi
echo "Suspening $VMNAME..."
"$VMRUN" suspend "$VM"
}
function vmrun_list
{
LIST=$("$VMRUN" list)
ESCAPED_DIR=$(echo "$VMDIR" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
echo "$LIST" | sed -n "s/$ESCAPED_DIR\/\(.*\)\.vmwarevm\/\(.*\)\.vmx/\2/p"
echo "$LIST" | head -n 1
}
function vmrun_find_running
{
VM="$@"
echo $("$VMRUN" list | grep "$VM" | wc -l);
}
function vmrun_help
{
echo "usage:"
echo "start a headless vm:"
echo "$ $0 start vmname"
echo "suspend a headless vm:"
echo "$ $0 stop vmname"
echo "list running vms"
echo "$ $0 list"
echo
echo "https://github.com/dnoiz1/vmware-fusion-headless-helper"
echo "author: Tim Noise <[email protected]>"
echo
}
if [ -s $ACTION ]; then
vmrun_help
exit
fi
if [[ $ACTION == 'list' ]]; then
vmrun_list
exit
fi
if [ -s $VMNAME ]; then
echo 'specify a vm name'
exit
fi
if [ ! -d "$VMDIR/$VMNAME.vmwarevm" ]; then
echo 'vm not found'
exit
fi
VMX="$VMDIR/$VMNAME.vmwarevm/$VMNAME.vmx"
if [ ! -f "$VMX" ]; then
echo 'vmx not found'
exit
fi
case $ACTION in
start)
vmrun_start $VMX
;;
stop)
vmrun_suspend $VMX
;;
suspend)
vmrun_suspend $VMX
;;
*)
vmrun_help
;;
esac