105 lines
3.1 KiB
Ruby
105 lines
3.1 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.36.2.tar.gz"
|
|
sha256 "e7f7ceefd4cd9d2e57d18cecf55228a5a126c6ed5ee53767660601c35e70535c"
|
|
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: "b1d7c8aac5a4b0414a52cc39fb2bd1db36dac123e9641118c94019a93ae24736"
|
|
sha256 cellar: :any_skip_relocation, big_sur: "c22a86596d2b29a371c08339c476ef3c0384dcc14acba089d16e942b1e3b90a1"
|
|
sha256 cellar: :any_skip_relocation, catalina: "0d9a98777109bbc9b80be013586e9db4629496f4bc17f64cc8c734565e961ca8"
|
|
sha256 cellar: :any_skip_relocation, mojave: "6907b7aaa66415792d842edf2a719cbe9ec312578a905fdb56d0117ac4f2c0a6"
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
|
|
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"
|
|
pkgshare.install "release/config/geoip.dat"
|
|
pkgshare.install "release/config/geosite.dat"
|
|
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
|