# -*- 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/adnanh/webhook 2.8.2
# Delete this on next update to use golang PortGroup's default ('archive')
github.tarball_from tarball
revision            0

categories          net
license             MIT
maintainers         {judaew @judaew} openmaintainer

description         A lightweight incoming webhook server to run shell commands
long_description    \
    webhook is a lightweight configurable tool written in Go, that allows you \
    to easily create HTTP endpoints (hooks) on your server, which you can use \
    to execute configured commands. You can also pass data from the HTTP \
    request (such as headers, payload or query variables) to your commands. \
    webhook also allows you to specify rules which have to be satisfied in \
    order for the hook to be triggered.

checksums           ${distname}${extract.suffix} \
                        rmd160  0186e86341d7cf711278909d1f2b12367aa37b8d \
                        sha256  a74806f9b5e93203507cb82842ae68e71a6017b7f0c64a0a96a33b166688d060 \
                        size    1542928

# FIXME: This port currently can't be built without allowing go mod to fetch
go.offline_build no

destroot {
    xinstall -m 0755 ${worksrcpath}/${name} ${destroot}${prefix}/bin

    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 {*}[glob ${worksrcpath}/docs/*.md] \
        ${destroot}${prefix}/share/doc/${name}

    xinstall -d ${destroot}${prefix}/share/examples/${name}
    xinstall -m 0644 ${worksrcpath}/hooks.json.example \
        ${destroot}${prefix}/share/examples/${name}/hooks.json

    xinstall -d ${destroot}${prefix}/etc/${name}
    destroot.keepdirs ${destroot}${prefix}/etc/${name}
}

startupitem.create  yes
startupitem.start   \
    "${prefix}/bin/${name} -hooks ${prefix}/etc/webhook/hooks.json -verbose"
startupitem.stop    "kill \$(cat ${prefix}/var/run/${name}.pid) "
startupitem.pidfile auto ${prefix}/var/run/${name}.pid

notes "
A config must be created in
    ${prefix}/etc/webhook/hooks.json

An example config is
    ${prefix}/share/examples/webhook/hooks.json

Launch ${name} as daemon with
    sudo port load ${name}
or
    sudo launchctl load -w \\
        /Library/LaunchDaemons/org.macports.webhook.plist
"
