-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
vendor
executable file
·51 lines (40 loc) · 1.25 KB
/
vendor
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
#!/bin/bash
set -euo pipefail
directory="${2?Must be set to the directory of the iso contents}"
if [ -e "$directory.ova" ]; then
echo "$directory.ova already exists" >&2
exit
fi
cleanup(){
rm -f "$iso"
VBoxManage unregistervm "$name" --delete || true
}
name=""
description="This is a self installing Windows VM.
This VM uses https://github.com/brimstone/windows-ova"
. "$directory/variables.txt"
iso="$(mktemp --tmpdir XXX.iso)"
rm "$iso"
trap cleanup EXIT
genisoimage -o "$iso" -J -R -V "$directory" "$directory"
vboxmanage import "${1?Path to ova}" \
--vsys 0 --vmname "$name" \
--vsys 0 --ostype "Windows2012_64" \
--vsys 0 --cpus 2 \
--vsys 0 --memory "2048"
VBoxManage storageattach "$name" --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium "$iso"
# update description
VBoxManage modifyvm "$name" --description "$description"
# Start the VM
VBoxManage startvm "$name" --type headless
echo "$(date) Waiting for VM to personalize and shutdown"
# Wait for the VM to finish setting up.
while VBoxManage list runningvms | grep -q "$name"; do
printf "."
sleep 2
done
echo
# remove iso
VBoxManage storageattach "$name" --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium none
# export
VBoxManage export "$name" -o "$directory.ova" --ovf20