# -*- 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
# check if legacysupport is necessary when updating to 1.3.10
# https://github.com/proftpd/proftpd/issues/1879
# https://github.com/proftpd/proftpd/issues/1881
PortGroup           legacysupport 1.1

# dprintf
legacysupport.newest_darwin_requires_legacy 10

name                proftpd
version             1.3.9
revision            0
checksums           rmd160  3cd0a88329a73761e272828a6cc5e4c168e62379 \
                    sha256  4a5f13b666226813b4da0ade34535d325e204ab16cf8008c7353b1b5a972f74b \
                    size    19837398

categories          net
license             GPL-2+
maintainers         {@BjarneDMat mathiesen.info:macintosh} openmaintainer

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

# remove the following line when updating to 1.3.10
use_autoconf        yes
configure.args      --sysconfdir=${prefix}/etc/${name} \
                    --localstatedir=${prefix}/var/run/${name} \
                    --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 {
    if {[lsearch -glob ${modules} mod_sql_*] != -1} {
        lappend modules mod_sql mod_sql_passwd
        configure.args-append   --enable-openssl
    }
    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/${name}
    touch ${destroot}${prefix}/var/run/${name}/${name}.scoreboard
}

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

post-activate {
    # move the .conf from an old install
    if {[file exists ${prefix}/etc/${name}.conf]} {
        move ${prefix}/etc/${name}.conf ${prefix}/etc/${name}/${name}.conf
    }
    if {![file exists ${prefix}/etc/${name}/${name}.conf]} {
        copy ${prefix}/etc/${name}/${name}.conf.dist ${prefix}/etc/${name}/${name}.conf
    }
}

variant mysql57 conflicts mysql8 sqlite3 postgresql13 postgresql14 postgresql15 postgresql16 postgresql17 description {Build with mysql 5.7 support} {
    set my_db mysql57
    depends_lib-append      port:${my_db}
    lappend modules mod_sql_mysql
    lappend includes ${prefix}/include/${my_db}/mysql
    lappend libs ${prefix}/lib/${my_db}/mysql
}

variant mysql8 conflicts mysql57 sqlite3 postgresql13 postgresql14 postgresql17 postgresql17 postgresql17 description {Build with mysql 8 support} {
    set my_db mysql8
    depends_lib-append      port:${my_db}
    lappend modules mod_sql_mysql
    lappend includes ${prefix}/include/${my_db}/mysql
    lappend libs ${prefix}/lib/${my_db}/mysql
}

# https://www.postgresql.org/support/versioning/
variant postgresql13 conflicts mysql57 mysql8 sqlite3 postgresql14 postgresql15 postgresql16 postgresql17 description {Build with PostgreSQL 13 support} {
    set my_db postgresql13
    depends_lib-append      port:${my_db}
    lappend modules mod_sql_postgres
    lappend includes ${prefix}/include/${my_db}
    lappend libs ${prefix}/lib/${my_db}
}

variant postgresql14 conflicts mysql57 mysql8 sqlite3 postgresql13 postgresql15 postgresql16 postgresql17 description {Build with PostgreSQL 14 support} {
    set my_db postgresql14
    depends_lib-append      port:${my_db}
    lappend modules mod_sql_postgres
    lappend includes ${prefix}/include/${my_db}
    lappend libs ${prefix}/lib/${my_db}
}

variant postgresql15 conflicts mysql57 mysql8 sqlite3 postgresql13 postgresql14 postgresql16 postgresql17 description {Build with PostgreSQL 15 support} {
    set my_db postgresql15
    depends_lib-append      port:${my_db}
    lappend modules mod_sql_postgres
    lappend includes ${prefix}/include/${my_db}
    lappend libs ${prefix}/lib/${my_db}
}

variant postgresql16 conflicts mysql57 mysql8 sqlite3 postgresql13 postgresql14 postgresql15 postgresql17 description {Build with PostgreSQL 16 support} {
    set my_db postgresql16
    depends_lib-append      port:${my_db}
    lappend modules mod_sql_postgres
    lappend includes ${prefix}/include/${my_db}
    lappend libs ${prefix}/lib/${my_db}
}

variant postgresql17 conflicts mysql57 mysql8 sqlite3 postgresql13 postgresql14 postgresql15 postgresql16 description {Build with PostgreSQL 17 support} {
    set my_db postgresql17
    depends_lib-append      port:${my_db}
    lappend modules mod_sql_postgres
    lappend includes ${prefix}/include/${my_db}
    lappend libs ${prefix}/lib/${my_db}
}

variant sqlite3 conflicts mysql57 mysql8 postgresql13 postgresql14 postgresql15 postgresql16 postgresql17 description {Build with sqlite3 support} {
    depends_lib-append      port:sqlite3
    lappend modules mod_sql_sqlite
}

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

    notes "
On activation, if no ${prefix}/etc/${name}/${name}.conf file exists,
one will be created

If a ${prefix}/etc/${name}/${name}.cnf file exists, MacPorts does not
touch it, and any changes you make to ${prefix}/etc/${name}/${name}.cnf
will be preserved (e.g., during port upgrades, deactivations or
activations).

If you are upgrading from 1.3.8, the old  ${prefix}/etc/${name}.cnf
will be moved to ${prefix}/etc/${name}/${name}.cnf
"

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