# -*- 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                    xymon-server
set shortname           xymon
conflicts               xymon-client
epoch                   1
version                 4.3.26
revision                3
categories              net
platforms               darwin
license                 {GPL-2 OpenSSLException}
maintainers             nomaintainer

description             Xymon network monitor Server

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

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 xybindir            ${xytopdir}/server/bin
set xylogdir            ${prefix}/var/log/${shortname}
set xytmpdir            ${xytopdir}/tmp
set xyvardir            ${xytopdir}/data
set xywebdir            ${xytopdir}/web
set xywwwdir            ${xytopdir}/www

configure.cmd           ./configure.server
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 \
                        ENABLELDAP=y \
                        ENABLELDAPSSL=y \
                        XYMONUSER=${xymonuser} \
                        USEXYMONPING=n \
                        XYMONTOPDIR=${xytopdir} \
                        XYMONHOSTURL=/${shortname} \
                        CGIDIR=${xytopdir}/cgi-bin \
                        XYMONCGIURL=/${shortname}-cgi \
                        SECURECGIDIR=${xytopdir}/cgi-secure \
                        SECUREXYMONCGIURL=/${shortname}-secgci \
                        HTTPDGID=_www \
                        XYMONLOGDIR=${xylogdir} \
                        XYMONHOSTNAME=localhost \
                        XYMONHOSTIP=127.0.0.1 \
                        XYMONHOSTOS=${os.platform} \
                        MANROOT=${prefix}/share/man \
                        INSTALLBINDIR=${xytopdir}/server/bin \
                        INSTALLETCDIR=${xyetcdir} \
                        INSTALLEXTDIR=${xytopdir}/server/ext \
                        INSTALLTMPDIR=${xytmpdir} \
                        INSTALLWEBDIR=${xywebdir} \
                        INSTALLWWWDIR=${xywwwdir} \
                        XYMONVAR=${xyvardir}

destroot.env-append     INSTALLROOT=${destroot}
destroot.keepdirs       ${destroot}${xytopdir} \
                        ${destroot}${xylogdir} \
                        ${destroot}${xytmpdir} \
                        ${destroot}${xyvardir}/acks \
                        ${destroot}${xyvardir}/data \
                        ${destroot}${xyvardir}/disabled \
                        ${destroot}${xyvardir}/hist \
                        ${destroot}${xyvardir}/histlogs \
                        ${destroot}${xyvardir}/hostdata \
                        ${destroot}${xyvardir}/logs \
                        ${destroot}${xyvardir}/rrd \
                        ${destroot}${xyvardir} \
                        ${destroot}${xywebdir} \
                        ${destroot}${xywwwdir}/html \
                        ${destroot}${xywwwdir}/rep \
                        ${destroot}${xywwwdir}/snap \
                        ${destroot}${xywwwdir}/notes \
                        ${destroot}${xywwwdir}/wml

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

post-destroot {
    # Adding own startupitem - xymon needs to be run under ${xymonuser} user
    xinstall -d ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${name}/
    xinstall -m 644 ${filespath}/org.macports.${name}.plist ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${name}/
    # The startup script needs to be adapted to use ${xymonuser} user
    reinplace s%@XYMONUSER@%${xymonuser}%g ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${name}/org.macports.${name}.plist
    reinplace s%@XYMONLAUNCH@%${xybindir}/xymonlaunch%g ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${name}/org.macports.${name}.plist
    reinplace s%@XYMONTASKS@%${xyetcdir}/tasks.cfg%g ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${name}/org.macports.${name}.plist
    reinplace s%@XYMONSERVER@%${xyetcdir}/xymonserver.cfg%g ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${name}/org.macports.${name}.plist
    reinplace s%@XYMONLAUNCHLOG@%${xylogdir}/xymonlaunch.log%g ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${name}/org.macports.${name}.plist
    reinplace s%@XYMONLAUNCHPID@%${xylogdir}/xymonlaunch.pid%g ${destroot}${prefix}/etc/LaunchDaemons/org.macports.${name}/org.macports.${name}.plist

    # Creation of a symbolic link towards startupitem
    xinstall -d -m 755 ${destroot}/Library/LaunchDaemons
    ln -sf ${prefix}/etc/LaunchDaemons/org.macports.${name}/org.macports.${name}.plist ${destroot}/Library/LaunchDaemons/
    # And a link to have the xymon client working
    ln -sf ${xytmpdir} ${destroot}${xytopdir}/client/

    # Adding a suffix to config files
    foreach f { alerts.cfg analysis.cfg cgioptions.cfg client-local.cfg columndoc.csv combo.cfg critical.cfg graphs.cfg holidays.cfg \
                hosts.cfg protocols.cfg rrddefinitions.cfg snmpmibs.cfg tasks.cfg xymon-apache.conf xymonmenu.cfg xymonserver.cfg } {
        move ${destroot}${xyetcdir}/${f} ${destroot}${xyetcdir}/${f}.${version}
    }
}

post-activate {
    # If not already present we put default config files
    foreach f { alerts.cfg analysis.cfg cgioptions.cfg client-local.cfg columndoc.csv combo.cfg critical.cfg graphs.cfg holidays.cfg \
                hosts.cfg protocols.cfg rrddefinitions.cfg snmpmibs.cfg tasks.cfg xymon-apache.conf xymonmenu.cfg xymonserver.cfg } {
        if {![file exists ${xyetcdir}/${f}]} {
            file copy ${xyetcdir}/${f}.${version} ${xyetcdir}/${f}
            system "chown ${xymonuser} ${xyetcdir}/${f}"
        }
    }
}

notes "  *** To complete the Xymon install ***

Run the following commands in your terminal:
    $ sudo bash -c \"echo kern.sysv.shmmax=16777216 >> /etc/sysctl.conf\"
    $ sudo bash -c \"echo kern.sysv.shmmni=128 >> /etc/sysctl.conf\"
    $ sudo bash -c \"echo kern.sysv.shmseg=32 >> /etc/sysctl.conf\"
    $ sudo bash -c \"echo kern.sysv.shmall=4096 >> /etc/sysctl.conf\"
    $ sudo mv ${xyetcdir}/xymon-apache.conf /etc/apache2/\[other|sites\]/
    $ sudo /usr/sbin/apachectl restart
    $ sudo dscl . -append /Groups/admin GroupMembership ${xymonuser}
Make sure the following line is uncommented in your /etc/apache2/httpd.conf:
LoadModule cgi_module libexec/apache2/mod_cgi.so
Reboot your system
Start xymon server:
    $ sudo launchctl load -w /Library/LaunchDaemons/org.macports.xymon-server.plist
Open \"http://localhost/xymon/\" in your server's browser

Full install instructions here: http://trac.macports.org/wiki/howto/SetupXymonServer

"

use_parallel_build  no

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

variant snmp description {add integrated SNMP support} {
    configure.env-append    SNMP=1
}