# $Id$

PortSystem		1.0

name			nefu
version			1.4.0
revision        2
categories		net
license			BSD
maintainers		nomaintainer
description		A network monitoring daemon.
long_description	nefu monitors network services and reports outages. \
					Working from a description 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/nefu/
master_sites	${homepage}files/
checksums		md5 f0953b21cdb5eb327e40d4b215110b71 \
				sha1 799d5573ab6d30f32cdc36bfee09a04de0f33bf8 \
				rmd160 712b637b3c9126c2a218f5ec0eb74497f7e6ea59
extract.suffix  .tgz
platforms		darwin

depends_build	bin:bison:bison
depends_lib		path:lib/libssl.dylib:openssl port:zlib

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

use_autoconf	yes
# This really should be in a post-autoconf hook, but we don't have one yet.
pre-configure {
    system "cd ${worksrcpath}/libsnet && autoconf"
}
configure.args	--mandir=${prefix}/share/man \
				--with-html=${prefix}/share/${name}/public_html \
				--with-shelltests=${prefix}/share/${name}/shelltests

use_parallel_build	no
build.args		DEFS="-DBIND_8_COMPAT -DLDAP_DEPRECATED"
post-build {
	system "cd ${worksrcpath}/TDK && ${build.cmd}"
}

pre-destroot {
	addgroup nefu
	set gid [existsgroup nefu]
	adduser nefu gid=${gid} realname=Nefu\ Monitor home=${prefix}/share/${name}
	xinstall -d -m 0755 ${destroot}${prefix}/share/${name}/public_html
}
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 {${os.platform} ne "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
	xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
	xinstall -m 0644 -W ${worksrcpath} README ${destroot}${prefix}/share/doc/${name}

	# nefu TDK
	xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}/TDK
	xinstall -m 0755 -W ${worksrcpath} TDK/tdk \
		${destroot}${prefix}/share/doc/${name}/TDK
	xinstall -m 0644 -W ${worksrcpath} 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 -W ${worksrcpath} 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.diff
	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"
}