class ShadowsocksLibev < Formula desc "Libev port of shadowsocks" homepage "https://github.com/shadowsocks/shadowsocks-libev" url "https://github.com/shadowsocks/shadowsocks-libev/releases/download/v3.3.3/shadowsocks-libev-3.3.3.tar.gz" sha256 "677356a5ed6b5ae9e32a898061db2587158ff27e245db03f4bde9b006ef12dc9" bottle do cellar :any sha256 "be5c6b0ee030a71916cb8eaa46c5661f1ab92a382556d2e45b748ad6d05b1ec1" => :catalina sha256 "7698e2260405590b827b65a1d2e2db18cdb62973021af8207bca803ff8f0bcad" => :mojave sha256 "ffd307be32d7040633103eabab039b856df5e99f4e2512386c954dde32262c19" => :high_sierra end head do url "https://github.com/shadowsocks/shadowsocks-libev.git" depends_on "autoconf" => :build depends_on "automake" => :build depends_on "libtool" => :build end depends_on "asciidoc" => :build depends_on "xmlto" => :build depends_on "c-ares" depends_on "libev" depends_on "libsodium" depends_on "mbedtls" depends_on "pcre" def install ENV["XML_CATALOG_FILES"] = etc/"xml/catalog" system "./autogen.sh" if build.head? system "./configure", "--prefix=#{prefix}" system "make" (buildpath/"shadowsocks-libev.json").write <<~EOS { "server":"localhost", "server_port":8388, "local_port":1080, "password":"barfoo!", "timeout":600, "method":null } EOS etc.install "shadowsocks-libev.json" inreplace Dir["man/*"], "/etc/shadowsocks-libev/config.json", "#{etc}/shadowsocks-libev.json" system "make", "install" end plist_options :manual => "#{HOMEBREW_PREFIX}/opt/shadowsocks-libev/bin/ss-local -c #{HOMEBREW_PREFIX}/etc/shadowsocks-libev.json -u" def plist; <<~EOS Label #{plist_name} ProgramArguments #{opt_bin}/ss-local -c #{etc}/shadowsocks-libev.json -u RunAtLoad KeepAlive EOS end test do (testpath/"shadowsocks-libev.json").write <<~EOS { "server":"127.0.0.1", "server_port":9998, "local":"127.0.0.1", "local_port":9999, "password":"test", "timeout":600, "method":null } EOS server = fork { exec bin/"ss-server", "-c", testpath/"shadowsocks-libev.json" } client = fork { exec bin/"ss-local", "-c", testpath/"shadowsocks-libev.json" } sleep 3 begin system "curl", "--socks5", "127.0.0.1:9999", "github.com" ensure Process.kill 9, server Process.wait server Process.kill 9, client Process.wait client end end end