class Vnstat < Formula desc "Console-based network traffic monitor" homepage "https://humdi.net/vnstat/" url "https://humdi.net/vnstat/vnstat-2.2.tar.gz" sha256 "c60a7bc35e0247b0d2e628d8fc39427f2482e844c2c7b9cdbfc814463310e02c" head "https://github.com/vergoh/vnstat.git" bottle do sha256 "216012c13a9fe1dacbecefaa0c81d057af90a56d9a57659499209fbf52cd6802" => :mojave sha256 "2998e62e52715c24a7ef1163835181cb225cf80c437ff19f621b4e97849d049f" => :high_sierra sha256 "929192819e003cc52bd0216901d51f722c1e64bff18d17c4d4df74a2d7c61447" => :sierra end depends_on "gd" def install inreplace %w[src/cfg.c src/common.h man/vnstat.1 man/vnstatd.1 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