# -*- 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/XTLS/Xray-core 25.10.15 v
revision            0
name                xray
categories          net security
homepage            https://xtls.github.io/
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             MPL-2

description         Platform for building proxies to bypass network restrictions
long_description    Project X originates from XTLS protocol, provides a set of network tools such as Xray-core. \
                    Xray-core is a superset of v2ray-core, with various improvements such as XTLS, and is mostly \
                    compatible with v2ray-core.

checksums           rmd160  71a7e5d4c92c36549c23290167cbb01d56376a6d \
                    sha256  5df030f456db58b682110545e19da9b971303387955562ec408f484580450736 \
                    size    703659

go.offline_build    no
# Since v1.8.6, building requires dependencies from a domain not supported by go PG: git.zx2c4.com

depends_build-append \
                    port:wget

build.args          -o ./${name}
build.post_args     -trimpath \
                    -buildvcs=false \
                    -ldflags='-s -w -buildid='
build.dir           ${worksrcpath}/main

destroot {
    xinstall -m 0755 ${worksrcpath}/main/${name} ${destroot}${prefix}/bin/
    xinstall -d ${destroot}${prefix}/etc/${name}
    # borrow v2ray example config
    system -W ${destroot}${prefix}/etc/${name} "wget https://raw.githubusercontent.com/v2fly/v2ray-core/v5.22.0/release/config/config.json"
}

post-destroot {
    file rename ${destroot}${prefix}/etc/${name}/config.json ${destroot}${prefix}/etc/${name}/config.json.example
}

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

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

variant geoip description {Install geoip and geosite from Project V, enables routing rules. Also provided by v2ray port.} {
    conflicts v2ray
    post-destroot {
        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"
    }
}

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