# -*- 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: Portfile 48212 2009-03-17 01:06:42Z alpha@macports.org $

PortSystem          1.0

name                munin
version             1.2.6
categories          net
maintainers         alpha
platforms           darwin
description         Extensible system monitoring tool

long_description    Munin the monitoring tool surveys all your computers \
                    and remembers what it saw. It presents all the \
                    information in graphs through a web interface. Its \
                    emphasis is on plug and play capabilities. Using Munin \
                    you can easily monitor the performance of your \
                    computers, networks, SANs, applications, weather \
                    measurements and whatever comes to mind. \
                    \
                    Note: By default only Munin node is installed. To \
                    install the Munin server that gathers data from \
                    existing nodes and generates graphs please enable the \
                    server variant.

homepage            http://munin.projects.linpro.no/
master_sites        sourceforge
distname            ${name}_${version}
worksrcdir          ${name}-${version}
checksums           md5     45f84d58f80642ce914f147232f0d396 \
                    sha1    bdc6d1767df1ea618071d76f0c4525dda2ea33d9 \
                    rmd160  1fe38f8da3b2c88b38d56eb86f7b584c7fded962
depends_lib         port:perl5 port:p5-net-server

use_configure       no
patchfiles          patch-Makefile.config patch-munin-node.conf.in
build.target        build
build.args          PREFIX=${prefix} \
                    CONFDIR=${prefix}/etc/munin \
                    DBDIR=${prefix}/var/munin \
                    LOGDIR=${prefix}/var/log/munin \
                    STATEDIR=${prefix}/var/run/munin \
                    MANDIR=${prefix}/share/man \
                    DOCDIR=${prefix}/share/doc/munin \
                    LIBDIR=${prefix}/lib/munin \
                    HTMLDIR=${prefix}/www/munin \
                    CGIDIR=${prefix}/www/cgi-bin \
                    PERL=${prefix}/bin/perl
destroot.args       PREFIX=${destroot}${prefix} \
                    CONFDIR=${destroot}${prefix}/etc/munin \
                    DBDIR=${destroot}${prefix}/var/munin \
                    LOGDIR=${destroot}${prefix}/var/log/munin \
                    STATEDIR=${destroot}${prefix}/var/run \
                    MANDIR=${destroot}${prefix}/share/man \
                    DOCDIR=${destroot}${prefix}/share/doc/munin \
                    LIBDIR=${destroot}${prefix}/lib/munin \
                    HTMLDIR=${destroot}${prefix}/www/munin \
                    CGIDIR=${destroot}${prefix}/www/cgi-bin \
                    PERL=${prefix}/bin/perl
destroot.keepdirs   ${destroot}${prefix}/var/log/munin \
                    ${destroot}${prefix}/var/run/munin \
                    ${destroot}${prefix}/etc/munin/plugins \
                    ${destroot}${prefix}/var/munin \
                    ${destroot}${prefix}/www/munin
destroot.target     install-node install-node-plugins install-doc install-man

startupitem.create  yes
startupitem.name    munin-node
startupitem.start   "${prefix}/sbin/munin-node"
startupitem.stop    "kill `cat ${prefix}/var/run/munin/munin-node.pid`"

variant server description {Install Munin server} {
    depends_lib-append port:rrdtool port:p5-html-template
    destroot.target-append install-main
}

pre-destroot {
    # Create munin user and group
    addgroup munin
    adduser munin gid=[existsgroup munin]
}
post-destroot {
    # State directory should be owned by munin
    xinstall -d -o munin ${destroot}${prefix}/var/run/munin

    if { [variant_isset server] } {
        # Create and symlink launchd item for munin-cron
        xinstall -d ${destroot}${prefix}/etc/LaunchDaemons/org.macports.munin-cron
        file copy ${portpath}/files/org.macports.munin-cron.plist.in \
        ${destroot}${prefix}/etc/LaunchDaemons/org.macports.munin-cron/org.macports.munin-cron.plist
        reinplace s|@PREFIX@|${prefix}|g ${destroot}${prefix}/etc/LaunchDaemons/org.macports.munin-cron/org.macports.munin-cron.plist

        xinstall -d ${destroot}/Library/LaunchDaemons
        ln -s ${prefix}/etc/LaunchDaemons/org.macports.munin-cron/org.macports.munin-cron.plist \
        ${destroot}/Library/LaunchDaemons/org.macports.munin-cron.plist

        ui_msg "###########################################################"
        ui_msg "# A startup item has been generated that will cause the"
        ui_msg "# Munin server to fetch data from all nodes every 5 mins."
        ui_msg "# It is disabled by default, please execute the following"
        ui_msg "# command to enable:"
        ui_msg "#"
        ui_msg "# sudo launchctl load -w /Library/LaunchDaemons/org.macports.munin-cron.plist"
        ui_msg "###########################################################"
    }
}
post-install {
    ui_msg "To detect supported Munin plugins please use the following command"
    ui_msg "$ sudo munin-node-configure --suggest --shell | sh"
}
