# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem              1.0

name                    inetutils
version                 2.6
revision                1
categories              net
license                 GPL-3+
maintainers             {mps @Schamschula} openmaintainer
description             Inetutils is a collection of common network programs, including \
                        ftp, telnet, rsh, rlogin, tftp and the corresponding daemons.
long_description        {*}${description} Other tools include logger, ping, ping6, rcp, \
                        rexec, talk, and traceroute. \
                        Additional daemons include inetd, rexecd, syslogd and uucpd.
homepage                https://www.gnu.org/software/${name}/
master_sites            gnu:${name}
use_xz                  yes

checksums               rmd160  43694025d28345b16bf645b8d2e33eb503758784 \
                        sha256  68bedbfeaf73f7d86be2a7d99bcfbd4093d829f52770893919ae174c0b2357ca \
                        size    1764528

depends_lib             port:readline

configure.args          --infodir=${prefix}/share/info \
                        --mandir=${prefix}/share/man \
                        --disable-servers \
                        --disable-hostname \
                        --disable-ifconfig \
                        --disable-whois

variant client description {Enable all clients (with g prefix)} {
    post-patch {
        # grsh has a hard reference to ${prefix}/bin/rlogin
        reinplace -locale C "s|/rlogin|/grlogin|g" ${worksrcpath}/paths
        reinplace -locale C "s|/rsh|/grsh|g" ${worksrcpath}/paths
    }

    configure.args-append   --program-prefix=g

    post-destroot {
        file attributes ${destroot}${prefix}/bin/grcp -permissions +s
        file attributes ${destroot}${prefix}/bin/grlogin -permissions +s
        file attributes ${destroot}${prefix}/bin/grsh -permissions +s

        xinstall -m 755 -d ${destroot}${prefix}/libexec/gnubin
        foreach binary [glob -tails -directory ${destroot}${prefix}/bin g*] {
            ln -s ${prefix}/bin/${binary} ${destroot}${prefix}/libexec/gnubin/[string range $binary 1 end]
        }

        xinstall -m 755 -d ${destroot}${prefix}/libexec/gnubin/man/man1
        foreach manpage [glob -tails -directory ${destroot}${prefix}/share/man/man1 g*] {
            ln -s ${prefix}/share/man/man1/${manpage}.gz ${destroot}${prefix}/libexec/gnubin/man/man1/[string range $manpage 1 end].gz
        }
    }

notes "
All clients are now installed with the \"g\" prefix. This means that you'll now, for\
example, find GNU telnet at ${prefix}/bin/gtelnet. If you dislike typing gtelnet,\
you can create a shell alias or you can add ${prefix}/libexec/gnubin to your PATH,\
wherein non-g* prefixed symlinks are installed. In other words,\
${prefix}/libexec/gnubin contains GNU binaries without any prefix to the file\
names, so you can type telnet and get GNU telnet just as before.\
The (g)whois client has been removed as it duplicates the separate whois port"
}

variant server description {Enable server daemons} {
    configure.args-delete    --disable-servers

    post-destroot {
        xinstall -m 755 -d ${destroot}${prefix}/libexec/gnubin/man/man8
        foreach manpage [glob -tails -directory ${destroot}${prefix}/share/man/man8 g*] {
            ln -s ${prefix}/share/man/man8/${manpage}.gz ${destroot}${prefix}/libexec/gnubin/man/man8/[string range $manpage 1 end].gz
        }
    }
}

default_variants +client
