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

name                sendpage
version             1.000003
revision            4
categories          net
license             GPL-2+
maintainers         nomaintainer
platforms           darwin

description         Sendpage sends alphanumeric pages via a modem, receives via SNPP

long_description    An SNPP client, SNPP server, a queuing engine, \
                    a modem control engine, a TAP communication system, \
                    and an email notification system.

homepage            http://www.sendpage.org/

master_sites        sourceforge

checksums           rmd160  a427a662dceef09a3b9f881429b18c429c2fdf97 \
                    sha256  88a128c077ca0573cfe456bd9f595ccf8f9335ba44a339144a0c70163e209317

perl5.branches      5.24

depends_lib         port:p${perl5.major}-net-snpp \
                    port:p${perl5.major}-device-serialport \
                    port:p${perl5.major}-mailtools \
                    port:p${perl5.major}-dbi

use_configure       no
build               {}

# Create a startupitem to start/stop the server
startupitem.create  yes
startupitem.start   "${prefix}/share/${name}/sendpage.init start"
startupitem.stop    "${prefix}/share/${name}/sendpage.init stop"

# Add sendpage user and group
add_users sendpage group=sendpage

# Maintain empty directories
destroot.keepdirs   ${destroot}${prefix}/var/sendpage \
                    ${destroot}${prefix}/var/sendpage/lock

pre-destroot {
    reinplace "s|Win32|Device|g" ${worksrcpath}/Makefile.PL

    reinplace "s|/etc/sendpage.cf|${prefix}/etc/sendpage/sendpage.cf|g" ${worksrcpath}/sendpage
    reinplace "s|/var/lock|${prefix}/var/sendpage/lock|g" ${worksrcpath}/sendpage

    reinplace "s|/etc/sendpage.cf|${prefix}/etc/sendpage/sendpage.cf|g" ${worksrcpath}/sendpage.init
    reinplace "s|/var/spool|${prefix}/var|g" ${worksrcpath}/sendpage.init
    reinplace "s|/usr/local/bin|${prefix}/bin|g" ${worksrcpath}/sendpage.init

    reinplace "s|/var/spool|${prefix}/var|g" \
        ${worksrcpath}/sendpage

    reinplace "s|/etc|${prefix}/etc/sendpage|g" ${worksrcpath}/snpp

    reinplace "s|#pidfileprefix = /tmp/var/spool/sendpage/sendpage| \
        pidfileprefix = ${prefix}/var/sendpage/sendpage|g" ${worksrcpath}/sendpage.cf

    reinplace "s|#lockprefix = /tmp/var/lock/LCK..| \
        lockprefix = ${prefix}/var/sendpage/lock/LCK..|g" ${worksrcpath}/sendpage.cf

    reinplace "s|#queuedir = /tmp/var/spool/sendpage| \
        queuedir = ${prefix}/var/sendpage|g" ${worksrcpath}/sendpage.cf
}

destroot {
    system "cd ${worksrcpath} && ${perl5.bin} Makefile.PL INSTALLDIRS=vendor CC='${configure.cc}' LD='${configure.cc}'"
    system "cd ${worksrcpath} && make"
    system "cd ${worksrcpath} && make install DESTDIR='${destroot}'"
}

post-destroot {

# Copy sendpage configuration files
    xinstall -m 755 -d ${destroot}${prefix}/etc/sendpage
    xinstall -m 755 ${worksrcpath}/sendpage.cf ${destroot}${prefix}/etc/sendpage
    xinstall -m 755 ${worksrcpath}/email2page.conf ${destroot}${prefix}/etc/sendpage
    xinstall -m 755 ${worksrcpath}/snpp.conf ${destroot}${prefix}/etc/sendpage

# Copy sendpage documentation & examples
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/sendpage
    xinstall -m 755 ${worksrcpath}/README ${destroot}${prefix}/share/doc/sendpage
    xinstall -m 755 ${worksrcpath}/FEATURES ${destroot}${prefix}/share/doc/sendpage
    xinstall -m 755 ${worksrcpath}/TODO ${destroot}${prefix}/share/doc/sendpage

    xinstall -m 755 -d ${destroot}${prefix}/share/sendpage/examples
    eval xinstall -m 755 [glob ${worksrcpath}/examples/*] ${destroot}${prefix}/share/sendpage/examples
    xinstall -m 755 ${worksrcpath}/${name}.init ${destroot}${prefix}/share/sendpage/examples

# Make the sendpage queue area
    xinstall -d ${destroot}${prefix}/var/sendpage/lock
    system "chmod og-rwx ${destroot}${prefix}/var/sendpage"
    system "chown sendpage ${destroot}${prefix}/var/sendpage"
    system "chgrp tty ${destroot}${prefix}/var/sendpage"

    system "chown sendpage ${destroot}${prefix}/var/sendpage/lock"
    system "chgrp uucp ${destroot}${prefix}/var/sendpage/lock"

# Install sendpage start script
    xinstall -o root -m 755 -c ${worksrcpath}/${name}.init ${destroot}${prefix}/share/${name}

}

notes "

README & docs -->   ${prefix}/share/doc/sendpage
Config files -->    ${prefix}/etc/sendpage
Start script -->    ${prefix}/share/sendpage/sendpage.init
Examples  -->       ${prefix}/share/sendpage/examples

"

livecheck.regex     "production\.*${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"