-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.sh
executable file
·46 lines (34 loc) · 1.34 KB
/
make.sh
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
#!/bin/bash
# Re-create the VM.
# Argument: file name ( ${VM_NAME%.json} removes the extension if needed)
export VM_NAME=${1:-"vb-fedora-27-np"}
export VM_NAME=${VM_NAME%.json}
# Clean up old VM
VBoxManage controlvm $VM_NAME poweroff
VBoxManage unregistervm $VM_NAME --delete
rm -rf output-"$VM_NAME"/
for i in *.vdi; do vboxmanage closemedium disk $i --delete ; done
# Create shared folder (If you change this path change also in Packer: .json)
sudo mkdir -p /mnt/guest_vm
sudo sh -c 'chown -R $SUDO_UID:$SUDO_GID /mnt/guest_vm'
# Check before starting all the work (require package "pykickstart")
for i in kickstart/*.*; do ksvalidator "$i" || exit 1; done
ansible-playbook --syntax-check provisioners/ansible/*.yml || exit 1
# This is where I put all my VirtualBox machines
VIRTUALBOX_VM=~/VirtualBoxVM
PLOG=0
if [ $PLOG -eq 1 ]; then
mkdir -p log
TIMER=$(date +"%F_%Hh%M")
export PACKER_LOG=1
export PACKER_LOG_PATH="log/${TIMER}_packer.txt"
fi
# Create the VM
time packerio build $VM_NAME.json
if [ -f output-$VM_NAME/$VM_NAME.ovf ]; then
[ $PLOG -eq 1 ] && cp output-$VM_NAME/$VM_NAME.ovf log/${TIMER}_${VM_NAME}.ovf
VBoxManage import output-$VM_NAME/$VM_NAME.ovf
[ $PLOG -eq 1 ] && cp "$VIRTUALBOX_VM/$VM_NAME/$VM_NAME.vbox" log/${TIMER}_${VM_NAME}.vbox
echo "Now: launch.sh $VM_NAME"
./launch.sh $VM_NAME
fi