1# 2# $FreeBSD$ 3# 4# 5# Makefile for uploading Google Compute Engine disk images. 6# 7 8GCE_IMG?= ${.OBJDIR}/gce.raw 9GCE_UPLOAD_TGTS= gce-check-depends \ 10 gce-do-package \ 11 gce-do-upload 12# I do not yet have a better way to deal with the "must be run interactively" 13# thing, so this is a fail-safe "do not do anything." 14.if !defined(GCE_LOGIN_SKIP) || empty(GCE_LOGIN_SKIP) 15GCE_UPLOAD_TGTS= gce-do-login 16.endif 17CLEANFILES+= ${GCE_UPLOAD_TGTS} 18 19GCE_BUCKET?= 20 21.if !defined(GCE_FAMILY) || empty(GCE_FAMILY) 22GCE_FAMILY= ${TYPE:tl}-${REVISION:S,.,-,} 23.endif 24 25.if ${BRANCH} == "STABLE" || ${BRANCH} == "CURRENT" || ${BRANCH} == "PRERELEASE" 26SNAPSHOT_DATE!= date +-%Y-%m-%d 27GCE_FAMILY_SUFX= -snap 28.endif 29 30# Really? Uppercase characters are not allowed? Sigh... 31# And don't even get me started on the '.'. 32GCE_TARGET:= ${OSRELEASE:S,.raw,,:tl:S,.,-,g}${SNAPSHOT_DATE} 33 34gce-upload: ${GCE_UPLOAD_TGTS} 35 36gce-check-depends: 37.for VAR in _BUCKET 38. if !defined(GCE${VAR}) || empty(GCE${VAR}) 39 @echo "Variable GCE${VAR} cannot be empty." 40 @false 41. endif 42.endfor 43.if !exists(/usr/local/bin/gcloud) 44. if !exists(${PORTSDIR}/net/google-cloud-sdk/Makefile) 45. if !exists(/usr/local/sbin/pkg-static) 46 env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf 47. endif 48 env ASSUME_ALWAYS_YES=yes pkg install -y net/google-cloud-sdk 49. else 50 make -C ${PORTSDIR}/net/google-cloud-sdk BATCH=1 all install clean 51. endif 52.endif 53 54gce-do-package: 55 @# Yes, really... Sigh. 56 cd ${.OBJDIR} && mv gce.raw disk.raw 57 cd ${.OBJDIR} && tar --format=gnutar -zcf \ 58 ${GCE_TARGET:S,${.OBJDIR}/,,}.tar.gz disk.raw 59 cd ${.OBJDIR} && mv disk.raw gce.raw 60 touch ${.OBJDIR}/${.TARGET} 61 62gce-do-login: 63 @echo "This requires human interaction, which is not yet supported." 64 @true 65 66gce-do-upload: 67 @# Fallthrough in case the bucket already exists. 68 /usr/local/bin/gsutil mb gs://${GCE_BUCKET} || true 69 /usr/local/bin/gsutil cp ${.OBJDIR}/${GCE_TARGET}.tar.gz \ 70 gs://${GCE_BUCKET}/ 71 /usr/local/bin/gcloud compute images create ${GCE_TARGET} \ 72 --family=${GCE_FAMILY}${GCE_FAMILY_SUFX} \ 73 --source-uri gs://${GCE_BUCKET}/${GCE_TARGET}.tar.gz 74 touch ${.OBJDIR}/${.TARGET} 75 76