# -*- 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.4 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  81d0d369a3e0f4397217e8027c5797cbd55de5da \
                    sha256  0130ba82ea79f04ba4f34c5249a85943977efd984ed7df6aec1a518d5a3594f8 \
                    size    6522704

# nut uses telnetlib.py which was removed in Python 3.13
set python_branch   3.12
set python_version  [string map {. {}} ${python_branch}]

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

depends_lib-append  port:libtool \
                    port:libusb-compat \
                    port:neon \
                    port:tcp_wrappers \
                    port:nss \
                    port:python${python_version}

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-append \
                    --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 \
                    --without-python2 \
                    --with-python=${prefix}/bin/python${python_branch} \
                    --with-python3=${prefix}/bin/python${python_branch}

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

github.livecheck.regex  {([0-9.]+)}
