class ShadowsocksLibev < Formula desc "Libev port of shadowsocks" homepage "https://github.com/shadowsocks/shadowsocks-libev" url "https://github.com/shadowsocks/shadowsocks-libev/archive/v2.4.1.tar.gz" sha256 "a11a341adf9a921bb9aa9529472b722fba2836a92eef7ef8820f7c3226acef1c" head "https://github.com/shadowsocks/shadowsocks-libev.git" bottle do cellar :any sha256 "1b1117025762b1d32e3b8ebcb56ff0d40ede3907f05217a60548fa329327033a" => :el_capitan sha256 "946939bffb4bdd39acd28203f9e71abf07695755fc5d9e511427933fcbd6232a" => :yosemite sha256 "5aaa91595a1c93e016bd582e20bfe84e4a1e10233af065edfa347695a7ff5e5d" => :mavericks end depends_on "openssl" def install args = ["--prefix=#{prefix}"] system "./configure", *args system "make" bin.install "src/ss-local", "src/ss-tunnel", "src/ss-server", "src/ss-manager" (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" rm "man/ss-redir.1" inreplace Dir["man/*"], "/etc/shadowsocks-libev/config.json", "#{etc}/shadowsocks-libev.json" man8.install Dir["man/*.8"] man1.install Dir["man/*.1"] 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 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 SuccessfulExit EOS end end