Skip to content

Instantly share code, notes, and snippets.

@bionix
Created May 14, 2014 13:47
Show Gist options
  • Save bionix/c509a078bef3665439e2 to your computer and use it in GitHub Desktop.
Save bionix/c509a078bef3665439e2 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
case "$PACKER_BUILDER_TYPE" in
virtualbox-iso|virtualbox-ovf)
echo "==> Start VBoxGuestAdditions installation"
# The netboot installs the VirtualBox support (old) so we have to remove it
if test -f /etc/init.d/virtualbox-ose-guest-utils ; then
/etc/init.d/virtualbox-ose-guest-utils stop
fi
rmmod vboxguest
aptitude -y purge virtualbox-ose-guest-x11 virtualbox-ose-guest-dkms virtualbox-ose-guest-utils
# If libdbus is not installed, virtualbox will not autostart
apt-get -y install --no-install-recommends libdbus-1-3
mkdir /tmp/vbox
VER=$(cat /home/vagrant/.vbox_version)
mount -o loop /home/vagrant/VBoxGuestAdditions_$VER.iso /tmp/vbox
sh /tmp/vbox/VBoxLinuxAdditions.run --nox11
# A little workaround for a virtualbox bug with version 4.3.10
if [ $VER = '4.3.10' ] ; then
ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
rm /sbin/mount.vboxsf
ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions/mount.vboxsf /sbin/mount.vboxsf
fi
umount /tmp/vbox
rmdir /tmp/vbox
rm /home/vagrant/*.iso
;;
vmware-iso|vmware-ovf)
echo "==> Start VMware installation"
mkdir /tmp/vmfusion
mkdir /tmp/vmfusion-archive
mount -o loop /home/vagrant/linux.iso /tmp/vmfusion
tar xzf /tmp/vmfusion/VMwareTools-*.tar.gz -C /tmp/vmfusion-archive
/tmp/vmfusion-archive/vmware-tools-distrib/vmware-install.pl --default
umount /tmp/vmfusion
rm -rf /tmp/vmfusion
rm -rf /tmp/vmfusion-archive
rm /home/vagrant/*.iso
;;
*)
echo "Unknown Packer Builder Type >>$PACKER_BUILDER_TYPE<< selected."
echo "Known are virtualbox-iso|virtualbox-ovf|vmware-iso|vmware-ovf."
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment