class Clash < Formula desc "Rule-based tunnel in Go" homepage "https://github.com/Dreamacro/clash" url "https://github.com/Dreamacro/clash/archive/v1.3.0.tar.gz" sha256 "34a31e12eb7e639bdc2e19421fe3a8d9ad710e7d4c13bfc361c2023c9dfe04f6" license "GPL-3.0-only" bottle do cellar :any_skip_relocation sha256 "d3c6497c1d3b6f6c4c7c8c611a964d2d9acf54fc7e0f11e1f4b7ba0cfc1bb75f" => :big_sur sha256 "05c3cc38443156b857ba98ec54b8b7ba413d464ec76aad2283487560fa687599" => :catalina sha256 "bbc2a5cc2abc096ed91ca251a2fcac994fc8ecd1c327472eaa5bfdf67f074c77" => :mojave end depends_on "go" => :build depends_on "shadowsocks-libev" => :test def install system "go", "build", *std_go_args end plist_options manual: "#{HOMEBREW_PREFIX}/opt/clash/bin/clash" def plist <<~EOS Label #{plist_name} ProgramArguments #{opt_bin}/clash RunAtLoad KeepAlive StandardOutPath #{var}/log/clash.log StandardErrorPath #{var}/log/clash.log EOS end test do ss_port = free_port (testpath/"shadowsocks-libev.json").write <<~EOS { "server":"127.0.0.1", "server_port":#{ss_port}, "password":"test", "timeout":600, "method":"chacha20-ietf-poly1305" } EOS server = fork { exec "ss-server", "-c", testpath/"shadowsocks-libev.json" } clash_port = free_port (testpath/"config.yaml").write <<~EOS mixed-port: #{clash_port} mode: global proxies: - name: "server" type: ss server: 127.0.0.1 port: #{ss_port} password: "test" cipher: chacha20-ietf-poly1305 EOS system "#{bin}/clash", "-t", "-d", testpath # test config && download Country.mmdb client = fork { exec "#{bin}/clash", "-d", testpath } sleep 3 begin system "curl", "--socks5", "127.0.0.1:#{clash_port}", "github.com" ensure Process.kill 9, server Process.wait server Process.kill 9, client Process.wait client end end end