-
-
Save raphaelkong/54bc20b3e83cb5c2f45b to your computer and use it in GitHub Desktop.
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
| BOX_NAME=vagrant-build | |
| BASE_DIR="`pwd`/machines" | |
| BOX_DIR="${BASE_DIR}/${BOX_NAME}" | |
| mkdir -p ${BASE_DIR} | |
| VBoxManage createvm --name "${BOX_NAME}" --ostype RedHat_64 --basefolder ${BASE_DIR} | |
| VBoxManage registervm "${BOX_DIR}/${BOX_NAME}.vbox" | |
| mkdir -p tmp | |
| rm -rf tmp/clone.vdi | |
| VBoxManage clonehd latest.vmdk tmp/clone.vdi --format vdi | |
| VBoxManage modifyhd tmp/clone.vdi --resize 20480 | |
| VBoxManage clonehd tmp/clone.vdi "${BOX_DIR}/${BOX_NAME}.vmdk" --format vmdk | |
| VBoxManage -q closemedium disk tmp/clone.vdi | |
| rm -f tmp/clone.vdi | |
| VBoxManage storagectl "${BOX_NAME}" --name LsiLogic --add scsi --controller LsiLogic | |
| VBoxManage storageattach "${BOX_NAME}" --storagectl LsiLogic --port 0 --device 0 --type hdd --medium "${BOX_DIR}/${BOX_NAME}.vmdk" | |
| VBoxManage setextradata "${BOX_NAME}" "VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/Protocol" TCP | |
| VBoxManage setextradata "${BOX_NAME}" "VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/GuestPort" 22 | |
| VBoxManage setextradata "${BOX_NAME}" "VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/HostPort" 22222 | |
| VBoxManage modifyvm "${BOX_NAME}" --usb on --usbehci on | |
| VBoxManage modifyvm "${BOX_NAME}" --memory 512 | |
| VBoxManage startvm "${BOX_NAME}" #--type headless | |
| echo "Sleeping to give machine time to boot" | |
| sleep 60 | |
| echo "Uploading ssh key & creating vagrant user" | |
| cat ~/.ssh/vagrant.pub | ssh -p 22222 root@localhost "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" | |
| ssh -p 22222 root@localhost <<EOT | |
| useradd vagrant | |
| echo vagrant | passwd vagrant --stdin | |
| umask 077 | |
| test -d /home/vagrant/.ssh || mkdir -p /home/vagrant/.ssh | |
| cp ~/.ssh/authorized_keys /home/vagrant/.ssh | |
| chown -R vagrant:vagrant /home/vagrant/.ssh | |
| EOT | |
| scp -P 22222 templates/sudoers root@localhost:/etc/sudoers | |
| echo -n "Waiting for machine to shutdown" | |
| VBoxManage controlvm ${BOX_NAME} acpipowerbutton | |
| while [ `VBoxManage showvminfo --machinereadable ${BOX_NAME} | grep VMState=` != 'VMState="poweroff"' ]; do | |
| echo -n . | |
| sleep 1 | |
| done | |
| echo "Done" | |
| vagrant package --base ${BOX_NAME} --output ${BOX_NAME}.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
| BOX_NAME=vagrant-build | |
| BASE_DIR="`pwd`/machines" | |
| BOX_DIR="${BASE_DIR}/${BOX_NAME}" | |
| mkdir -p ${BASE_DIR} | |
| VBoxManage createvm --name "${BOX_NAME}" --ostype RedHat_64 --basefolder ${BASE_DIR} | |
| VBoxManage registervm "${BOX_DIR}/${BOX_NAME}.vbox" |
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
| mkdir -p tmp | |
| rm -rf tmp/clone.vdi | |
| VBoxManage clonehd latest.vmdk tmp/clone.vdi --format vdi | |
| VBoxManage modifyhd tmp/clone.vdi --resize 20480 | |
| VBoxManage clonehd tmp/clone.vdi "${BOX_DIR}/${BOX_NAME}.vmdk" --format vmdk | |
| VBoxManage -q closemedium disk tmp/clone.vdi | |
| rm -f tmp/clone.vdi | |
| VBoxManage storagectl "${BOX_NAME}" --name LsiLogic --add scsi --controller LsiLogic | |
| VBoxManage storageattach "${BOX_NAME}" --storagectl LsiLogic --port 0 --device 0 --type hdd --medium "${BOX_DIR}/${BOX_NAME}.vmdk" |
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
| cp latest.vmdk "${BOX_DIR}/${BOX_NAME}.vmdk" | |
| VBoxManage storagectl "${BOX_NAME}" --name LsiLogic --add scsi --controller LsiLogic | |
| VBoxManage storageattach "${BOX_NAME}" --storagectl LsiLogic --port 0 --device 0 --type hdd --medium "${BOX_DIR}/${BOX_NAME}.vmdk" |
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
| VBoxManage setextradata "${BOX_NAME}" "VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/Protocol" TCP | |
| VBoxManage setextradata "${BOX_NAME}" "VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/GuestPort" 22 | |
| VBoxManage setextradata "${BOX_NAME}" "VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/HostPort" 22222 |
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
| VBoxManage modifyvm "${BOX_NAME}" --usb on --usbehci on | |
| VBoxManage modifyvm "${BOX_NAME}" --memory 512 |
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
| VBoxManage startvm "${BOX_NAME}" #--type headless | |
| echo "Sleeping to give machine time to boot" | |
| sleep 60 |
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
| echo "Uploading ssh key & creating vagrant user" | |
| cat ~/.ssh/vagrant.pub | ssh -p 22222 root@localhost "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" | |
| ssh -p 22222 root@localhost <<EOT | |
| useradd vagrant | |
| echo vagrant | passwd vagrant --stdin | |
| umask 077 | |
| test -d /home/vagrant/.ssh || mkdir -p /home/vagrant/.ssh | |
| cp ~/.ssh/authorized_keys /home/vagrant/.ssh | |
| chown -R vagrant:vagrant /home/vagrant/.ssh | |
| EOT | |
| scp -P 22222 templates/sudoers root@localhost:/etc/sudoers |
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
| echo -n "Waiting for machine to shutdown" | |
| VBoxManage controlvm ${BOX_NAME} acpipowerbutton | |
| while [ `VBoxManage showvminfo --machinereadable ${BOX_NAME} | grep VMState=` != 'VMState="poweroff"' ]; do | |
| echo -n . | |
| sleep 1 | |
| done | |
| echo "Done" | |
| vagrant package --base ${BOX_NAME} --output ${BOX_NAME}.box |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment