# -*- 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           perl5 1.0
PortGroup           github 1.0

github.setup        sympa-community sympa 6.2.68
revision            0
github.tarball_from releases

set branch          [join [lrange [split ${version} .] 0 1] .]
categories          mail
license             GPL-2
maintainers         nomaintainer
platforms           darwin

description         Sympa - Mailing List Manager with LDAP support

long_description    An advanced perl-based mail list manager with a web interface \
                    that supports LDAP authentication and LDAP extraction of \
                    list subscribers and owners.

checksums           rmd160  a88db306bea135ab97267eb174313d4441e52151 \
                    sha256  9ebd0afde966f2ba41c3897627df51a26d15fd641d50523e89a34db7b6aaad28 \
                    size    12997187

perl5.require_variant   yes
perl5.conflict_variants yes
perl5.branches          5.28 5.30 5.32 5.34
perl5.default_branch    5.34
perl5.create_variants   ${perl5.branches}

depends_lib         port:apache2 \
                    port:mod_fcgid \
                    path:lib/libssl.dylib:openssl \
                    port:postfix \
                    port:p${perl5.major}-archive-zip-simplezip \
                    port:p${perl5.major}-authcas \
                    port:p${perl5.major}-cgi \
                    port:p${perl5.major}-cgi-fast \
                    port:p${perl5.major}-class-singleton \
                    port:p${perl5.major}-clone \
                    port:p${perl5.major}-crypt-ciphersaber \
                    port:p${perl5.major}-crypt-eksblowfish \
                    port:p${perl5.major}-crypt-openssl-x509 \
                    port:p${perl5.major}-crypt-smime \
                    port:p${perl5.major}-data-password \
                    port:p${perl5.major}-datetime-format-mail \
                    port:p${perl5.major}-datetime-timezone \
                    port:p${perl5.major}-dbi \
                    port:p${perl5.major}-encode \
                    port:p${perl5.major}-encode-locale \
                    port:p${perl5.major}-fcgi \
                    port:p${perl5.major}-file-copy-recursive \
                    port:p${perl5.major}-file-nfslock \
                    port:p${perl5.major}-html-formatter \
                    port:p${perl5.major}-html-stripscripts-parser \
                    port:p${perl5.major}-html-tree \
                    port:p${perl5.major}-io-stringy \
                    port:p${perl5.major}-io-socket-ip \
                    port:p${perl5.major}-io-socket-ssl \
                    port:p${perl5.major}-libintl-perl \
                    port:p${perl5.major}-libwww-perl \
                    port:p${perl5.major}-lwp-protocol-https \
                    port:p${perl5.major}-mail-dkim \
                    port:p${perl5.major}-mailtools \
                    port:p${perl5.major}-mhonarc \
                    port:p${perl5.major}-mime-charset \
                    port:p${perl5.major}-mime-encwords \
                    port:p${perl5.major}-mime-lite-html \
                    port:p${perl5.major}-mime-tools \
                    port:p${perl5.major}-net-cidr \
                    port:p${perl5.major}-net-dns \
                    port:p${perl5.major}-perl-ldap \
                    port:p${perl5.major}-scalar-list-utils \
                    port:p${perl5.major}-soap-lite \
                    port:p${perl5.major}-template-toolkit \
                    port:p${perl5.major}-term-progressbar \
                    port:p${perl5.major}-time-hires \
                    port:p${perl5.major}-unicode-linebreak \
                    port:p${perl5.major}-unicode-normalize \
                    port:p${perl5.major}-unicode-utf8 \
                    port:p${perl5.major}-uri \
                    port:p${perl5.major}-xml-libxml

pre-patch {
    copy ${filespath}/httpd-sympa.conf ${worksrcpath}
}

patchfiles          patch-src-etc-script-sympa.in.diff

post-patch {
    reinplace "s|__MP_PREFIX__|${prefix}|" \
                    ${worksrcpath}/httpd-sympa.conf
    reinplace "s|#mhonarc|mhonarc|" \
                    ${worksrcpath}/sympa.conf.in
    reinplace "s|/usr/bin/mhonarc|${prefix}/bin/mhonarc-${perl5.major}|" \
                    ${worksrcpath}/sympa.conf.in \
                    ${worksrcpath}/t/data/sympa.conf
}

configure.args      --with-perl=${perl5.bin} \
                    --with-user=www \
                    --with-group=www \
                    --enable-fhs \
                    --sysconfdir=${prefix}/etc/${name} \
                    --with-cgidir=${prefix}/www/${name}/cgi \
                    --with-staticdir=${prefix}/www/${name}/static_content \
                    --with-aliases_file=${prefix}/etc/${name}/sympa_aliases

# Create a startupitem to start/stop/restart the server processes

startupitem.create  yes
startupitem.start   "${prefix}/etc/sympa/rc.d/init.d/sympa start"
startupitem.stop    "${prefix}/etc/sympa/rc.d/init.d/sympa stop"
startupitem.restart "${prefix}/etc/sympa/rc.d/init.d/sympa restart"
startupitem.pidfile auto ${prefix}/var/run/${name}/${name}.pid

set apache_name apache2
set extra       ${prefix}/etc/apache2/extra/
set httpd_conf  ${prefix}/etc/apache2/httpd.conf

# Keep these empty directories

destroot.keepdirs   ${destroot}${prefix}/etc/${name}/${name} \
                    ${destroot}${prefix}/var/lib/${name}/arc \
                    ${destroot}${prefix}/var/lib/${name}/bounce \
                    ${destroot}${prefix}/var/lib/${name}/list_data \
                    ${destroot}${prefix}/var/lock/subsys \
                    ${destroot}${prefix}/var/log/${name} \
                    ${destroot}${prefix}/var/run/${name} \
                    ${destroot}${prefix}/var/spool/${name}

post-destroot {
    xinstall -m 644 ${worksrcpath}/INSTALL.md ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${destroot}${extra}
    xinstall -m 644 ${worksrcpath}/httpd-sympa.conf ${destroot}${extra}
    delete  ${destroot}${prefix}/etc/sympa/sympa/sympa.conf
}

variant postgresql description {Install optional dependencies for PostgreSQL database support} {
    depends_lib-append \
                    port:p${perl5.major}-dbd-pg
}

variant sqlite description {Install optional dependencies for SQLite version 3 database support} {
    depends_lib-append \
                    port:p${perl5.major}-dbd-sqlite
}

# if neither postgresql nor sqlite selected default to mysql

if {![variant_isset postgresql] && ![variant_isset sqlite]} {
    depends_lib-append \
                    port:p${perl5.major}-dbd-mysql
}

post-activate {
#   create default configuration file if it doesn't already exist

    if {![file exists ${prefix}/etc/sympa/sympa/sympa.conf]} {
            system "${prefix}/sbin/sympa_wizard.pl --create sympa.conf"
    }
}

notes "
You can find the reference documentation at:
    https://sympa-community.github.io/manual/

Check that you have all the required perl modules:
    $ ${prefix}/sbin/sympa_wizard.pl --check

First installation:
    Review the installation instructions:
        https://sympa-community.github.io/manual/install.html
    Run the wizard to customize the default configuration files
        $ sudo ${prefix}/sbin/sympa_wizard.pl
    Create the sympa database and tables using the script for your database at
        ${prefix}/share/sympa/bin/create_db.*
    For example, if using MySQL, the appropriate command is
        $ mysql -u root -p  < ${prefix}/share/sympa/bin/create_db.mysql
    Create a database user with access to the sympa database. This should
    match to the parameters db_name, db_host, db_user and db_passwd
    in ${prefix}/etc/sympa/sympa.conf.
        $ mysql -u root -p
        mysql> CREATE USER 'sympa'@'localhost' IDENTIFIED BY 'my_password';
        mysql> GRANT ALL ON sympa.* TO 'sympa'@'localhost';
        mysql> FLUSH PRIVILEGES;
        mysql> quit
    Add these lines to the end of ${httpd_conf}
        # Include module mod_fcgid
        Include conf/extra/httpd-fcgid.conf
        # Include sympa configuration file
        Include conf/extra/httpd-sympa.conf
    You should then restart ${apache_name} to enable mod_fcgid and the sympa web interface
        $ sudo port unload ${apache_name}
        $ sudo port load ${apache_name}
    Start the sympa daemons now and at startup
        $ sudo port load sympa

Upgrading to a new version:
    Run this script to upgrade your existing data structures:
        sudo ${prefix}/sbin/sympa.pl --upgrade
"
# ignore beta releases
github.livecheck.regex  "(\\d+(?:\\.\\d+)+)"
