homebrew-core/Formula/shadowsocks-libev.rb
2015-12-12 14:01:33 +00:00

91 lines
2.7 KiB
Ruby

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.2.tar.gz"
sha256 "0a2367b1f14fb68b0a8329ca2199abbe2f98e2caeb3234229396d10fd2becaa7"
head "https://github.com/shadowsocks/shadowsocks-libev.git"
bottle do
cellar :any
sha256 "9a81a9317f74cc1041bae7f2f51d5d0b5f34bffaf08948b4c1f9949d58c13645" => :el_capitan
sha256 "880f70623c3c00e328830a62c4e7d5a4f64fae856836962fd1eb911ba67157a0" => :yosemite
sha256 "693b63f995cf4ec389c26cdef2c324cd5602e27c49215a8c50469317ab230295" => :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
<?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>#{opt_bin}/ss-local</string>
<string>-c</string>
<string>#{etc}/shadowsocks-libev.json</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
EOS
end
end