# -*- 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                snmptt
version             1.4
revision            1
categories          net
license             GPL-2+
maintainers         nomaintainer
description         An SNMP trap handler written in Perl for use with the Net-SNMP / UCD-SNMP snmptrapd program
long_description    ${description}

platforms           darwin
supported_archs     noarch
homepage            http://www.snmptt.org/
master_sites        sourceforge:snmptt
extract.suffix      .tgz
distname            ${name}_${version}

checksums           rmd160  91514f21f05d41a4ccaf789f2033f3389f2ed989 \
                    sha256  512c33ecdf06da8b3c75082c1506e4b4091ddb714d0d9564771aa12ddc98ef99

perl5.branches      5.24
depends_lib         port:perl${perl5.major} \
                    port:p${perl5.major}-config-inifiles

use_configure       no
build               {}

set bindir          ${prefix}/sbin
set docsdir         ${prefix}/share/doc/${name}
set etcdir          ${prefix}/etc/${name}
set scriptdir       ${prefix}/share/${name}

post-patch {
    reinplace "s|/usr/bin/perl|${perl5.bin}|g" \
        ${worksrcpath}/snmptt \
        ${worksrcpath}/snmptt-net-snmp-test \
        ${worksrcpath}/snmpttconvert \
        ${worksrcpath}/snmpttconvertmib \
        ${worksrcpath}/snmptthandler

    reinplace "s|/etc/snmp/snmptt.ini|${prefix}/etc/${name}/snmptt.ini|g" \
        ${worksrcpath}/snmptt \
        ${worksrcpath}/snmptthandler

    reinplace "s|/etc/snmp/snmptt.conf|${prefix}/etc/snmptt.conf|g" \
        ${worksrcpath}/snmptt.ini
}

destroot {
    xinstall -m 755 -d ${destroot}${bindir}
    xinstall -m 755 -d ${destroot}${docsdir}/docs
    xinstall -m 755 -d ${destroot}${scriptdir}
    xinstall -m 755 -d ${destroot}${etcdir}

    xinstall -m 755 -W ${worksrcpath} snmptt snmptt-net-snmp-test snmpttconvert \
        snmpttconvertmib snmptthandler                           ${destroot}${bindir}

    xinstall -m 755 -W ${worksrcpath}/docs faqs.html index.html layout1.css \
        snmptt.html snmpttconvert.html snmpttconvertmib.html     ${destroot}${docsdir}/docs

    xinstall -m 755 -W ${worksrcpath} ChangeLog INSTALL README   ${destroot}${docsdir}

    eval xinstall -m 644 [glob ${worksrcpath}/sample-*]          ${destroot}${docsdir}
    eval xinstall -m 644 [glob ${worksrcpath}/examples/*-trap.*] ${destroot}${docsdir}

    xinstall -m 644 ${worksrcpath}/snmptt.ini                    ${destroot}${etcdir}/snmptt.ini.sample
    xinstall -m 644 ${worksrcpath}/examples/snmptt.conf.generic  ${destroot}${etcdir}
    xinstall -m 755 ${worksrcpath}/snmptt-init.d                 ${destroot}${docsdir}
}

post-activate {
ui_msg "\n

snmptt setup:

-Rename the ${prefix}/etc/${name}/snmptt.ini.sample file to remove the trailing
\"sample\" so snmptt will be able to find its configuration, and customize the
 file as necessary.

-Use snmpttconvertmib to build an ${prefix}/etc/snmptt.conf file with translations from
 MIB files for your devices as described in the documentation.


snmptrapd setup:

-Edit your snmptrapd.conf (you may use the snmpconf utility) and make sure that
 these items are present.

    traphandle  default ${perl5.bin} ${prefix}/sbin/snmptt

\n"
}

livecheck.regex     {/snmptt/snmptt_([0-9.]+)/}