class Vnstat < Formula desc "Console-based network traffic monitor" homepage "https://humdi.net/vnstat/" url "https://humdi.net/vnstat/vnstat-2.5.tar.gz" sha256 "f1bfb16911b28cb0db93341e65433da804ec178592b6728235a84b1c091d1578" head "https://github.com/vergoh/vnstat.git" bottle do sha256 "20c5f324f3ace6755f5f98bb54af26d774557e61783802c1f1b7bb3c3b1b5938" => :catalina sha256 "7e01be903cffd9278f118921a12af52135990ef07a7170676e3966e7d2c920f7" => :mojave sha256 "6b09ffb239d221379702ccbe866033d80eca38efe4148ef5fbba82c53060c973" => :high_sierra end depends_on "gd" def install inreplace %w[src/cfg.c src/common.h man/vnstat.1 man/vnstatd.8 man/vnstati.1 man/vnstat.conf.5].each do |s| s.gsub! "/etc/vnstat.conf", "#{etc}/vnstat.conf", false s.gsub! "/var/", "#{var}/", false s.gsub! "var/lib", "var/db", false s.gsub! "\"eth0\"", "\"en0\"", false end system "./configure", "--disable-dependency-tracking", "--disable-silent-rules", "--prefix=#{prefix}", "--sysconfdir=#{etc}", "--sbindir=#{bin}", "--localstatedir=#{var}" system "make", "install" end def post_install (var/"db/vnstat").mkpath (var/"log/vnstat").mkpath (var/"run/vnstat").mkpath end def caveats; <<~EOS To monitor interfaces other than "en0" edit #{etc}/vnstat.conf EOS end plist_options :startup => true, :manual => "#{HOMEBREW_PREFIX}/opt/vnstat/bin/vnstatd --nodaemon --config #{HOMEBREW_PREFIX}/etc/vnstat.conf" def plist; <<~EOS Label #{plist_name} ProgramArguments #{opt_bin}/vnstatd --nodaemon --config #{etc}/vnstat.conf KeepAlive RunAtLoad WorkingDirectory #{var} ProcessType Background EOS end test do cp etc/"vnstat.conf", testpath inreplace "vnstat.conf", "/usr/local/var", testpath/"var" (testpath/"var/db/vnstat").mkpath begin stat = IO.popen("#{bin}/vnstatd --nodaemon --config vnstat.conf") sleep 1 ensure Process.kill "SIGINT", stat.pid Process.wait stat.pid end assert_match "Info: Monitoring", stat.read end end