# -*- 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/maxmind/geoipupdate 6.0.0 v
# Delete this on next update to use golang PortGroup's default ('archive')
github.tarball_from tarball
revision            0
categories          devel net
maintainers         nomaintainer
description         Maxmind geoip databse updater
license             {Apache-2 MIT}

long_description    {*}${description}
homepage            https://dev.maxmind.com/geoip/geoipupdate/

depends_lib-append  port:zlib \
                    port:curl

depends_build-append \
                    port:pandoc \
                    port:perl5

checksums           ${distname}${extract.suffix} \
                    rmd160  417e901b848d8f334c955f9967a3bae31180cf1a \
                    sha256  569dd5995e6c7dd14cec75a8371265d22f22d84ca70496779f451298448a6465 \
                    size    46529

go.vendors          gopkg.in/yaml.v3 \
                        lock    v3.0.1 \
                        rmd160  e85ac1368fb7f9ef945b7fd7bd608a1f0d261c12 \
                        sha256  f3ea6be3f405ec25f8799773355aba54f8831d11f5315a01155bdc69b92eca7b \
                        size    91208 \
                    gopkg.in/check.v1 \
                        lock    038fdea0a05b \
                        rmd160  0f1896097db9d42b2fb5d62999bb52c77635f758 \
                        sha256  a82bd5c6960aa523c4dd8b30d52c3a7e8a5382e91f25862ef277bedf5c107007 \
                        size    31647 \
                    golang.org/x/sys \
                        lock    v0.8.0 \
                        rmd160  e678fbf405f6f2de2dd29b0a8b71baec9f1f1321 \
                        sha256  8c0922a390cb8c22c340d69aa24ecf3cd923b30ca28dc96965d32d4b3a4e917d \
                        size    1436856 \
                    golang.org/x/sync \
                        lock    v0.5.0 \
                        rmd160  510a82f4888a99756ad7287f8129821003540e2b \
                        sha256  7941823efeb75c83632f4a652286074917418f2539a05abf8fee6c09329711b3 \
                        size    17575 \
                    github.com/stretchr/testify \
                        lock    v1.8.4 \
                        rmd160  8e1645055c9b1d8e117df7974034e74b7f600d27 \
                        sha256  6d0a77075bbe0f8f1c0cbed51dd4d174579db976fef39d9ae6b500aab8917d6a \
                        size    104469 \
                    github.com/spf13/pflag \
                        lock    v1.0.5 \
                        rmd160  2ce81608a38c6f383a35bccd24d64361df5828c9 \
                        sha256  7f41acdcba65b1fab5b9b633947a139f9915b60f94bdab486cdbe9d90c54f61e \
                        size    50815 \
                    github.com/pmezard/go-difflib \
                        lock    v1.0.0 \
                        rmd160  fc879bfbdef9e3ff50844def58404e2b5a613ab8 \
                        sha256  7cd492737641847266115f3060489a67f63581e521a8ec51efbc280c33fc991f \
                        size    11409 \
                    github.com/niemeyer/pretty \
                        lock    a10e7caefd8e \
                        rmd160  46bcfc3db9e3d98acbacd1f96d9483fa360f88b7 \
                        sha256  97b952a32175ba84349ef352e523bfa15bf3a06e07e44458a908061fbc519b40 \
                        size    9405 \
                    github.com/kr/text \
                        lock    v0.2.0 \
                        rmd160  48558c7e8ff67d510f83c66883907e95f4783163 \
                        sha256  2f2e21ac8a9d523e88cbba4039441defc4a66bfaa78811c900a88fcf28729c4c \
                        size    8702 \
                    github.com/gofrs/flock \
                        lock    v0.8.1 \
                        rmd160  7ccfc1c50e85c62dab7e3ad2b0c7a0212c4f481c \
                        sha256  6e35685e7796d4b36b90d4a908270e16868a44e06fcb890c1ec13d34cbb092ea \
                        size    9059 \
                    github.com/davecgh/go-spew \
                        lock    v1.1.1 \
                        rmd160  7c02883aa81f81aca14e13a27fdca9e7fbc136f7 \
                        sha256  e85d6afa83e64962e0d63dd4812971eccf2b9b5445eda93f46a4406f0c177d5f \
                        size    42171 \
                    github.com/cenkalti/backoff \
                        lock    v4.2.1 \
                        rmd160  e4ac343410906a6a1ab0acd578ce034783b5ab42 \
                        sha256  f30a8b3e79935ada4f425a1e19ba42863bc00e42a981d5b936f7555bd326651d \
                        size    10399

build.args          "-ldflags '" \
                    "-X main.defaultConfigFile=${prefix}/etc/GeoIP.conf" \
                    "-X main.defaultDatabaseDirectory=${prefix}/share/GeoIP" \
                    "-X main.version=${version}'" \
                    ./cmd/${name}

set docs_path       ${worksrcpath}/doc
set conf_path       ${worksrcpath}/conf

test.run            yes
test.cmd            ${worksrcpath}/${name}
test.target         {}
test.args           "-V"

post-build {
    foreach f [concat [glob -type f -dir ${docs_path} *.md] \
        ${conf_path}/GeoIP.conf.default] {

        # update paths before generating man pages
        reinplace -q "s|CONFFILE|${prefix}/etc/GeoIP.conf|g" ${f}
        reinplace -q "s|DATADIR|${prefix}/share/GeoIP|g" ${f}
        reinplace -q "s|\$\$||g" ${f}
    }
    reinplace "s|#!/usr/bin/env perl|#!${prefix}/bin/perl5|" \
        ${worksrcpath}/dev-bin/make-man-pages.pl
    system -W ${docs_path} "${worksrcpath}/dev-bin/make-man-pages.pl ${docs_path}"
}

destroot.keepdirs   ${destroot}${prefix}/share/GeoIP
destroot {
    # install bin file, man pages and config file
    xinstall -m 0755 ${worksrcpath}/${name} ${destroot}${prefix}/bin
    file copy ${docs_path}/${name}.1 ${destroot}${prefix}/share/man/man1
    file copy ${docs_path}/GeoIP.conf.5 ${destroot}${prefix}/share/man/man5
    file copy ${conf_path}/GeoIP.conf.default ${destroot}${prefix}/etc

    # install doc files
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -W ${worksrcpath} -m 0444 CHANGELOG.md LICENSE-APACHE LICENSE-MIT \
        ${destroot}${prefix}/share/doc/${name}
}

post-activate {
    #- set up to use the free DBs if we don't already have a configuration
    if {![file exists ${prefix}/etc/GeoIP.conf]} {
        file rename ${prefix}/etc/GeoIP.conf.default ${prefix}/etc/GeoIP.conf
    }
}
