# -*- 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            dspam
version         3.10.2
revision        2
categories      mail net
license         AGPL-3
maintainers     nomaintainer
description     Scalable, open-source statistical anti-spam filter
long_description Open-source anti-spam filter with multiple algorithms and \
                 useful admin tools and cgi quarantine interface.

homepage        http://dspam.sourceforge.net/
platforms       darwin freebsd
master_sites    sourceforge:project/dspam/dspam/dspam-${version}

checksums       md5 0e0e405d3284485b2a43f47eaf6b09bb \
                sha1 21133e0ee1880f3e8c849365b7e27a73f6d0413a \
                rmd160 7e112981e45e483350b9afc056ebfa4c5561036c

configure.args  --sysconfdir='${prefix}/etc' \
                --mandir='${prefix}/share/man' \
                --with-logdir=${prefix}/var/log/dspam \
                --enable-daemon

destroot.keepdirs       ${destroot}${prefix}/var/log/dspam

set storage-driver "hash_drv"
# if {[variant_isset mysql5]} {
#     set storage-driver   "${storage-driver},mysql_drv"
# }
if {[variant_isset sqlite]} {
    set storage-driver   "${storage-driver},sqlite3_drv"
}
# if {[variant_isset postgres]} {
#     set storage-driver   "${storage-driver},pgsql_drv"
# }
configure.args-append \
                    --with-storage-driver=${storage-driver}
# if {[variant_isset mysql5] || [variant_isset postgres]} {
#
#     configure.args-append \
#                     --enable-preferences-extension \
#                     --enable-virtual-users
# }

variant vpopmail description {Configure dspam to work with vpopmail} {
                configure.args-append --with-dspam-home-owner=vpopmail \
                                      --with-dspam-home-group=vchkpw \
                                      --with-dspam-owner=vpopmail \
                                      --with-dspam-group=vchkpw
                depends_lib     port:vpopmail
}

# variant mysql5 description {Configure dspam to work with mysql5} {
#                 depends_lib     path:bin/mysql_config5:mysql5
#                 configure.args-append --with-mysql-includes=${prefix}/include/mysql5/mysql \
#                                       --with-mysql-libraries=${prefix}/lib/mysql5/mysql
# }

variant sqlite description {Configure dspam to work with sqlite} {
                depends_lib     port:sqlite3
                configure.args-append --with-sqlite-libraries=${prefix}/lib
}
# variant postgres description {Configure dspam to work with postgresql80} {
#                 depends_lib     port:postgresql80
#                 configure.args-append --with-pgsql-includes=${prefix}/include/postgresql80 \
#                                       --with-pgsql-libraries=${prefix}/lib/postgresql80
# }

variant debug description {add debug capabilities} {
                configure.args-append --enable-debug \
                                      --enable-verbose-debug
}

post-destroot {
        file rename ${destroot}${prefix}/etc/dspam.conf ${destroot}${prefix}/etc/dspam.conf.sample
        file mkdir ${destroot}${prefix}/var/dspam/samples
        file mkdir ${destroot}${prefix}/share/doc/dspam
        file mkdir ${destroot}${prefix}/var/dspam/mysql
        file mkdir ${destroot}${prefix}/var/dspam/pgsql
        file mkdir ${destroot}${prefix}/var/dspam/sqlite
        file mkdir ${destroot}${prefix}/var/dspam/webui
        file mkdir ${destroot}${prefix}/var/dspam/webui/cgi-bin
        file mkdir ${destroot}${prefix}/var/dspam/webui/htdocs
        file copy ${worksrcpath}/README ${destroot}${prefix}/share/doc/dspam/
        file copy ${worksrcpath}/UPGRADING ${destroot}${prefix}/share/doc/dspam/
        file copy ${worksrcpath}/RELEASE.NOTES ${destroot}${prefix}/share/doc/dspam/
        file copy ${worksrcpath}/CHANGELOG ${destroot}${prefix}/share/doc/dspam/
        system "cp -R ${worksrcpath}/webui/cgi-bin/* ${destroot}${prefix}/var/dspam/webui/cgi-bin/"
        system "rm ${destroot}${prefix}/var/dspam/webui/cgi-bin/Make*"
        system "cp -R ${worksrcpath}/webui/htdocs/* ${destroot}${prefix}/var/dspam/webui/htdocs/"
        system "rm ${destroot}${prefix}/var/dspam/webui/htdocs/Make*"
        system "cp ${worksrcpath}/txt/*.txt ${destroot}${prefix}/var/dspam/samples/"
        system "cp ${worksrcpath}/doc/*.txt ${destroot}${prefix}/share/doc/dspam/"
        system "cp -R ${worksrcpath}/src/tools.mysql_drv/*sql ${destroot}${prefix}/var/dspam/mysql"
        system "cp -R ${worksrcpath}/src/tools.pgsql_drv/*sql ${destroot}${prefix}/var/dspam/pgsql"
        system "cp -R ${worksrcpath}/src/tools.sqlite_drv/*sql ${destroot}${prefix}/var/dspam/sqlite"
        if {[variant_isset vpopmail]} {
                system "chown -R vpopmail:vchkpw ${destroot}${prefix}/var/dspam"
                system "chown -R vpopmail:vchkpw ${destroot}${prefix}/var/log/dspam"
        }
}

startupitem.create      yes
startupitem.executable  ${prefix}/bin/dspam --daemon --nofork

notes "
Please create the dspam configuration file ${prefix}/etc/dspam.conf\
by using the sample file ${prefix}/etc/dspam.conf.sample as a reference
"

livecheck.url   http://sourceforge.net/projects/dspam/files/dspam/
livecheck.regex "${name}-((?!.*${name}.*|\\${extract.suffix}).*)\\${extract.suffix}"
