homebrew-core/Formula/v2ray.rb

121 lines
3.6 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.37.3.tar.gz"
sha256 "b5001622b8a67c4a8e57651ef0f9d23f20604b7a65a18db47e51c1e19c3be08a"
license all_of: ["MIT", "CC-BY-SA-4.0"]
head "https://github.com/v2fly/v2ray-core.git"
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "40f99b12b5b55b47d14349c612d188df63931dca8d483b5da661d8f4fd21af97"
sha256 cellar: :any_skip_relocation, big_sur: "a2f5f1604148a09afe67dc79ad2666fa4b64d21497a7b22f387db1a0619a3929"
sha256 cellar: :any_skip_relocation, catalina: "8c62717111cbe94e31a5d180c78980159ed30c918534929c39841cdc369aecc5"
sha256 cellar: :any_skip_relocation, mojave: "27b44137dd25340c495affb4023cc2c60f7ab0f772183574636f6d2780719008"
end
depends_on "go" => :build
resource "geoip" do
url "https://github.com/v2fly/geoip/releases/download/202104080008/geoip.dat"
sha256 "1ba724e396f31e89d05f4cc9e912e13c1c5ea4478a2a0901e9cbb9f9a8b9c5db"
end
resource "geosite" do
url "https://github.com/v2fly/domain-list-community/releases/download/20210407065022/dlc.dat"
sha256 "3fb0dc75a94fafe55445ffd14c2317c8f871d63732170b5c8d5e9d2efcf9c655"
end
def install
ldflags = "-s -w -buildid="
execpath = libexec/name
system "go", "build", *std_go_args, "-o", execpath,
"-ldflags", ldflags,
"./main"
system "go", "build", *std_go_args,
"-ldflags", ldflags,
"-tags", "confonly",
"-o", bin/"v2ctl",
"./infra/control/main"
(bin/"v2ray").write_env_script execpath,
V2RAY_LOCATION_ASSET: "${V2RAY_LOCATION_ASSET:-#{pkgshare}}"
pkgetc.install "release/config/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"
},
{
"domains": [
"geosite: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