# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                nsd
version             4.3.8
revision            0
categories          net
platforms           darwin
license             BSD
maintainers         {rna.nl:gerben.wierda @gctwnl} openmaintainer

description         Authoritative only, high performance, simple name server.
long_description    NSD is an authoritative only, high performance, simple and \
    open source name server.

set nsduser         nsd
set nsdgroup        nsd

homepage            https://www.nlnetlabs.nl/projects/nsd/about/
master_sites        https://www.nlnetlabs.nl/downloads/nsd/

checksums           rmd160  f7f0af8d12b819b435134d516bef769e596af1ee \
                    sha256  11897e25f72f5a98f9202bd5378c936886d54376051a614d3688e451e9cb99e1 \
                    size    1225840

depends_lib         port:libevent \
                    path:lib/libssl.dylib:openssl

configure.args      --with-ssl=${prefix} \
                    --with-pidfile=${prefix}/var/run/nsd/nsd.pid

platform darwin {
    configure.cppflags-append -D_DARWIN_C_SOURCE
}

add_users ${nsduser} group=${nsdgroup} shell=/sbin/nologin \
    realname=NSD\ Server home=${prefix}/var/db/nsd

post-destroot {
    xinstall -d ${destroot}${prefix}/share/doc/nsd
    xinstall -m 644 {*}[glob ${worksrcpath}/doc/*] ${destroot}${prefix}/share/doc/nsd
    xinstall -o ${nsduser} -g ${nsdgroup} -m 755 -d ${destroot}${prefix}/var/db/nsd
    xinstall -o ${nsduser} -g ${nsdgroup} -m 755 -d ${destroot}${prefix}/var/run/nsd
}

destroot.keepdirs   ${destroot}${prefix}/var/run/nsd \
                    ${destroot}${prefix}/var/db/nsd

variant rootserver description {Allows NSD to function as a root server} {
    configure.args-append   --enable-root-server
}

variant stats description {Enable BIND8-style statistics} {
    configure.args-append   --enable-bind8-stats
}

livecheck.type  regex
livecheck.url   ${master_sites}
livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"

# Make it run at boot
# Redirect stderr on launchd-started items because launchd redirects stderr to a black hole
# Let macports (daemondo) manage the availability of process and pidfile (works without for now, but is more robust)
startupitem.create	yes
startupitem.name	nsd
startupitem.logfile	/Library/Logs/nsd-startupitem.log
startupitem.logevents	yes
startupitem.start	"(${prefix}/sbin/nsd 2>&1)"
startupitem.stop	"(/bin/kill \$(cat ${prefix}/var/run/${name}/${name}.pid) 2>&1)"
startupitem.pidfile	clean ${prefix}/var/run/${name}/${name}.pid
