-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive_fusionvm
executable file
·69 lines (51 loc) · 1.41 KB
/
archive_fusionvm
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
#!/bin/zsh
if [ ! -d "$1" ]; then
echo "Argument 1 must be a directory path to archive."
exit 3
fi
if [ -z "$2" ]; then
echo "Argument 2 must be a path to the desired output file."
exit 3
fi
# $1 is the path to a folder of VMs -- this will be sent directly to hdiutil
# $2 is a destination path for the disk image.
# We need an absolute path for the source.
SRCPATH=$(cd "$1"; pwd)
echo "SRCPATH is $SRCPATH"
running=()
# Test whether running .vmx files are inside our path.
refresh_running() {
running=(${(@f)"$(vmrun list | grep "$SRCPATH")"})
}
refresh_running
# Save this initial list of .vmx files
vmxlist=($running)
i=0
while true; do
echo "Current running VM list is $running"
# If no VMs are running, we can continue.
[ -z "$running" ] && break
i=$[ $i + 1 ]
if [ $i -gt 3 ]; then
echo "VMs were not suspended after three tries."
exit 4
fi
echo "Attempting to suspend VMs"
for vmx in $running; do
echo "Suspending $vmx"
vmrun suspend "$vmx"
done
refresh_running
done
# Test that every VMX in the list has no lockfile; otherwise quit Fusion
echo "Checking for lockfiles for VM list $vmxlist"
for vmx in $vmxlist; do
echo "Testing lockfile $vmx.lck"
if [ -e "$vmx.lck" ]; then
osascript -e 'tell application "VMware Fusion" to quit'
break
fi
done
# Create a compressed read-only .dmg. HFS+ seems to be smaller than APFS.
echo "Creating disk image"
hdiutil create -srcfolder "$1" "$2" -fs HFS+