PORTNAME=	lego
DISTVERSIONPREFIX=	v
DISTVERSION=	4.35.2
PORTREVISION=	1
CATEGORIES=	security

MAINTAINER=	matt@matthoran.com
COMMENT=	Let's Encrypt client and ACME library written in Go
WWW=		https://github.com/go-acme/lego

LICENSE=	MIT
LICENSE_FILE=	${WRKSRC}/LICENSE

RUN_DEPENDS=	${LOCALBASE}/share/certs/ca-root-nss.crt:security/ca_root_nss

USES=		go:modules
GO_MODULE=	github.com/go-acme/lego/v4
GO_TARGET=	./cmd/lego
GO_BUILDFLAGS=	-ldflags '-X "main.version=${DISTVERSION}"'

SAMPLE_FILES=	deploy.sh.sample lego.sh.sample
SUB_FILES=	${SAMPLE_FILES} 604.lego pkg-message
SUB_LIST=	LEGO_USER=${LEGO_USER} \
		PORTNAME=${PORTNAME}

LEGO_USER?=	_lego
.if ${LEGO_USER} == _lego
USERS=		${LEGO_USER}
GROUPS=		${LEGO_USER}
.endif
GROUPS+=	www
PLIST_SUB=	LEGO_USER=${LEGO_USER}

PERIODIC_DIRS=	etc/periodic/weekly
PERIODIC_FILES=	604.lego

post-install:
	${MKDIR} ${STAGEDIR}${PREFIX}/${PERIODIC_DIRS} \
		 ${STAGEDIR}${PREFIX}/etc/ssl/lego \
		 ${STAGEDIR}${ETCDIR} \
		 ${STAGEDIR}${WWWDIR}
	${INSTALL_SCRIPT} ${WRKDIR}/${PERIODIC_FILES} ${STAGEDIR}${PREFIX}/${PERIODIC_DIRS}
	${INSTALL_SCRIPT} ${SAMPLE_FILES:C|^|${WRKDIR}/|} ${STAGEDIR}${ETCDIR}

.include <bsd.port.mk>
