homebrew-core/Formula/shadowsocks-libev.rb
2015-09-20 08:25:07 -07:00

94 lines
2.8 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.3.3.tar.gz"
sha256 "c00e18a19f20b837ea7d74c98720536044338daf652db1cdad3eae5d7a2718e5"
head "https://github.com/shadowsocks/shadowsocks-libev.git"
bottle do
cellar :any
sha256 "31b22b39c5a8dd12435a5267f3804849516b6e13341a0a7154ee25c2f3373e2a" => :el_capitan
sha256 "30792d0d594888993e0a06e86471be7ce37213bcb30272ac09358f5068a3163a" => :yosemite
sha256 "ad2d76f3934d876c4243425e261e675734c178efc06bd648c0644058b830644a" => :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>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
</dict>
</plist>
EOS
end
end