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

set version         0.27.0
revision            0

checksums           rmd160  70c4ae33ef3ce59e2f4ca7c7868b736a2676e8f4 \
                    sha256  4112afb1571f8f27c80eec61315b364ba41aa93e1e6883456a6a0ac1b6f2b7ff \
                    size    16072167

# the last IPFS which can be build 1.17.13
if {${os.platform} eq "darwin" && ${os.major} <= 16} {
    version         0.15.0
    revision        0
    epoch           1

    checksums       rmd160  b946e1023c492cb06e50cb69ed43123e414ac9ac \
                    sha256  e0666fb11ec4164f5a9bedfc4cd3e7b1f85ca7f18e27c44ed667022898bb9f66 \
                    size    13319349
}

go.setup            github.com/ipfs/kubo ${version} v
go.author           go
go.project          ipfs
# Delete this on next update to use golang PortGroup's default ('archive')
github.tarball_from tarball
name                ipfs

description         Global, versioned, peer-to-peer filesystem

long_description    IPFS is a global, versioned, peer-to-peer filesystem. \
                    It combines good ideas from Git, BitTorrent, Kademlia, \
                    SFS, and the Web. It is like a single bittorrent swarm, \
                    exchanging git objects. IPFS provides an interface as \
                    simple as the HTTP web, but with permanence built in.

categories          net
installs_libs       no
license             MIT
maintainers         {ogsite.net:sirn @sirn} \
                    {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

set tagged_version  ${github.tag_prefix}${version}
set ipfs_dist_url   https://dist.ipfs.io/go-ipfs/
homepage            https://ipfs.io
master_sites        ${ipfs_dist_url}${tagged_version}/
distname            go-ipfs-source
dist_subdir         ${name}/${version}

build.cmd           make
build.target        build

# FIXME: This port currently can't be built without allowing go mod to fetch
# dependencies during the build phase. See
# https://trac.macports.org/ticket/61192
go.offline_build no

extract.dir         ${workpath}/${go.author}-${go.project}-${version}

destroot {
    xinstall -m 0755 ${worksrcpath}/cmd/ipfs/ipfs ${destroot}${prefix}/bin
    xinstall -d ${destroot}${prefix}/share/examples/${name}
    xinstall -W ${worksrcpath}/misc/launchd io.ipfs.ipfs-daemon.plist ${destroot}${prefix}/share/examples/${name}/ipfs.plist
    reinplace "s|{{IPFS_BIN}}|${prefix}/bin/ipfs|g" ${destroot}${prefix}/share/examples/${name}/ipfs.plist
    reinplace "s|{{IPFS_PATH}}|/Users/USERNAME/.ipfs|g" ${destroot}${prefix}/share/examples/${name}/ipfs.plist
}

notes-append \
    "IPFS provides an example launchd plist. To use it:" \
    "1. Copy ${prefix}/share/examples/${name}/ipfs.plist to ~/Library/LaunchAgents" \
    "2. Edit ipfs.plist by replacing USERNAME with your actual username" \
    "3. Log out and in again, or run: launchctl load ~/Library/LaunchAgents/ipfs.plist"

livecheck.url       ${ipfs_dist_url}
livecheck.regex     {go-ipfs/v([0-9.]+)}
livecheck.type      regex
