require 'formula' class Vnstat < Formula homepage 'http://humdi.net/vnstat/' url 'http://humdi.net/vnstat/vnstat-1.13.tar.gz' sha256 '6f4e2599ebb195b25f499d3e2e865aa14da336dfc9cc03a79181aa71f7ed99cd' depends_on 'gd' def install inreplace "src/cfg.c", '/etc/vnstat.conf', "#{etc}/vnstat.conf" inreplace "man/vnstat.1" do |s| s.gsub! '/etc/vnstat.conf', "#{etc}/vnstat.conf" s.gsub! '/var/lib/vnstat', "#{var}/db/vnstat" end inreplace "man/vnstatd.1" do |s| s.gsub! '/etc/vnstat.conf', "#{etc}/vnstat.conf" s.gsub! '/var/lib/vnstat', "#{var}/db/vnstat" s.gsub! '/var/log/vnstat.log', "#{var}/log/vnstat/vnstat.log" s.gsub! '/var/run/vnstat.pid', "#{var}/run/vnstat/vnstat.pid" end inreplace "man/vnstati.1" do |s| s.gsub! '/etc/vnstat.conf', "#{etc}/vnstat.conf" s.gsub! '/var/lib/vnstat', "#{var}/db/vnstat" end inreplace "man/vnstat.conf.5", '/etc/vnstat.conf', "#{etc}/vnstat.conf" inreplace "cfg/vnstat.conf" do |c| c.gsub! 'Interface "eth0"', %Q{Interface "en0"} c.gsub! 'DatabaseDir "/var/lib/vnstat"', %Q{DatabaseDir "#{var}/db/vnstat"} c.gsub! 'LogFile "/var/log/vnstat/vnstat.log"', %Q{LogFile "#{var}/log/vnstat/vnstat.log"} c.gsub! 'PidFile "/var/run/vnstat/vnstat.pid"', %Q{PidFile "#{var}/run/vnstat/vnstat.pid"} end (var+'db/vnstat').mkpath system "make", "all", "-C", "src", "CFLAGS=#{ENV.cflags}", "CC=#{ENV.cc}" (prefix+'etc').install "cfg/vnstat.conf" bin.install "src/vnstat", "src/vnstatd", "src/vnstati" man1.install "man/vnstat.1", "man/vnstatd.1", "man/vnstati.1" man5.install "man/vnstat.conf.5" end plist_options :startup => true def plist; <<-EOS.undent Label #{plist_name} ProgramArguments #{opt_bin}/vnstatd --nodaemon --config #{etc}/vnstat.conf KeepAlive RunAtLoad UserName #{`whoami`.chomp} GroupName staff WorkingDirectory #{var} ProcessType Background EOS end def caveats; <<-EOS.undent To monitor interfaces other than "en0" edit #{etc}/vnstat.conf EOS end end