homebrew-core/Formula/caddy.rb
2019-07-11 21:52:58 -04:00

64 lines
1.9 KiB
Ruby

class Caddy < Formula
desc "Alternative general-purpose HTTP/2 web server"
homepage "https://caddyserver.com/"
url "https://github.com/caddyserver/caddy/archive/v1.0.1.tar.gz"
sha256 "7cbd80c798a0db4195381f730f5409680c6e1239fbc06295b90b34f666a05692"
head "https://github.com/caddyserver/caddy.git"
bottle do
cellar :any_skip_relocation
sha256 "5e8f8e9822b41eae38560a9cfdebebfb504bc4dbd9b1bd62fc384e1f3edcee82" => :mojave
sha256 "c8c1937120d718bc3b0f7ceeaac6259d300873b3bce142dea140d6952f8af255" => :high_sierra
sha256 "290ffe78bdedbc9201203cd3cb473266a1477d5eb423cca25db280ef7e48e355" => :sierra
end
depends_on "go" => :build
def install
ENV["GOOS"] = "darwin"
ENV["GOARCH"] = "amd64"
(buildpath/"src/github.com/caddyserver").mkpath
ln_s buildpath, "src/github.com/caddyserver/caddy"
system "go", "build", "-ldflags",
"-X github.com/caddyserver/caddy/caddy/caddymain.gitTag=#{version}",
"-o", bin/"caddy", "github.com/caddyserver/caddy/caddy"
end
plist_options :manual => "caddy -conf #{HOMEBREW_PREFIX}/etc/Caddyfile"
def plist; <<~EOS
<?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>KeepAlive</key>
<true/>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/caddy</string>
<string>-conf</string>
<string>#{etc}/Caddyfile</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOS
end
test do
begin
io = IO.popen("#{bin}/caddy")
sleep 2
ensure
Process.kill("SIGINT", io.pid)
Process.wait(io.pid)
end
io.read =~ /0\.0\.0\.0:2015/
end
end