# -*- 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.13.0
revision            0
categories          net
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  8e68912ee50219dd8f48141ec68ee1ac23bc5b77 \
                    sha256  83181b9cfee9495076f124926b28259e7f3911c4da80e17883c211c7e17cd04e \
                    size    1575303

depends_lib         port:libevent \
                    port:protobuf-c \
                    port:fstrm \
                    path:lib/libssl.dylib:openssl

depends_build       path:bin/pkg-config:pkgconfig
                    
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/manual/manpages/*] ${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
