# $Id: Portfile 74623 2010-12-24 05:30:54Z digdog@macports.org $

PortSystem 1.0

name		tftp-hpa
version		0.48
revision        2
categories	net
maintainers	markd
description	Enhanced port of the BSD TFTP server
platforms	darwin 
long_description	tftp-hpa is an enhanced version of the BSD TFTP client \
		and server,  possessing a number of bugfixes and enhancements \
		over the  original. It has been made portable and will work on \
		pretty much any modern Unix variant.

homepage	http://www.kernel.org/pub/software/network/tftp/
master_sites	${homepage}
use_bzip2	yes
checksums	md5 f2e0a1ca0c49ae46ecad26a54df3e887

set tftp-root	${prefix}/var/${name}/

variant enable_upload description {If invoked with the server variant, tftp uploads \
	are enabled; without the server variant, this variant has no effect} {}

variant server description {Install launchd scripts to run tftpd at system boot} {
	startupitem.create	yes
	startupitem.name	tftpd
		if { ! [variant_isset enable_upload] } {
			startupitem.executable	${prefix}/sbin/tftpd -L -s ${tftp-root}
		} else {
			startupitem.executable  ${prefix}/sbin/tftpd -L -c -s ${tftp-root}
		}
}

configure.args	--mandir=\\\${prefix}/share/man

destroot.destdir	prefix=${destroot}${prefix}

post-destroot	{ 
	file rename ${destroot}${prefix}/sbin/in.tftpd \
		${destroot}${prefix}/sbin/tftpd

	file delete ${destroot}${prefix}/share/man/man8/tftpd.8
	file rename ${destroot}${prefix}/share/man/man8/in.tftpd.8 \
		${destroot}${prefix}/share/man/man8/tftpd.8

	reinplace "s|in.tftpd|tftpd|g" \
		${destroot}${prefix}/share/man/man8/tftpd.8

	xinstall -m 777 -d ${tftp-root}
	destroot.keepdirs ${tftp-root}
}

# tftp-ha setup instructions
post-install {
	ui_msg "\n

***** Setup Instructions *****

NOTE: By default, tftp-hpa listens to the tftp port specified in /etc/services (port 69)
      on all local addresses.

To run tftpd manually for download only access, use this command:
	sudo tftpd -L -s <tftp-root-dir>

To run tftpd manually and support tftp uploads, add \"-c\" to the command:
	sudo tftpd -L -c -s <tftp-root-dir>

You may run tftpd at system boot using the startupitem if you installed tftp-hpa
using the server variant.  To load the startupitem using launchctl:
	sudo launchctl load -w /Library/LaunchDaemons/org.macports.tftpd.plist

NOTE: When loading tftp-hpa using launchctl, make sure to place the files you want to serve
in ${tftp-root}, because that is the location set in the StartupItem.

*******************************

If you wish to run tftpd in inetd mode, you may make an inetd compatible .plist
file and replace the one installed by MacPorts in /Library/LaunchDaemons.  You
may use /System/Library/LaunchDaemons/tftp.plist as a template.

\n"
}

