homebrew-core/Formula/v2ray.rb

106 lines
3.0 KiB
Ruby

class V2ray < Formula
desc "Platform for building proxies to bypass network restrictions"
homepage "https://v2fly.org/"
url "https://github.com/v2fly/v2ray-core/archive/v4.33.0.tar.gz"
sha256 "ce456df0a798e1ed76ec014cb619e89c508bfb812c689260067575ee94e18c76"
license all_of: ["MIT", "CC-BY-SA-4.0"]
head "https://github.com/v2fly/v2ray-core.git"
bottle do
cellar :any_skip_relocation
sha256 "124dd5f5dc2499ae80e44fa6763afa47852466de0454838dd71b0a405969e950" => :big_sur
sha256 "132fcde2858d46f2ab08234dc99d466cc3cea825cf2ecc3a74020727d6efadca" => :catalina
sha256 "2fbeee703cfc396362543b0353dfbff527d88a37a77d3cc5dd7f60afe582db6f" => :mojave
end
depends_on "go" => :build
resource "geoip" do
url "https://github.com/v2fly/geoip/releases/download/202011190012/geoip.dat"
sha256 "022e6426f66cd7093fc2454c28537d2345b4fce49dc97b81ddfec07ce54e7081"
end
resource "geosite" do
url "https://github.com/v2fly/domain-list-community/releases/download/20201122065644/dlc.dat"
sha256 "574af5247bb83db844be03038c8fed1e488bf4bd4ce5de2843847cf40be923c1"
end
def install
ldflags = "-s -w -buildid="
system "go", "build", *std_go_args,
"-ldflags", ldflags,
"./main"
system "go", "build", *std_go_args,
"-ldflags", ldflags,
"-tags", "confonly",
"-o", bin/"v2ctl",
"./infra/control/main"
pkgetc.install "release/config/config.json" => "config.json"
resource("geoip").stage do
pkgshare.install "geoip.dat"
end
resource("geosite").stage do
pkgshare.install "dlc.dat" => "geosite.dat"
end
end
plist_options manual: "v2ray -config=#{HOMEBREW_PREFIX}/etc/v2ray/config.json"
def plist
<<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{bin}/v2ray</string>
<string>-config</string>
<string>#{etc}/v2ray/config.json</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOS
end
test do
(testpath/"config.json").write <<~EOS
{
"log": {
"access": "#{testpath}/log"
},
"outbounds": [
{
"protocol": "freedom",
"tag": "direct"
}
],
"routing": {
"rules": [
{
"ip": [
"geoip:private"
],
"outboundTag": "direct",
"type": "field"
}
]
}
}
EOS
output = shell_output "#{bin}/v2ray -c #{testpath}/config.json -test"
assert_match "Configuration OK", output
assert_predicate testpath/"log", :exist?
end
end