class ShadowsocksLibev < Formula desc "Libev port of shadowsocks" homepage "https://github.com/shadowsocks/shadowsocks-libev" url "https://github.com/shadowsocks/shadowsocks-libev/archive/v2.5.2.tar.gz" sha256 "05d41e6c7c4d81add392d13152b7d9eedd253b334ba60a661174c49438aa1296" head "https://github.com/shadowsocks/shadowsocks-libev.git" bottle do cellar :any sha256 "6823efe0e71a2608a138f7d2b5a7ba7739c3017230b0bddc9e635ef64e1345a0" => :sierra sha256 "6108132161a42b9d19071b70afd304039b14703cb763759f35140a436a180161" => :el_capitan sha256 "3ca40bd8248bd99dc88293c943f1ed05d6157ca80aa024354217fb2a3cfc9269" => :yosemite sha256 "2c24e399f5b21a4f302311fff02a2a1d06322af87cbfb98c56fb8590008a43cd" => :mavericks end depends_on "asciidoc" => :build depends_on "xmlto" => :build depends_on "openssl" depends_on "pcre" def install ENV["XML_CATALOG_FILES"] = etc/"xml/catalog" system "./configure", "--prefix=#{prefix}" system "make" (buildpath/"shadowsocks-libev.json").write <<-EOS.undent { "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" def plist; <<-EOS.undent Label #{plist_name} ProgramArguments #{opt_bin}/ss-local -c #{etc}/shadowsocks-libev.json RunAtLoad KeepAlive EOS end test do (testpath/"shadowsocks-libev.json").write <<-EOS.undent { "server":"127.0.0.1", "server_port":9998, "local":"127.0.0.1", "local_port":9999, "password":"test", "timeout":600, "method":"table" } 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