Created
March 8, 2013 00:36
-
-
Save mrmichalis/5113247 to your computer and use it in GitHub Desktop.
This file contains 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 | |
(( $# < 2 )) && { echo "usage: $0 majorversion minorversion"; exit 1; } | |
vc_osiso="${HOME}/Downloads/CentOS-${1}.${2}-x86_64-minimal.iso" | |
vc_guestiso='/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso' | |
vc_vboxbase="${HOME}/VirtualBox VMs" | |
vc_basebox="vagrant-centos-${1}-${2}" | |
vc_hddbase="${vc_vboxbase}/${vc_basebox}/${vc_basebox}" | |
vc_hddfile="${vc_hddbase}.vdi" | |
checkdir() { [[ ! -d "$1" ]] && { echo "ERROR: missing $1 dir!"; exit 1; } } | |
checkiso() { [[ ! -e "$1" ]] && { echo "ERROR: missing $1 file!"; exit 1; } } | |
checkdir "$HOME" | |
checkdir "$vc_vboxbase" | |
checkiso "$vc_osiso" | |
checkiso "$vc_guestiso" | |
VBoxManage -v &> /dev/null || { echo "ERROR: VBoxManage not in path!"; exit 1; } | |
VBoxManage createvm --name "$vc_basebox" --register | |
VBoxManage modifyvm "$vc_basebox" --ostype RedHat_64 --memory 512 --vram 12 --rtcuseutc on --ioapic on | |
VBoxManage storagectl "$vc_basebox" --name ide0 --add ide | |
VBoxManage storageattach "$vc_basebox" --storagectl ide0 --device 0 --port 0 --type dvddrive --medium "$vc_osiso" | |
VBoxManage storageattach "$vc_basebox" --storagectl ide0 --device 0 --port 1 --type dvddrive --medium "$vc_guestiso" | |
VBoxManage storagectl "$vc_basebox" --name sata0 --add sata --sataportcount 1 | |
VBoxManage createhd --filename "$vc_hddbase" --size 40960 | |
VBoxManage storageattach "$vc_basebox" --storagectl sata0 --port 0 --type hdd --medium "$vc_hddfile" | |
VBoxManage modifyvm "$vc_basebox" --nic1 nat | |
VBoxManage startvm "$vc_basebox" | |
ruby -rsocket -e 'puts "Kickstart URL: ks=http://" + IPSocket.getaddress(Socket.gethostname) + ":8000/vagrant-centos.ks"' | |
ruby -rwebrick -e 's=WEBrick::HTTPServer.new(:Port=>8000,:DocumentRoot=>".");trap("INT") { s.shutdown }; s.start' | |
vagrant package --base "$vc_basebox" --output "${vc_basebox}.box" | |
VBoxManage unregistervm "$vc_basebox" --delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment