# $Id: Portfile 62428 2010-01-07 18:12:30Z markd@macports.org $

PortSystem        1.0

name              nrpe
version           2.12
categories        net
maintainers       markd
description       Nagios Remote Plugin Executor
long_description  Allows \"local\" Nagios plugins to run on remote hosts and \
		  report back to a Nagios server.

homepage          http://nagios.org
master_sites      sourceforge:nagios
platforms         darwin
checksums         md5 b2d75e2962f1e3151ef58794d60c9e97

patchfiles	  patch-init-script.in

configure.args    --mandir=${prefix}/share/man \
		  --with-nrpe-user=nagios \
                  --with-nrpe-group=nagios \
		  --libexecdir=${prefix}/libexec/nagios \
		  --bindir=${prefix}/sbin \
		  --sysconfdir=${prefix}/etc/${name} \
                  --with-kerberos-inc=/usr/include/kerberosIV \
                  --enable-ssl \
		  --with-ssl-lib=${prefix}/lib \
                  --with-ssl-inc=${prefix} \
		  --enable-command-args

		startupitem.create    yes
		startupitem.start    "${prefix}/share/${name}/init-script start"
		startupitem.stop    "${prefix}/share/${name}/init-script stop"

post-patch {
        adduser nagios
        addgroup nagios

        reinplace "s|dir/libssl.so|dir/libssl.dylib|g" ${worksrcpath}/configure

        reinplace "s|__PREFIX__|${prefix}|g" "${worksrcpath}/init-script.in"
}

destroot {
	xinstall -d -m 755 ${destroot}${prefix}/etc/${name}
	xinstall -d -m 755 ${destroot}${prefix}/share/${name}
	xinstall -d -m 755 ${destroot}${prefix}/libexec/nagios
        xinstall -m 755 ${worksrcpath}/src/nrpe ${destroot}${prefix}/sbin/nrpe
        xinstall -m 755 ${worksrcpath}/src/check_nrpe ${destroot}${prefix}/libexec/nagios
	xinstall -m 755 ${worksrcpath}/sample-config/nrpe.cfg ${destroot}${prefix}/etc/${name}/nrpe.cfg.sample

        xinstall -m 755 ${worksrcpath}/init-script ${destroot}${prefix}/share/${name}

	xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
	xinstall -m 755 ${worksrcpath}/README ${destroot}${prefix}/share/doc/${name}
        xinstall -m 755 ${worksrcpath}/README.SSL ${destroot}${prefix}/share/doc/${name}

	xinstall -d -m 755 ${destroot}${prefix}/var/run/nrpe
	destroot.keepdirs ${destroot}${prefix}/var/run/nrpe
}

post-destroot {
	system "chown nagios:nagios ${destroot}${prefix}/sbin/nrpe"
	system "chown nagios:nagios ${destroot}${prefix}/libexec/nagios/check_nrpe"
	system "chown nagios:nagios ${destroot}${prefix}/etc/${name}/nrpe.cfg.sample"
}

post-install {
                ui_msg "\n
README files 	 -->       ${prefix}/share/doc/${name}
Config file name -->       ${prefix}/etc/${name}/nrpe.cfg (rename nrpe.cfg.sample)
Start script 	 -->       ${prefix}/share/${name}/init-script start|stop|status
\n"
}

