# -*- 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
PortGroup           legacysupport 1.1

name                opensmtpd
version             7.8.0p0
revision            0
categories          mail
license             ISC
maintainers         {@ryanakca debian.org:rak} {@artkiver gmail.com:artkiver}
description         secure, reliable, lean, and easy-to configure SMTP server
long_description    The OpenSMTPD server seeks to be \
                    \n* as secure as possible, and uses privilege separation to mitigate \
                    \n  possible security bugs \
                    \n* as reliable as possible: any accepted email must not be lost \
                    \n* lean: it covers typical usage cases instead of every obscure one \
                    \n* easy to configure, with a configuration syntax reminiscent of the OpenBSD \
                    \n  Packet Filter's (PF) \
                    \n* fast and efficient: it can handle large queues with reasonable performance
homepage            https://www.opensmtpd.org

master_sites        https://opensmtpd.org/archives/

checksums           rmd160  d5b2093c11bf0f1fb5fe4559932230abf9e26e4c \
                    sha256  4034de2e92c61fa83eedadb1d8d8bdfe65e57eb50ce9679e0140950e34ca4ab7 \
                    size    744995

depends_build       port:bison

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

startupitem.create      yes
startupitem.executable  ${prefix}/sbin/smtpd -F

add_users           _smtpd group=_smtpd realname=OpenSMTP\ Daemon \
                    _smtpq group=_smtpq realname=OpenSMTP\ Queue

set sysconfdir ${prefix}/etc/${name}

post-patch {
    reinplace "s|file:/etc/mail/aliases|file:${sysconfdir}/aliases|g" ${worksrcpath}/usr.sbin/smtpd/smtpd.conf
}

 
depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:libtool

configure.args      --sysconfdir=${sysconfdir} \
                    --with-auth-pam \
                    --with-libevent=${prefix} \
                    --with-mantype=doc \
                    --with-path-queue=${prefix}/var/spool/smtpd \
                    --with-table-db

# The spool directory *must* be installed with uid/gid 0.
# OpenSMTPD checks these permissions at startup (queue_backend.c, using ckdir
# from util.c), and aborts if they are not correctly set. Consequently,
# opensmtpd must be installed as root
destroot.asroot     yes
destroot.keepdirs   ${destroot}${prefix}/var/spool/smtpd

post-destroot {
    xinstall -o root -g wheel -m 711 -d ${destroot}${prefix}/var/spool/smtpd
    file rename ${destroot}${sysconfdir}/smtpd.conf ${destroot}${sysconfdir}/smtpd.conf.dist

    file link -symbolic ${destroot}${prefix}/sbin/sendmail smtpctl
    file link -symbolic ${destroot}${prefix}/sbin/mailq smtpctl
    file link -symbolic ${destroot}${prefix}/sbin/makemap smtpctl
    file link -symbolic ${destroot}${prefix}/sbin/newaliases smtpctl
}

post-activate {
    if {![file exists ${sysconfdir}/smtpd.conf]} {
        file copy ${sysconfdir}/smtpd.conf.dist ${sysconfdir}/smtpd.conf
    }
    if {![file exists ${sysconfdir}/aliases] && [file exists /etc/postfix/aliases]} {
        file copy /etc/postfix/aliases ${sysconfdir}/aliases
    }
}

notes "
    Both OpenSMTPD and the built-in Postfix daemon listen on port 25 by\
    default. The easiest way to avoid this conflict is to change the\
    inet_interfaces setting in /etc/postfix/main.cf to keep Postfix from\
    listening to the same interfaces as OpenSMTPD, and then restarting Postfix.\
    To keep Postfix from listening on any interfaces, it is sufficient to set:

        inet_interfaces =

    Please see postconf(5) for more details.
"

livecheck.url       https://opensmtpd.org/archives/
livecheck.type      regex
livecheck.regex     opensmtpd-(\[0-9p.\]+)\\.tar\\.gz
