# $Id: Portfile,v 1.7 2005/08/11 21:33:24 rshaw Exp $
PortSystem		1.0

name			nefu
version			0.9.7
revision		2
categories		net
maintainers		darwinports@opendarwin.org
description		A network monitoring daemon.
long_description	nefu monitors network services and reports outages. \
					Working from a discription of the network \
					topography, nefu's algorithm prevents "false alarms" \
					in the event of a network outage due to a dependency \
					failure.
homepage		http://rsug.itd.umich.edu/software/${name}
master_sites	${homepage}/files/
checksums		md5 41827023db2d909309a99e4c10619cb4
platforms		darwin

depends_build	bin:bison:bison \
				bin:flex:flex
depends_lib		lib:libssl.0.9:openssl

patchfiles		patch-Makefile.in \
				patch-aclocal.m4 \
				patch-configure.ac

use_autoconf	yes
configure.args	--mandir='\${prefix}/share/man' \
				--with-htmldir='\${prefix}/share/${name}/public_html' \
				--with-scriptdir='\${prefix}/share/${name}/shelltests'

build.args		DEFS=-DBIND_8_COMPAT
post-build {
	build.dir	${worksrcpath}/TDK
	system "[command build]"
	build.dir	${worksrcpath}
}

pre-destroot {
	addgroup nefu
	set gid [existsgroup nefu]
	adduser nefu gid=${gid} realname=Nefu\ Monitor home=${prefix}/share/${name}
}
destroot.keepdirs	${destroot}${prefix}/share/${name}/shelltests
post-destroot {
	# nefu conf file
	xinstall -d -m 0755 ${destroot}${prefix}/etc
	xinstall -m 0644 ${filespath}/nefu.conf.in \
		${destroot}${prefix}/etc/nefu.conf-dist
	set hostname [exec hostname]
	reinplace "s%__HOSTNAME%${hostname}%" \
		${destroot}${prefix}/etc/nefu.conf-dist

	# nefu start/stop rc script (if non-Darwin)
	if {![variant_isset darwin]} {
		xinstall -d -m 0755 ${destroot}${prefix}/etc/rc.d
		xinstall -m 0755 ${filespath}/nefu.sh.in \
			${destroot}${prefix}/etc/rc.d/nefu.sh
		reinplace "s%__PREFIX%${prefix}%" \
			${destroot}${prefix}/etc/rc.d/nefu.sh
	}

	# nefu documentation
	cd ${worksrcpath}
	xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
	xinstall -m 0644 README ${destroot}${prefix}/share/doc/${name}

	# nefu TDK
	xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}/TDK
	xinstall -m 0755 TDK/tdk \
		${destroot}${prefix}/share/doc/${name}/TDK
	xinstall -m 0644 TDK/README TDK/README.C TDK/README.SH \
		${destroot}${prefix}/share/doc/${name}/TDK
	reinplace "s%nefu-src/TDK/shelltests%./shelltests%" \
		${destroot}${prefix}/share/doc/${name}/TDK/README.SH
	xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}/TDK/shelltests
	xinstall -m 0755 TDK/shelltests/environ.sh \
		${destroot}${prefix}/share/doc/${name}/TDK/shelltests

	# fix ownership
	if {$env(USER) == "root"} {
		system "chown -R nefu ${destroot}${prefix}/share/${name}"
		system "chgrp -R nefu ${destroot}${prefix}/share/${name}"
	}
}

pre-install {
	addgroup nefu
	set gid [existsgroup nefu]
	adduser nefu gid=${gid} realname=Nefu\ Monitor home=${prefix}/share/${name}
}

post-activate {
	# Make sure initial conf file is present and setup correctly
	if {![file exists ${prefix}/etc/nefu.conf]} {
		xinstall -m 0644 ${prefix}/etc/nefu.conf-dist ${prefix}/etc/nefu.conf
	}
}

platform darwin {
	patchfiles-append	patch-libtest-ping.c
	post-destroot {
		system "ln -s public_html ${destroot}${prefix}/share/${name}/Sites"
	}

	startupitem.create			yes
	startupitem.name			Nefu
	startupitem.start			"${prefix}/bin/nefu -f ${prefix}/etc/nefu.conf -H"
	startupitem.stop			"/usr/bin/killall -SIGUSR1 nefu 2>/dev/null"
}

