# -*- 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/v2fly/v2ray-core 5.52.0 v
revision            0
name                v2ray
categories          net security
license             MIT
maintainers         {@casouri gmail.com:casouri} {i0ntempest @i0ntempest} openmaintainer
description         A proxy server for bypassing network restrictions

long_description    V2Ray supports many protocols, including Socks, HTTP, Shadowsocks, \
                    VMess, and more. And each protocol may have its own transport, such as TCP, \
                    mKCP, WebSocket, etc. Better yet, V2Ray has built in obfuscation \
                    to hide traffic in TLS, and can run in parallel with web servers.

homepage            https://www.v2fly.org

checksums           rmd160  20c9f4aaab92a3ca3696b627a1b0a1a6b8f207a5 \
                    sha256  b44f615b17bf627505b329a935568a5864a0d0cc071a5d7a71369da6f232f800 \
                    size    1305402

go.offline_build    no

depends_build-append \
                    port:wget

build.env-append    CGO_ENABLED=0
build.args          -o ./v2ray
build.post_args     -ldflags '-s -w'
build.dir           ${worksrcpath}/main

destroot {
    xinstall -m 755 ${worksrcpath}/main/v2ray ${destroot}${prefix}/bin
    xinstall -d ${destroot}${prefix}/etc/v2ray
    xinstall -m 640 ${worksrcpath}/release/config/config.json ${destroot}${prefix}/etc/v2ray
    system -W ${destroot}${prefix}/bin "wget https://github.com/v2fly/geoip/raw/release/geoip.dat"
    system -W ${destroot}${prefix}/bin "wget https://github.com/v2fly/domain-list-community/raw/release/dlc.dat -O geosite.dat"
}

# until #2365 is implemented, manually handle config file
post-destroot {
    file rename ${destroot}${prefix}/etc/v2ray/config.json ${destroot}${prefix}/etc/v2ray/config.json.example
}

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

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

notes "
    The default configuration file is copied to ${prefix}/etc/v2ray/config.json.\
    It is used by the startup item (service). You should edit or replace it.

    v2ctl utility has been removed in version 5. Its functionalities are now in\
    the main executable.
"
