1# 2# $FreeBSD$ 3# 4# Makefile for producing and uploading Vagrant boxes to Hashicorp Atlas 5# 6# Usage Example: 7# Create a Vagrant image for VirtualBox: 8# make vagrant-box WITH_VMIMAGES=y WITH_CLOUDWARE=y \ 9# CLOUDWARE=vagrant-virtualbox VMFORMATS=vmdk 10# 11# To create a Vagrant image for VMWare and Upload it to Atlas: 12# VAGRANT_KEY is your Atlas API Token 13# VAGRANT_USERNAME is your Atlas Username 14# env VAGRANT_KEY=foo VAGRANT_USERNAME=bar make vagrant-upload \ 15# WITH_VMIMAGES=y WITH_CLOUDWARE=y CLOUDWARE=vagrant-vmware \ 16# VMFORMATS=vmdk 17# For more info: https://www.vagrantup.com/docs/other/atlas.html 18# 19 20VAGRANT_IMG?= ${.OBJDIR}/vagrant.vmdk 21VAGRANT_UPLOAD_TGTS= vagrant-check-depends 22CLEANFILES+= ${VAGRANT_UPLOAD_TGTS} 23 24.if defined(VAGRANT_UPLOAD_CONF) && !empty(VAGRANT_UPLOAD_CONF) 25. for VAR in _KEY _USERNAME 26VAGRANT${VAR}!= grep -E ^VAGRANT${VAR} ${VAGRANT_UPLOAD_CONF} | awk -F' ' '{print $$2}' 27ATLAS${VAR}:= ${VAGRANT${VAR}} 28. endfor 29.endif 30 31.if ${BRANCH} == "STABLE" || ${BRANCH} == "CURRENT" || ${BRANCH} == "PRERELEASE" 32SNAPSHOT_DATE!= date +-${BUILDDATE} 33.endif 34 35VAGRANT_VERSION!= date +%Y.%m.%d 36VAGRANT_TARGET:= ${OSRELEASE}${SNAPSHOT_DATE} 37.if !empty(CLOUDWARE) 38. for _PROVIDER in ${CLOUDWARE} 39. if ${_PROVIDER:tu:MVAGRANT*} 40VAGRANT_PROVIDERS+= ${_PROVIDER:tu:S/VAGRANT-//:tl} 41. endif 42. endfor 43.endif 44VAGRANT_PROVIDERS?= vmware virtualbox 45 46 47vagrant-check-depends: 48.for VAR in _KEY _USERNAME _VERSION 49. if !defined(VAGRANT${VAR}) || empty(VAGRANT${VAR}) 50 @echo "Variable VAGRANT${VAR} cannot be empty." 51 @false 52. endif 53.endfor 54.if !exists(/usr/local/bin/curl) 55. if !exists(${PORTSDIR}/ftp/curl/Makefile) 56. if !exists(/usr/local/sbin/pkg-static) 57 env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf 58. endif 59 env ASSUME_ALWAYS_YES=yes pkg install -y curl 60. else 61 make -C ${PORTSDIR}/ftp/curl BATCH=1 all install clean 62. endif 63.endif 64 65.for PROVIDER in ${VAGRANT_PROVIDERS} 66CLEANFILES+= vagrant-do-package-${PROVIDER} ${VAGRANT_TARGET}.${PROVIDER}.box 67CLEANDIRS+= ${PROVIDER} 68VAGRANT_UPLOAD_TGTS+= vagrant-do-upload-${PROVIDER} 69 70${PROVIDER}: 71 @mkdir -p ${PROVIDER} 72 73${VAGRANT_TARGET}.${PROVIDER}.box: ${PROVIDER} cw-vagrant-${PROVIDER} vagrant-create-${PROVIDER}-metadata 74 @echo "==> PACKAGING: ${VAGRANT_TARGET}.${PROVIDER}.box in `pwd`" 75 @cp vagrant-${PROVIDER}.vmdk ${PROVIDER}/vagrant.vmdk 76. if ${PROVIDER} == "virtualbox" 77 @(cd ${.OBJDIR}/${PROVIDER} && echo '{"provider":"${PROVIDER}"}' > metadata.json) 78 @(cd ${.OBJDIR}/${PROVIDER} && tar -czf ../${VAGRANT_TARGET}.${PROVIDER}.box metadata.json box.ovf vagrant.vmdk) 79. elif ${PROVIDER} == "vmware" 80 @(cd ${.OBJDIR}/${PROVIDER} && echo '{"provider":"${PROVIDER}_desktop"}' > metadata.json) 81 @(cd ${.OBJDIR}/${PROVIDER} && tar -czf ../${VAGRANT_TARGET}.${PROVIDER}.box metadata.json vagrant.vmx vagrant.vmdk) 82. endif 83 84CLEANFILES+= vagrant-do-upload-${PROVIDER} 85vagrant-do-upload-${PROVIDER}: vagrant-box 86. if ${PROVIDER} == "virtualbox" 87 ${.CURDIR}/scripts/atlas-upload.sh -b ${TYPE}-${REVISION}-${BRANCH} -f ${VAGRANT_TARGET}.${PROVIDER}.box -p ${PROVIDER} -k ${VAGRANT_KEY} -u ${VAGRANT_USERNAME} -v ${VAGRANT_VERSION} 88. elif ${PROVIDER} == "vmware" 89 ${.CURDIR}/scripts/atlas-upload.sh -b ${TYPE}-${REVISION}-${BRANCH} -f ${VAGRANT_TARGET}.${PROVIDER}.box -p ${PROVIDER}_desktop -k ${VAGRANT_KEY} -u ${VAGRANT_USERNAME} -v ${VAGRANT_VERSION} 90. endif 91 touch ${.OBJDIR}/${.TARGET} 92 93vagrant-box: ${VAGRANT_TARGET}.${PROVIDER}.box 94 95.endfor 96 97vagrant-upload: ${VAGRANT_UPLOAD_TGTS} 98 99vagrant-create-virtualbox-metadata: virtualbox/box.ovf 100 101virtualbox/box.ovf: ${.CURDIR}/scripts/box.ovf 102 cp ${.ALLSRC} virtualbox/ 103 104vmware/vagrant.vmx: 105 @(cd vmware && echo '.encoding = "UTF-8"' > vagrant.vmx) 106 @(cd vmware && echo 'bios.bootorder = "hdd,CDROM"' >> vagrant.vmx) 107 @(cd vmware && echo 'checkpoint.vmstate = ""' >> vagrant.vmx) 108 @(cd vmware && echo 'cleanshutdown = "TRUE"' >> vagrant.vmx) 109 @(cd vmware && echo 'config.version = "8"' >> vagrant.vmx) 110 @(cd vmware && echo 'displayname = "${VAGRANT_TARGET}"' >> vagrant.vmx) 111 @(cd vmware && echo 'ethernet0.addresstype = "generated"' >> vagrant.vmx) 112 @(cd vmware && echo 'ethernet0.bsdname = "en0"' >> vagrant.vmx) 113 @(cd vmware && echo 'ethernet0.connectiontype = "nat"' >> vagrant.vmx) 114 @(cd vmware && echo 'ethernet0.displayname = "Ethernet"' >> vagrant.vmx) 115 @(cd vmware && echo 'ethernet0.linkstatepropagation.enable = "FALSE"' >> vagrant.vmx) 116 @(cd vmware && echo 'ethernet0.pcislotnumber = "33"' >> vagrant.vmx) 117 @(cd vmware && echo 'ethernet0.present = "TRUE"' >> vagrant.vmx) 118 @(cd vmware && echo 'ethernet0.virtualdev = "e1000"' >> vagrant.vmx) 119 @(cd vmware && echo 'ethernet0.wakeonpcktrcv = "FALSE"' >> vagrant.vmx) 120 @(cd vmware && echo 'floppy0.present = "FALSE"' >> vagrant.vmx) 121 @(cd vmware && echo 'guestos = "freebsd-64"' >> vagrant.vmx) 122 @(cd vmware && echo 'gui.fullscreenatpoweron = "FALSE"' >> vagrant.vmx) 123 @(cd vmware && echo 'gui.viewmodeatpoweron = "windowed"' >> vagrant.vmx) 124 @(cd vmware && echo 'memsize = "512"' >> vagrant.vmx) 125 @(cd vmware && echo 'sound.startconnected = "FALSE"' >> vagrant.vmx) 126 @(cd vmware && echo 'softpoweroff = "TRUE"' >> vagrant.vmx) 127 @(cd vmware && echo 'scsi0.pcislotnumber = "16"' >> vagrant.vmx) 128 @(cd vmware && echo 'scsi0.present = "TRUE"' >> vagrant.vmx) 129 @(cd vmware && echo 'scsi0.virtualdev = "lsilogic"' >> vagrant.vmx) 130 @(cd vmware && echo 'scsi0:0.filename = "vagrant.vmdk"' >> vagrant.vmx) 131 @(cd vmware && echo 'scsi0:0.present = "TRUE"' >> vagrant.vmx) 132 @(cd vmware && echo 'tools.synctime = "TRUE"' >> vagrant.vmx) 133 @(cd vmware && echo 'usb.present = "FALSE"' >> vagrant.vmx) 134 @(cd vmware && echo 'virtualhw.productcompatibility = "hosted"' >> vagrant.vmx) 135 @(cd vmware && echo 'virtualhw.version = "9"' >> vagrant.vmx) 136 137vagrant-create-vmware-metadata: vmware/vagrant.vmx 138