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

# strnlen
legacysupport.newest_darwin_requires_legacy 10

github.setup        networkupstools nut 2.8.2 v
github.tarball_from releases
revision            0

homepage            https://www.networkupstools.org/

description         Network based UPS monitoring tool

long_description    Network UPS Tools is a collection of programs \
                    which provide a common interface for monitoring \
                    and administering UPS hardware.

categories          sysutils
maintainers         nomaintainer
# The files in scripts/perl and scripts/python are under other licenses
# but we don't use them in this port.
license             GPL-2+

checksums           rmd160  b4de79fe2a4dfe331efe59a2ec356ab6962ceee2 \
                    sha256  e4b4b0cbe7dd39ba9097be7f7d787bb2fffbe35df64dff53b5fe393d659c597d \
                    size    5599935

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:libtool \
                    port:libusb-compat \
                    port:neon \
                    port:tcp_wrappers \
                    port:nss

patchfiles          dynamic_lookup-11.patch

# https://trac.macports.org/ticket/71514
patchfiles-append   patch-legacy-macos.diff

set userName        _nut
set groupName       _nut
add_users           ${userName} group=${groupName}
set stateDir        ${prefix}/var/db/ups
destroot.keepdirs   ${destroot}${stateDir}

configure.args      --disable-silent-rules \
                    --with-serial=no \
                    --with-usb=auto \
                    --with-snmp=no \
                    --with-hal=auto \
                    --with-cgi=no \
                    --with-neonxml=no \
                    --with-ssl=yes \
                    --with-ipv6=no \
                    --with-statepath=${stateDir} \
                    --with-pidpath=${prefix}/var/run \
                    --with-hotplug-dir=${prefix}/etc/nut/hotplug \
                    --with-udev-dir=${prefix}/etc/nut/udev
if {[getuid] == 0} {
    configure.args-append \
                    --with-user=${userName} \
                    --with-group=${groupName}
}

pre-destroot {
    if {[getuid] == 0} {
        set userargs [list -g ${groupName} -o ${userName}]
    } else {
        set userargs [list]
    }
    xinstall -d -m 0770 {*}${userargs} ${destroot}${stateDir}
}

## variant snmp {
##      configure.args-append   --with-snmp=yes
##      configure.args-delete   --with-snmp=no
##      depends_lib-append      port:net-snmp
## }
