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

github.setup        brona iproute2mac 1.7.2 v
revision            0
supported_archs     noarch
categories          net python
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             MIT

description         CLI wrapper for basic network utilites on Mac OS X inspired with iproute2 on Linux systems - ip command.
long_description    {*}${description} \
                    Provided functionality is limited and command output is not fully compatible with iproute2. \
                    Goal of this project is to make basic network configuration/debug tasks on Mac OS X easy \
                    for admins who already use Linux systems.

github.tarball_from releases

checksums           rmd160  27347f1d0cd2d5110b05773bc8fb98249d4111d3 \
                    sha256  b2460043a49f83e93f534dd7ebf31d1e3394df1c70e0a299682815bc63ff295d \
                    size    20770

pre-configure {
    if {![variant_isset python310] && ![variant_isset python311] && ![variant_isset python312] && \
        ![variant_isset python313] && ![variant_isset python314]} {
        ui_error "${name} requires Python, please use a Python variant."
        return -code error
    }
}

use_configure       no
build {}

destroot {
    xinstall -d ${destroot}${prefix}/libexec/${name}
    xinstall -m 755 {*}[glob ${worksrcpath}/src/*.py] ${destroot}${prefix}/libexec/${name}
    foreach cmd {ip bridge} {
        ln -s ${prefix}/libexec/${name}/${cmd}.py ${destroot}${prefix}/sbin/${cmd}
    }
    foreach cmd {ss} {
        ln -s ${prefix}/libexec/${name}/${cmd}.py ${destroot}${prefix}/bin/${cmd}
    }
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} README.md LICENSE AUTHORS ${destroot}${prefix}/share/doc/${name}
}

proc python-depends {python_branch} {
    set python_version [string map {. ""} ${python_branch}]
    depends_run-append  port:python${python_version}
    post-patch {
        reinplace "s|#!/usr/bin/env python3|#!${prefix}/bin/python${python_branch}|" {*}[glob ${worksrcpath}/src/*.py]
    }
}

variant python314 conflicts python310 python311 python312 python313 description {Use Python 3.14 as interpreter} {
    set ::python_branch 3.14
    python-depends ${::python_branch}
}

variant python313 conflicts python310 python311 python312 python314 description {Use Python 3.13 as interpreter} {
    set ::python_branch 3.13
    python-depends ${::python_branch}
}

variant python312 conflicts python310 python311 python313 python314 description {Use Python 3.12 as interpreter} {
    set ::python_branch 3.12
    python-depends ${::python_branch}
}

variant python311 conflicts python310 python312 python313 python314 description {Use Python 3.11 as interpreter} {
    set ::python_branch 3.11
    python-depends ${::python_branch}
}

variant python310 conflicts python311 python312 python313 python314 description {Use Python 3.10 as interpreter} {
    set ::python_branch 3.10
    python-depends ${::python_branch}
}

if {![variant_isset python310] && ![variant_isset python311] && ![variant_isset python312] && ![variant_isset python313]} {
    default_variants +python314
}

variant mpsudo description {Use sudo command provided by MacPorts instead of the system} {
    depends_run-append  port:sudo
    post-patch {
        reinplace "s|/usr/bin/sudo|${prefix}/bin/sudo|g" ${worksrcpath}/src/iproute2mac.py
    }
}
