# -*- 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                logwatch
version             7.12
revision            0
distname            logwatch-${version}
categories          security
license             MIT
maintainers         {khindenburg @kurthindenburg} openmaintainer
supported_archs     noarch

description         system log analyzer and reporter
long_description  \
                    Logwatch is a customizable log analysis system. Logwatch \
                    parses through your system's logs for a given period of \
                    time and creates a report analyzing areas that you \
                    specify, in as much detail as you require. Logwatch is \
                    easy to use and will work right out of the package on most \
                    systems.

homepage            http://logwatch.sourceforge.net
master_sites        sourceforge:project/logwatch/logwatch-${version}

platforms           any
depends_lib-append  path:bin/perl:perl5 \
                    port:p5-html-parser

checksums           rmd160  2795c48d62e4a6b3b428618c79b81a9b6112b0fd \
                    sha256  9b87f3f1122d4b6c9b3d77faca40ab98452225cae50019aad761ebd6b01b84d8 \
                    size    509278

patchfiles          patch-scripts.logwatch.pl.diff \
                    patch-conf.logwatch.conf.diff \
                    patch-zz-disk_space.conf.diff

use_configure       no

post-patch {
    file delete ${worksrcpath}/scripts/logwatch.pl.orig

    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/scripts/logwatch.pl
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/conf/logwatch.conf

    reinplace s|#!/usr/bin/perl|#!${prefix}/bin/perl| ${worksrcpath}/scripts/logwatch.pl
    reinplace s|messages|system|g ${worksrcpath}/conf/logfiles/messages.conf

    reinplace s|/usr/share/logwatch/default.conf|${prefix}/share/${name}/default.conf| ${worksrcpath}/logwatch.conf.5
    reinplace s|/etc/logwatch/conf/ignore.conf|${prefix}/share/${name}/conf/ignore.conf| ${worksrcpath}/logwatch.conf.5
    reinplace s|/etc/logwatch|${prefix}/etc/${name}| ${worksrcpath}/logwatch.conf.5

    reinplace s|/usr/share|${prefix}/share| ${worksrcpath}/logwatch.8
    reinplace s|/etc/${name}|${prefix}/etc/${name}| ${worksrcpath}/logwatch.8
}

build {}

destroot.keepdirs   ${destroot}${prefix}/var/cache/${name} \
                    ${destroot}${prefix}/etc/${name} \
                    ${destroot}${prefix}/etc/${name}/scripts \
                    ${destroot}${prefix}/etc/${name}/conf/logfiles \
                    ${destroot}${prefix}/etc/${name}/conf/services

destroot {
    file mkdir ${destroot}${prefix}/var/cache/${name}
    file mkdir ${destroot}${prefix}/etc/${name}
    file mkdir ${destroot}${prefix}/etc/${name}/scripts
    file mkdir ${destroot}${prefix}/etc/${name}/conf/logfiles
    file mkdir ${destroot}${prefix}/etc/${name}/conf/services
    file mkdir ${destroot}${prefix}/share/${name}/dist.conf/logfiles

    file copy ${worksrcpath}/conf    ${destroot}${prefix}/share/${name}/default.conf
    file copy ${worksrcpath}/scripts ${destroot}${prefix}/share/${name}/scripts
    file copy ${worksrcpath}/lib     ${destroot}${prefix}/share/${name}/lib

    xinstall -m 755 -d ${destroot}${prefix}/share/man/man5
    xinstall -m 755 -d ${destroot}${prefix}/share/man/man8

    xinstall -m 644 ${worksrcpath}/logwatch.conf.5 ${destroot}${prefix}/share/man/man5/
    xinstall -m 644 ${worksrcpath}/logwatch.8 ${destroot}${prefix}/share/man/man8/

    # startup item
    file mkdir ${destroot}${prefix}/etc/LaunchDaemons/${name}
    file copy ${filespath}/org.macports.${name}.plist ${destroot}${prefix}/etc/LaunchDaemons/${name}/org.macports.${name}.plist
    reinplace s|@PREFIX@|${prefix}|g ${destroot}${prefix}/etc/LaunchDaemons/${name}/org.macports.${name}.plist
}

post-destroot {
    file delete /Library/LaunchDaemons/org.macports.${name}.plist
    xinstall -d -m 0755 ${destroot}/Library/LaunchDaemons
    ln -sf ${prefix}/etc/LaunchDaemons/${name}/org.macports.${name}.plist ${destroot}/Library/LaunchDaemons/
    ln -sf ${prefix}/share/${name}/scripts/logwatch.pl ${destroot}${prefix}/bin/logwatch
}

notes "
Run the following command to load the logwatch launchd plist\
in order to start the service now and at system startup:

sudo port load logwatch
"

livecheck.regex     ${name}-(\[0-9.\]+)${extract.suffix}