-
-
Save jonasschultzmblox/f15fe3c10769d5f269635a54394c84d4 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
#Heavily inspired by clivewalkden/centos-7-package.sh | |
# ( https://gist.github.com/clivewalkden/b4df0074fc3a84f5bc0a39dc4b344c57 ) | |
#However, this one was tested... 2017-JAN-09 | |
vagrant init centos/7 | |
vagrant up | |
vagrant ssh -c "sudo yum -y update" | |
vagrant ssh -c "sudo yum -y install wget nano kernel-devel gcc" | |
vagrant ssh -c "sudo cd /opt && sudo wget http://download.virtualbox.org/virtualbox/5.1.12/VBoxGuestAdditions_5.1.12.iso -O /opt/VBGAdd.iso" | |
vagrant ssh -c "sudo mount /opt/VBGAdd.iso -o loop /mnt" | |
vagrant ssh -c "sudo sh /mnt/VBoxLinuxAdditions.run --nox11" | |
vagrant ssh -c "sudo umount /mnt" | |
vagrant ssh -c "sudo rm /opt/VBGAdd.iso" | |
#Check that we can halt and boot | |
vagrant halt | |
vagrant up | |
#Halt again and package | |
vagrant halt | |
vagrant package | |
#And finally, clean up | |
mv package.box centos7vb.box | |
rm Vagrantfile |
Very nice.
You could add a tiny bit of automation into it like so:
#!/bin/bash
# Get current installed version of VirtualBox VERSION=$(rpm -q --queryformat %{VERSION} VirtualBox-6.0 | cut -d '_' -f 1)
and replacing your line
vagrant ssh -c "sudo cd /opt && sudo wget http://download.virtualbox.org/virtualbox/5.1.12/VBoxGuestAdditions_5.1.12.iso -O /opt/VBGAdd.iso"
by
vagrant ssh -c "sudo cd /opt && sudo wget http://download.virtualbox.org/virtualbox/${VERSION}/VBoxGuestAdditions_${VERSION}.iso -O /opt/VBGAdd.iso"
@lbriais thank you for your comment and working out a solution to get a matching header/etc. That works great and I've implemented it successfully in my own script.
@ros-financial-com I added automation to my script by using a variable in the beginning and setting it equal to $1
so that way whatever parameter I append after the script execution, it will go grab that version and install it. I do this because some systems may be on an older version and you will want to match it against your installed version IMO, as well you may not have Guest Additions installed yet on the machine so you may not be able to query an installed version.
Example: Running ./vbox.sh 6.0.4
VBOX_VERSION=$1
curl -O http://download.virtualbox.org/virtualbox/$VBOX_VERSION/VBoxGuestAdditions_$VBOX_VERSION.iso
Would grab and download
http://download.virtualbox.org/virtualbox/6.0.4/VBoxGuestAdditions_6.0.4.iso
FYI - if you need the latest version of the guest additions is available in the repo:
sudo yum -y install wget
cd /opt/
sudo wget http://download.virtualbox.org/virtualbox/LATEST.TXT
sudo wget -c http://download.virtualbox.org/virtualbox/$(cat LATEST.TXT)/VBoxGuestAdditions_$(cat LATEST.TXT).iso
Above might not be the best syntax, I dunno. Anyways, IMO, it feels a bit cleaner to grab the version info from the same repo that we're wget-ing from.There's also a LATEST-STABLE.TXT.
Thanks.
vagrant ssh -c "sudo yum clean all && sudo rm -rf /var/cache/yum"