# -*- 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
PortGroup       github 1.0
PortGroup       legacysupport 1.1

# CLOCK_MONOTONIC
legacysupport.newest_darwin_requires_legacy 15

github.setup    Quagga quagga 1.2.4 quagga-
revision        0
checksums       rmd160  9d4b807ce150db9d3cec1f6bf9a3f836d4973428 \
                sha256  e364c082c3309910e1eb7b068bf39ee298e2f2f3f31a6431a5c115193bd653d3 \
                size    2925847

categories      net
license         GPL-2+
maintainers     nomaintainer
description     Collection of Routing daemons for OSPF BGP and RIP
long_description    Quagga is a routing software suite, providing implementations \
                of OSPFv2, OSPFv3, RIP v1 and v2, RIPng and BGP-4 for Unix \
                platforms, particularly FreeBSD, Linux, Solaris and NetBSD. \
                Quagga is a fork of GNU Zebra which was developed by Kunihiro \
                Ishiguro. The Quagga tree aims to build a more involved community \
                around Quagga than the current centralised model of GNU Zebra. \
                This port installs the binaries, but does not include startup \
                items, it should be considered experimental.

homepage        https://www.quagga.net
github.tarball_from releases

depends_build   port:gawk \
                port:pkgconfig

depends_lib     port:readline

patchfiles      quagga-patch2.diff \
                dynamic_lookup-11.patch \
                implicit.patch \
                packed.patch \
                sdkroot.patch \
                undefined.patch

post-patch {
    reinplace "s|@SDKROOT@|${configure.sdkroot}|g" ${worksrcpath}/configure.ac
}

# We are patching configure.ac
use_autoreconf  yes
configure.checks.implicit_function_declaration.whitelist-append strchr

configure.args  --localstatedir=${prefix}/var/run/quagga \
                --sysconfdir=${prefix}/etc/quagga \
                --disable-pimd \
                --disable-silent-rules \
                --enable-vty-group=staff

add_users       quagga group=quagga realname=Quagga home=${prefix}/var/quagga

post-destroot {
    xinstall -o quagga -g quagga -m 755 -d \
        ${destroot}${prefix}/var/run/quagga ${destroot}${prefix}/etc/quagga \
        ${destroot}${prefix}/var/quagga/logs
}

post-activate {
    # Make sure initial conf files are present and setup correctly
    foreach f { bgpd.conf ospf6d.conf ospfd.conf ripd.conf ripngd.conf zebra.conf } {
        if {![file exists ${prefix}/etc/quagga/${f}]} {
            file copy ${prefix}/etc/quagga/${f}.sample \
                ${prefix}/etc/quagga/${f}
        }
    }
}

destroot.keepdirs   ${destroot}${prefix}/var/run/quagga \
                    ${destroot}${prefix}/var/quagga/logs

notes "
The routing protocol daemons are in ${prefix}/sbin
bgpd ospfd ospf6d ripd ripng isisd zebra
These have not been well tested on Mac OS X (yet)
The man files for the above are in section 8
The sample configs in ${prefix}/etc/quagga
sudo cp <daemon>.conf.sample <daemon>.conf
and edit as needed.
No Startup Items have been made (yet)
As an example to start one of the daemons use
sudo ospfd -d
These drop root privileges and run as quagga/quagga
To manage these daemons use
telnet localhost:2604
For more info see ${homepage}
To stop one of the daemons use e.g.
sudo kill `cat ${prefix}/var/run/quagga/ospfd.pid`
"
