2010-09-19 04:28:58 +00:00
|
|
|
require 'formula'
|
|
|
|
|
2011-03-10 05:11:03 +00:00
|
|
|
class Vnstat < Formula
|
2010-09-19 04:28:58 +00:00
|
|
|
homepage 'http://humdi.net/vnstat/'
|
2012-03-11 00:30:36 +00:00
|
|
|
url 'http://humdi.net/vnstat/vnstat-1.11.tar.gz'
|
2012-09-03 18:33:56 +00:00
|
|
|
sha1 '92494f38a752dcf60053af2a6d8977737da7e616'
|
2010-09-19 04:28:58 +00:00
|
|
|
|
|
|
|
def install
|
2012-03-11 00:30:36 +00:00
|
|
|
inreplace "src/cfg.c", '/etc/vnstat.conf', "#{etc}/vnstat.conf"
|
2010-09-19 04:28:58 +00:00
|
|
|
|
2012-03-11 00:30:36 +00:00
|
|
|
inreplace "man/vnstat.1" do |s|
|
|
|
|
s.gsub! '/etc/vnstat.conf', "#{etc}/vnstat.conf"
|
|
|
|
s.gsub! '/var/lib/vnstat', "#{var}/db/vnstat"
|
2010-09-19 04:28:58 +00:00
|
|
|
end
|
|
|
|
|
2012-03-11 00:30:36 +00:00
|
|
|
inreplace "man/vnstat.conf.5", '/etc/vnstat.conf', "#{etc}/vnstat.conf"
|
|
|
|
|
2010-09-19 04:28:58 +00:00
|
|
|
inreplace "cfg/vnstat.conf" do |c|
|
2012-03-11 00:30:36 +00:00
|
|
|
c.gsub! 'DatabaseDir "/var/lib/vnstat"', %Q{DatabaseDir "#{var}/db/vnstat"}
|
|
|
|
c.gsub! 'LogFile "/var/log/vnstat.log"', %Q{LogFile "#{var}/log/vnstat.log"}
|
|
|
|
c.gsub! 'PidFile "/var/run/vnstat.pid"', %Q{PidFile "#{var}/run/vnstat.pid"}
|
2010-09-19 04:28:58 +00:00
|
|
|
end
|
|
|
|
|
2012-03-11 00:30:36 +00:00
|
|
|
(var+'db/vnstat').mkpath
|
|
|
|
(var+'spool/vnstat').mkpath
|
2010-09-19 04:28:58 +00:00
|
|
|
|
2012-03-11 00:30:36 +00:00
|
|
|
system "make", "-C", "src", "CFLAGS=#{ENV.cflags}", "CC=#{ENV.cc}"
|
|
|
|
(prefix+'etc').install "cfg/vnstat.conf"
|
|
|
|
bin.install "src/vnstat", "src/vnstatd"
|
|
|
|
man1.install "man/vnstat.1", "man/vnstatd.1"
|
2010-09-19 04:28:58 +00:00
|
|
|
man5.install "man/vnstat.conf.5"
|
|
|
|
end
|
|
|
|
|
2012-03-11 00:30:36 +00:00
|
|
|
def caveats; <<-EOS.undent
|
2010-09-19 04:28:58 +00:00
|
|
|
To setup vnstat, run `vnstat -u -i en0' (replace en0 with the network
|
|
|
|
interface you wish to monitor).
|
|
|
|
|
|
|
|
You must then create a cron job to update the vnstat database.
|
|
|
|
|
2012-03-11 00:30:36 +00:00
|
|
|
Run `crontab -e' and add the following:
|
2010-09-19 04:28:58 +00:00
|
|
|
0-55/5 * * * * if [ -x #{bin}/vnstat ] && [ `ls #{var}/db/vnstat/ | wc -l` -ge 1 ]; then #{bin}/vnstat -u; fi
|
2012-03-11 00:30:36 +00:00
|
|
|
EOS
|
2010-09-19 04:28:58 +00:00
|
|
|
end
|
|
|
|
end
|