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