# -*- 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/apernet/hysteria 2.12.0 app/v
set git-commit      23c90861add39acd9adde1898b6ae052b3b3d877
# This line is for displaying commit in CLI only
revision            0
categories          net
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             MIT

description         network utility and proxy optimized for networks of poor quality
long_description    Hysteria is a feature-packed network utility optimized for networks of poor quality \
                    (e.g. satellite connections, congested public Wi-Fi, cross-country connection) \
                    powered by a custom version of QUIC protocol.

checksums           rmd160  7c8264bac62d0467c54f5580cbec2e737a58e72d \
                    sha256  0c37f3ddc51a80e0c33425380d09c045045ce68b7fa6453e2ba27a986e65d9f5 \
                    size    4554163

# Notes for updating this port:
# Remember to update git commit hash

set time [clock format [clock seconds] -format %Y-%m-%dT%H:%M:%S]
build.args-append   -ldflags=\"-X 'main.appVersion=v${version}' -X 'main.appCommit=${git-commit}' -X 'main.appDate=${time}'\" -o ../hysteria .
# go2port no longer works since 1.3.1 as there's no go.mod at project root
go.offline_build    no
build.dir           ${worksrcpath}/app

destroot {
    xinstall -m 0755 ${worksrcpath}/${name} ${destroot}${prefix}/bin/
    file mkdir ${destroot}${prefix}/etc/hysteria
    copy ${filespath}/server.json ${filespath}/client.json ${destroot}${prefix}/etc/hysteria/
}

post-activate {
    if {![file exists ${prefix}/etc/hysteria/config.json]} {
        copy ${prefix}/etc/hysteria/client.json ${prefix}/etc/hysteria/config.json
    }
}

notes-append "
    The default config file is copied to ${prefix}/etc/hysteria/config.json and its content\
    will be preserved across upgrades and reinstalls. The startup item will use this config\
    file by default.
"

startupitem.create          yes
startupitem.executable      ${prefix}/bin/hysteria --config ${prefix}/etc/hysteria/config.json
