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

PortSystem          1.0

name                vsftpd
version             3.0.2
revision            1
categories          net
license             {GPL-2 OpenSSLException}
platforms           darwin
maintainers         nomaintainer

description         Secure FTP server for UNIX systems
long_description    vsftpd is an FTP server, or daemon. The 'vs' stands for \
                    Very Secure. Obviously this is not a guarantee, but a \
                    reflection that it is written with security in mind, and \
                    carefully designed to be resilient to attack.

homepage            https://security.appspot.com/vsftpd.html
master_sites        https://security.appspot.com/downloads/

checksums           md5     8b00c749719089401315bd3c44dddbb2 \
                    sha1    f36976bb1c5df25ac236d8a29e965ba2b825ccd0 \
                    rmd160  35005dcc03537259338b5ea199df679221df362f
                    
patchfiles          patch-sysdeputil.c.diff \
                    patch-vsf_findlibs.sh.diff \
                    patch-vsftpd.conf.diff \
                    patch-Makefile.diff

configure {
    reinplace "s|/etc/|${prefix}/etc/|g" \
        ${worksrcpath}/Makefile \
        ${worksrcpath}/defs.h \
        ${worksrcpath}/tunables.c \
        ${worksrcpath}/vsftpd.8 \
        ${worksrcpath}/vsftpd.conf
    reinplace "s|/var/|${prefix}/var/|g" \
        ${worksrcpath}/tunables.c \
        ${worksrcpath}/vsftpd.conf.5 \
        ${worksrcpath}/vsftpd.conf
    reinplace "s|/usr/share/empty|${prefix}/var/empty|g" \
        ${worksrcpath}/tunables.c
    reinplace "s|/usr/share/ssl/|${prefix}/share/ssl/|g" \
        ${worksrcpath}/tunables.c
    reinplace "s|/etc/vsftpd|${prefix}/etc/vsftpd|g" \
        ${worksrcpath}/vsftpd.conf.5

    reinplace "s|/usr/local/man|${destroot}${prefix}/share/man|g" \
        ${worksrcpath}/Makefile
    reinplace "s|/usr/local|${destroot}${prefix}|g" \
        ${worksrcpath}/Makefile
    reinplace "s|-Werror||g" ${worksrcpath}/Makefile
}

build.target

startupitem.create yes
startupitem.name ${name}
startupitem.executable ${prefix}/sbin/${name} ${prefix}/etc/${name}.conf

post-destroot {
    xinstall ${worksrcpath}/vsftpd.conf ${destroot}${prefix}/etc/vsftpd.conf.sample
    set docdir ${destroot}${prefix}/share/doc/${name}-${version}
    xinstall -d ${docdir}
    xinstall -m 644 -W ${worksrcpath} AUDIT BENCHMARKS BUGS COPYING FAQ LICENSE \
        README README.security README.ssl SIZE SPEED TODO TUNING \
        ${docdir}
    file copy ${worksrcpath}/EXAMPLE ${docdir}
    file copy ${worksrcpath}/SECURITY ${docdir}
}

post-activate {
    if {![file exists ${prefix}/etc/vsftpd.conf]} {
        copy ${prefix}/etc/vsftpd.conf.sample \
            ${prefix}/etc/vsftpd.conf
    }
}

destroot.keepdirs   "${destroot}${prefix}/var/empty/" \
                    "${destroot}${prefix}/var/log/"

variant ssl description "Enable SSL support" {
    depends_lib-append  path:lib/libssl.dylib:openssl

    post-configure {
        reinplace "s|#undef VSF_BUILD_SSL|#define VSF_BUILD_SSL|" \
        ${worksrcpath}/builddefs.h
    }

    build.env-append    LDFLAGS=${configure.ldflags}
}

platform darwin 9 {
    patchfiles-append oldpam.diff
}

notes               "To configure ${name} edit ${prefix}/etc/vsftpd.conf."

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "vsftpd-(\\d+(?:\\.\\d+)*)"