# -*- 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.3
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  c32f606e696e224f56c5989d472604a3b550bbe3 \
                        sha256  5bfb3d9efd75d33bfee81fb8dae935178f42689fe0165fc1f5c5a312a0162541 \
                        size    1548274

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