Last active
January 3, 2016 00:39
-
-
Save batandwa/8383871 to your computer and use it in GitHub Desktop.
Vigrant - Export a VirtualBox VM and import it as a Vagrant box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [ -z "$2" ];then | |
| echo "We need two parameters, boet." | |
| echo " Usage: $FUNCNAME vagrant-name vbox-machine-name" | |
| return 1 | |
| fi | |
| export lowername=$2 | |
| export tempdir=createvmbox.$((RANDOM)) | |
| mkdir -p /tmp/$tempdir | |
| cd /tmp/$tempdir | |
| VBoxManage export "$2" --output "box.ovf" --manifest | |
| export retval=$? | |
| if [ $retval -ne 0 ]; then | |
| echo "Error exporting VirtualBox machine. Exiting." | |
| return 2 | |
| fi | |
| # Remove existing box | |
| if [[ `vagrant box list` =~ "$1" ]]; then | |
| echo "Removing old box." | |
| vagrant box remove $1 virtualbox | |
| fi | |
| echo '{"provider":"virtualbox"}' >> metadata.json | |
| zip "$lowername.box" * | |
| vagrant box add $1 "$lowername.box" | |
| cd - | |
| rm /tmp/$tempdir -R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment