# -*- 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

# dprintf
legacysupport.newest_darwin_requires_legacy 10

name                proftpd
version             1.3.7b
revision            2
checksums           rmd160  6e923753558f28ed39f7efe0cf5f98e27c766b69 \
                    sha256  d1560d191f81ee9c0b295aea76f44e2d6c0b2d0f912c835c80bc1bbca473471e \
                    size    20422741

categories          net
license             GPL-2+
maintainers         nomaintainer
description         Highly configurable ftp-server.
long_description    ProFTPD is a highly configurable ftp daemon for unix \
                    and unix-like operating systems. ProFTPD is designed \
                    to be somewhat of a "drop-in" replacement for wu-ftpd \
                    with a configuration format like Apache.
homepage            http://www.proftpd.org
platforms           darwin freebsd
master_sites        ftp://ftp.proftpd.org/distrib/source/ \
                    ftp://ftp-stud.fht-esslingen.de/pub/Mirrors/ftp.proftpd.net/distrib/source/ \
                    ftp://mirror.hostfuss.com/proftpd/distrib/source/ \
                    ftp://ftp.piotrkosoft.net/pub/mirrors/ftp.proftpd.org/distrib/source/ \
                    ftp://proftpd.get7.biz/proftpd/distrib/source/ \
                    ftp://ftp.ibiblio.org/pub/mirrors/proftpd/distrib/source/ \
                    ftp://ftp.solnet.ch/mirror/proftpd.org/distrib/source/ \
                    gentoo

depends_build       port:libtool

depends_lib         port:libidn \
                    port:libsodium \
                    port:ncurses \
                    path:lib/libssl.dylib:openssl

patchfiles          dynamic_lookup-11.patch

configure.args      --sysconfdir=${prefix}/etc \
                    --localstatedir=${prefix}/var/run \
                    --mandir=${prefix}/share/man \
                    --enable-ctrls \
                    --enable-dso \
                    install_user=`id -u` \
                    install_group=`id -g`

# only one --with-modules arg can be used, likewise --with-{includes,libraries}
set modules [list mod_tls mod_sftp mod_sftp_pam mod_ban mod_ctrls_admin \
                  mod_dynmasq mod_exec mod_ifsession mod_load mod_log_forensic \
                  mod_qos mod_quotatab mod_quotatab_file mod_ratio mod_readme \
                  mod_rewrite mod_shaper mod_site_misc mod_unique_id]
set includes {}
set libs {}
pre-configure {
    configure.args-append --with-modules=[join $modules :]
    configure.args-append --with-shared=[join $modules :]
    if {$includes != {}} {
        configure.args-append --with-includes=[join $includes :]
    }
    if {$libs != {}} {
        configure.args-append --with-libraries=[join $libs :]
    }
}

pre-destroot {
    reinplace "s|nogroup|nobody|g" ${worksrcpath}/sample-configurations/basic.conf
    xinstall -m 755 -d ${destroot}${prefix}/var/run/proftpd
    touch ${destroot}${prefix}/var/run/proftpd/proftpd.scoreboard
}

post-destroot {
    move ${destroot}${prefix}/etc/proftpd.conf ${destroot}${prefix}/etc/proftpd.conf.dist
    move ${destroot}${prefix}/var/run/proftpd/proftpd.scoreboard ${destroot}${prefix}/var/run/proftpd/proftpd.scoreboard.dist
}

post-activate {
    if {![file exists ${prefix}/etc/proftpd.conf]} {
        copy ${prefix}/etc/proftpd.conf.dist ${prefix}/etc/proftpd.conf
    }
}

variant mysql57 conflicts postgresql11 sqlite3 description {Build with mysql 5.7 support} {
    depends_lib-append   port:mysql57
    lappend modules mod_sql mod_sql_mysql
    lappend includes ${prefix}/include/mysql57/mysql
    lappend libs ${prefix}/lib/mysql57/mysql
}

variant postgresql11 conflicts mysql57 sqlite3 description {Build with PostgreSQL 11 support} {
    depends_lib-append      port:postgresql11
    lappend modules mod_sql mod_sql_postgres
    lappend includes ${prefix}/include/postgresql11
    lappend libs ${prefix}/lib/postgresql11
}

variant sqlite3 conflicts mysql57 postgresql11 description {Build with sqlite3 support} {
    depends_lib-append      port:sqlite3
    lappend modules mod_sql mod_sql_sqlite
}

variant quotatab description {Build with SQL quota support} {
    lappend modules mod_quotatab mod_quotatab_sql
}

startupitem.create  yes
startupitem.start   "${prefix}/sbin/proftpd"
startupitem.restart "/bin/kill -HUP \$(/bin/cat ${prefix}/var/run/proftpd.pid)"
startupitem.stop    "/bin/kill -15 \$(/bin/cat ${prefix}/var/run/proftpd.pid)"
