# -*- 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

name                    xymon-client
set shortname           xymon
conflicts               xymon-server
version                 4.3.26
revision                1
categories              net
platforms               darwin
license                 {GPL-2 OpenSSLException}
maintainers             free.fr:fclaire openmaintainer

description             Xymon network monitor Client

long_description        Xymon is a system for monitoring of hosts and networks, \
                        inspired by the Big Brother system. It provides real-time \
                        monitoring, an easy web-interface, historical data, \
                        availability reports and performance graphs. \
                        Xymon was previously known as \"Hobbit\".

homepage                http://www.xymon.com/
master_sites            sourceforge:project/xymon/Xymon/${version}
distname                ${shortname}-${version}
dist_subdir             ${shortname}

checksums               sha256  cbd0586c77378c92d9866497c8e5ddc64ec9973e4078e44860f572258f8521c5 \
                        rmd160  c43ac804be298dca61d0f310bd599caea0b804de

depends_lib             port:rrdtool \
                        port:fping \
                        port:pcre \
                        port:libpng \
                        path:lib/libssl.dylib:openssl \
                        port:openldap

universal_variant       no

patchfiles              patch-build-Makefile.Darwin.diff

if {${os.platform} eq "darwin" && ${os.major} > 8} {
    set xymonuser       _xymon
} else {
    set xymonuser       xymon
}
set xymongroup          ${xymonuser}
set xytopdir            ${prefix}/lib/${shortname}
set xyetcdir            ${xytopdir}/etc
set xylogdir            ${xytopdir}/logs
set xytmpdir            ${xytopdir}/tmp
set xyvardir            ${xytopdir}/data
set xywebdir            ${xytopdir}/web
set xywwwdir            ${xytopdir}/www

configure.cmd           ./configure.client
configure.args-append   --rrdinclude ${prefix}/include \
                        --rrdlib ${prefix}/lib \
                        --pcreinclude ${prefix}/include \
                        --pcrelib ${prefix}/lib \
                        --sslinclude ${prefix}/include \
                        --ssllib ${prefix}/lib \
                        --ldapinclude ${prefix}/include \
                        --ldaplib ${prefix}/lib \
                        --fping ${prefix}/sbin/fping
configure.env-append    ENABLESSL=y \
                        XYMONUSER=${xymonuser} \
                        XYMONTOPDIR=${xytopdir} \
                        XYMONHOSTIP=127.0.0.1 \
                        XYMONHOSTOS=${os.platform} \
                        MANROOT=${prefix}/share/man \
                        INSTALLBINDIR=${xytopdir}/bin \
                        INSTALLETCDIR=${xyetcdir} \
                        INSTALLEXTDIR=${xytopdir}/ext \
                        INSTALLTMPDIR=${xytmpdir} \
                        INSTALLWEBDIR=${xywebdir} \
                        INSTALLWWWDIR=${xywwwdir} \
                        XYMONVAR=${xyvardir} \
                        CC=${configure.cc} \
                        CXX=${configure.cxx} \
                        CPP=${configure.cpp}

build.args-append       CC=${configure.cc} \
                        CXX=${configure.cxx} \
                        CPP=${configure.cpp}

destroot.env-append     INSTALLROOT=${destroot}
destroot.keepdirs       ${destroot}${xytopdir} \
                        ${destroot}${xylogdir} \
                        ${destroot}${xytmpdir} \
                        ${destroot}${xyvardir}/logs \
                        ${destroot}${xyvardir} \
                        ${destroot}${xywebdir}

startupitem.create      yes
startupitem.start       "sudo su ${xymonuser} -c \"${xytopdir}/runclient.sh start\""
startupitem.stop        "sudo su ${xymonuser} -c \"${xytopdir}/runclient.sh stop\""
startupitem.restart     "sudo su ${xymonuser} -c \"${xytopdir}/runclient.sh restart\""
#startupitem.pidfile     auto ${xylogdir}/clientlaunch.*.pid
startupitem.pidfile     none

add_users ${xymonuser} group=${xymongroup} realname=Xymon\ User home=${xytopdir} shell=/bin/bash

post-destroot {
    xinstall -d -o ${xymonuser} -g ${xymongroup} ${destroot}${xylogdir}
    xinstall -d -o ${xymonuser} -g ${xymongroup} ${destroot}${xytmpdir}
    # Adding a suffix to config files
    foreach f { clientlaunch.cfg localclient.cfg xymonclient.cfg } {
        move ${destroot}${xyetcdir}/${f} ${destroot}${xyetcdir}/${f}.${version}
    }
}

post-activate {
    # If not already present we put default config files
    foreach f { clientlaunch.cfg localclient.cfg xymonclient.cfg } {
        if {![file exists ${xyetcdir}/${f}]} {
            file copy ${xyetcdir}/${f}.${version} ${xyetcdir}/${f}
        }
    }
}

notes "\nSet your Xymon server's IP address with the following command:
    $ sudo vi ${xyetcdir}/xymonclient.cfg

If you wish your xymon client to report logfiles to your xymon server
you need to add the user ${xymonuser} to the admin group like this:
    $ sudo dscl . -append /Groups/admin GroupMembership ${xymonuser}

You can start,stop and restart the xymon client with:
    $ sudo -u ${xymonuser} ${xytopdir}/runclient.sh \[start|stop|restart\]
"

use_parallel_build  no

livecheck.type      regex
livecheck.url       http://sourceforge.net/projects/${shortname}/files/
livecheck.regex     ${shortname}-(\[0-9.\]+)\\.tar.gz