# -*- 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.44.1 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  074b5b2aeded243c45105873cac1cec610a259e1 \
                    sha256  b11d6ff12e69e1cc21e18e4eb6da2fb6332fa6a6cca53fb1a3f42e2484e0ebf3 \
                    size    1125812

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.
"
