# $Id$

PortSystem 1.0

name                tftp-hpa
version             5.2
revision            1
categories          net
maintainers         nomaintainer
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.
license             BSD
homepage            http://www.kernel.org/pub/software/network/tftp/
master_sites        ${homepage}/tftp-hpa/
use_bzip2           yes

checksums           rmd160  dc3935af75f2919c55cac6c04b61488af425918c \
                    sha256  0a9f88d4c1c02687b4853b02ab5dd8779d4de4ffdb9b2e5c9332841304d1a269

patchfiles          patch-tftpd-recvfrom.c.diff

depends_lib         port:readline port:ncurses

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} {}

startupitem.name    tftpd

variant server description {Install launchd scripts to run tftpd at system boot} {
    startupitem.create    yes
        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
notes "

***** 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.

"