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.39.2.tar.gz"
sha256 "bcb35c0fd3fed604762b4c2a0950718b0118d7f4cb0ca9987d716a6a6e471b2b"
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: "e8ee950a404d8393b41fc960d643c61348ca79d23c3fb8be1002e8e8a28ccb56"
sha256 cellar: :any_skip_relocation, big_sur: "ba6faaabd3976e288f342725059c1652cbeea26a4d8cb92897aad3b85a199a7d"
sha256 cellar: :any_skip_relocation, catalina: "2fe3c93707cd1abf15fd0619bbca35c334dff3d03fc607fd60dfd226abfea4a4"
sha256 cellar: :any_skip_relocation, mojave: "5de7ff4c46993114f85e987807d7cc106ddee0bbc666359e56def4d572c3a556"
end
depends_on "go" => :build
resource "geoip" do
url "https://github.com/v2fly/geoip/releases/download/202105270041/geoip.dat"
sha256 "a5f1cec9c252197a07a4b7b7e89da08dec65692715beb5ecad1106c2dea3c73c"
end
resource "geosite" do
url "https://github.com/v2fly/domain-list-community/releases/download/20210526032424/dlc.dat"
sha256 "fd83fe6cd88aaf2391e506fc6aba2d75067df729555341c747c00290a25d323d"
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