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

go.setup            github.com/bettercap/bettercap 2.42.0 v
go.toolchain_min    1.25.0
revision            0

homepage            https://www.bettercap.org

description         The Swiss Army knife for 802.11, BLE and Ethernet \
                    networks reconnaissance and MITM attacks.

long_description    bettercap is a powerful, easily extensible and portable \
                    framework written in Go which aims to offer to security \
                    researchers, red teamers and reverse engineers an easy to \
                    use, all-in-one solution with all the features they might \
                    possibly need for performing reconnaissance and attacking \
                    WiFi networks, Bluetooth Low Energy devices, wireless HID \
                    devices and Ethernet networks.

categories          net security
installs_libs       no
license             GPL-3
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

set ui_commit       6e126c470e97542d724927ba975011244127dbb1
set ui_distfile     ${ui_commit}${extract.suffix}
set main_distfile   ${distfiles}
master_sites-append https://github.com/bettercap/ui/archive/:ui
distfiles-append    ${ui_distfile}:ui

checksums           ${main_distfile} \
                    rmd160  7de1c7ad9fc34979b619988f8394635a29c0f4c7 \
                    sha256  cdcce5b68b426c286b0b6aa1aabd2c84f6e891dd3b6e441d4a61de07ccf653a3 \
                    size    12441846 \
                    ${ui_distfile} \
                    rmd160  c2121635595a241e20dbb48b8e2d86f333af8b01 \
                    sha256  8006a844d2e6a9678fe48c1e719022c2600b9fc8941bd5ee6c5777309edecc07 \
                    size    11308073

post-extract {
    delete ${worksrcpath}/modules/ui/ui
    move ${workpath}/ui-${ui_commit} ${worksrcpath}/modules/ui/ui
}

depends_build-append \
                    port:pkgconfig

depends_lib-append  path:lib/pkgconfig/libusb-1.0.pc:libusb

# 2.42 uses gopacket 1.7.2, which on macOS calls pcap_set_want_pktap. Only
# Apple's libpcap has it (since libpcap-48, OS X 10.10), so link the SDK's
# libpcap, ahead of any MacPorts libpcap in ${prefix}/lib.
configure.ldflags-prepend \
                    -L${configure.sdkroot}/usr/lib

go.offline_build    no

post-patch {
    reinplace "s|/usr/local|${prefix}|g" ${worksrcpath}/caplets/env.go
}

build.cmd           make
build.target        build

destroot {
    system -W ${worksrcpath} "make -w PREFIX=${destroot}${prefix} install"
}
