Skip to content

Instantly share code, notes, and snippets.

@cjcolvar cjcolvar/buildOVA.sh
Last active Dec 28, 2015

Embed
What would you like to do?
Bash script to build an OVA after vagrant up
#!/bin/bash
vagrant destroy
vagrant up
VM_UUID=`VBoxManage list runningvms | grep -o '[0-9a-fA-F]\{8\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{12\}'`
HD_UUID=`VBoxManage list -l runningvms | grep "SATA.*UUID" | grep -o '[0-9a-fA-F]\{8\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{12\}'`
VM_DATE=`date +%y%m%d`
VBoxManage snapshot "${VM_UUID}" take "avalon-vm-${VM_DATE}-bootstrapped"
#Do OVA prep
vagrant ssh -c 'sudo yum install -y NetworkManager-gnome firstboot perl-XML-Twig perl-YAML-LibYAML'
vagrant ssh -c 'sudo rpm -i "http://www.avalonmediasystem.org/downloads/avalon-vm-2.0-1.noarch.rpm"'
vagrant ssh -c 'sudo rm -rf /root/Downloads/* /var/avalon/dropbox/* /home/makerpm/rpmbuild /opt/staging /root/avalon-installer-flat /root/flat.tar.gz'
vagrant ssh -c 'sudo yum clean all'
vagrant ssh -c 'sudo swapoff /dev/mapper/VolGroup-lv_swap; sudo dd if=/dev/zero of=/dev/mapper/VolGroup-lv_swap bs=1M; sudo mkswap /dev/mapper/VolGroup-lv_swap'
vagrant ssh -c 'sudo dd if=/dev/zero of=/tmp/foo bs=1M oflag=direct; sudo rm /tmp/foo'
vagrant ssh -c 'sudo /usr/share/avalon/dist-prep'
vagrant ssh -c 'history -cw'
#End OVA prep
vagrant halt
#NOTE this requires a vdi disk instead of a vmdk!
VBoxManage modifyhd "${HD_UUID}" --compact
VBoxManage export "${VM_UUID}" --output "avalon-vm-${VM_DATE}.ova" --product "Avalon Media System" --producturl "http://www.avalonmediasystem.org" --version "R2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.