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

# Not planning to update past this version for minio port; major breaking
# change: https://min.io/docs/minio/linux/operations/install-deploy-manage/migrate-fs-gateway.html
version             2022-10-24T18-35-07Z
set commit          fc6c7949727ec261cd57fbdb02fa7575d0fd8e61

set relversion      [regsub {(T..)-(..)-(..Z)} $version {\1:\2:\3}]
# This is not used for fetching, but is compiled into the executable

github.setup        minio minio $version RELEASE.
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            0

homepage            https://minio.io
categories          www
maintainers         {eborisch @eborisch} openmaintainer
description         Open source Amazon S3-compatible object storage server.
long_description \
    {*}${description} It is best suited for storing unstructured data such as \
    photos, videos, log files, backups and container / VM images. Size of an \
    object can range from a few KBs to a maximum of 5TB. See also minio-mc \
    for command-line client.

license             AGPL-3

checksums \
    rmd160  d1f250ab0651950672afcb10e1b4aa16885166e3 \
    sha256  b614f85ecdc6d1b9119210bc23592e745cf19fba1e5b65e71c35dd8db1e76e67 \
    size    13211640

set goproj          github.com/${github.author}/${github.project}

depends_lib         port:go
platforms           darwin
use_configure       no
worksrcdir          src/${goproj}

post-extract {
    xinstall -d ${workpath}/src/github.com/${github.author}
    move ${workpath}/${name}-${github.version} \
        ${worksrcpath}
}

build {
    system -W ${worksrcpath} "GOPATH=${workpath} \
      CGO_ENABLED=0 GO111MODULE=on ${prefix}/bin/go build -tags kqueue -v \
      -o ${workpath}/${github.project} \
      -ldflags '-X ${goproj}/cmd.Version=${relversion} \
                -X ${goproj}/cmd.ReleaseTag=RELEASE.${version} \
                -X ${goproj}/cmd.CommitID=${commit} \
                -X ${goproj}/cmd.ShortCommitId=[string range ${commit} 0 11]'"
}

destroot {
    xinstall ${workpath}/${github.project} ${destroot}${prefix}/bin

    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} README.md LICENSE NOTICE \
        ${destroot}${docdir}

    # Config / log / storage directories
    set logPath     ${destroot}${prefix}/var/log/${name}
    set varPath     ${destroot}${prefix}/var/${name}
    set confPath    ${destroot}${prefix}/etc/${name}
    xinstall -m 700 -d ${logPath} ${confPath} ${varPath}
    destroot.keepdirs ${logPath} ${varPath} ${confPath}
}

startupitem.create      yes
startupitem.name        ${name}
startupitem.executable  ${prefix}/bin/${name} server \
                           --config-dir=${prefix}/etc/minio \
                           --address :9000 \
                           ${prefix}/var/minio
startupitem.logfile     ${prefix}/var/log/minio/server.log
startupitem.logevents   yes

notes " \
If you use 'port load minio':
 * after loading, view ${prefix}/var/log/minio/server.log for server info.
 * Object storage in ${prefix}/var/minio. To relocate:
 1) Copy with all (* and .*) contents to desired location.
 2) Replace ${prefix}/var/minio with symlink to new storage.

Or use 'minio server <dir>' to run a server manually / roll your own
startup system. Note './.minio/' will be created by default.

See also minio-mc port for command-line interaction.
"
