[packages] vnstat: rework package, get rid of download stuff (this is better done...
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 14 Jan 2011 19:53:27 +0000 (19:53 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 14 Jan 2011 19:53:27 +0000 (19:53 +0000)
SVN-Revision: 25000

net/vnstat/Makefile
net/vnstat/files/vnstat-uci.conf
net/vnstat/files/vnstat.init

index e0f364ca4977e207486e7e6c1cf45ee627abd6c6..29995fc6a76323ddfa8eea679399ddf761fc12c4 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=vnstat
 PKG_VERSION:=1.10
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://humdi.net/vnstat
@@ -98,16 +98,14 @@ endef
 
 define Package/vnstat/postinst
 #!/bin/sh
-BIN_REL=/usr/bin/vnstat
-BIN=$${IPKG_INSTROOT}$${BIN_REL}
-LIB_D_REL=/var/lib/vnstat
-LIB_D=$${IPKG_INSTROOT}$${LIB_D_REL}
-[ -d $$LIB_D ] || mkdir -p $$LIB_D
-IFACE_WAN=$$(uci get network.wan.ifname)
-if [ -n $$IFACE_WAN ]; then
-       [ -e $$LIB_D/$$IFACE_WAN ] || ( [ -x $$BIN ] && $$BIN -u -i $$IFACE_WAN )
+local wan="$$(uci -P/var/state get network.wan.ifname)"
+if [ -n "$$wan" ]; then
+       uci -q batch <<-EOF >/dev/null
+               add_list vnstat.@vnstat[-1].interface=$$wan
+               commit vnstat
+       EOF
 fi
-true
+exit 0
 endef
 
 $(eval $(call BuildPackage,vnstat))
index 44c02c2d00358d9ffa28c4855dda50105c9a1a6e..339fda48aef98ee1710affc1eb9a809e86c4a2ab 100644 (file)
@@ -1,4 +1,3 @@
-config interface               wan
-       option enabled          0
-       option remote_host      <webserver>
-       option remote_path      <directory>
+config vnstat
+       list interface          br-lan
+#      list interface          eth0.1
index 5632c6a777a5f8f6acbeb463bd193e0f06aa28be..2febdfae3a3736b8c1637b9d3c97040c2bde8865 100644 (file)
@@ -1,67 +1,46 @@
 #!/bin/sh /etc/rc.common
-# Copyright (C) 2008 OpenWrt.org
+# Copyright (C) 2008-2011 OpenWrt.org
 
 START=99
-LIB_D=/var/lib/vnstat
-WWW_D=/www/vnstat
-RUN_D=/var/run
-PID_F=$RUN_D/vnstat.pid
-VNSTATD_BIN=/usr/sbin/vnstatd
 
-system_config() {
-       local cfg="$1"
-
-       config_get hostname "$cfg" hostname
-       hostname="${hostname:-OpenWrt}"
+vnstat_option() {
+       sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
+               /etc/vnstat.conf
 }
 
-do_download() {
-       include /lib/network
-       scan_interfaces
-
-       local cfg="$1"
-
-       config_get ifname "$cfg" ifname
-       [ -n "$ifname" ] || return 0
-       [ -e $LIB_D/$ifname ] && return 0
+start() {
+       local lib="$(vnstat_option DatabaseDir)"
+       local pid="$(vnstat_option PidFile)"
 
-       config_get_bool enabled "$cfg" enabled '1'
-       [ "$enabled" -gt 0 ] && {
-               config_get remote_host "$cfg" remote_host
-               [ -n "$remote_host" ] || return 0
-               config_get remote_path "$cfg" remote_path
-               [ -n "$remote_path" ] || return 0
+       [ -n "$lib" ] || {
+               echo "Error: No DatabaseDir set in vnstat.conf" >&2
+               exit 1
+       }
 
-               while [ ! -e $LIB_D/$ifname ]; do
-                       wget http://$remote_host/$remote_path/${hostname}_$ifname -O $LIB_D/$ifname 2>/dev/null
-                       [ -e $LIB_D/$ifname ] && {
-                               logger -t "vnstat" "Successfully downloaded ${ifname}'s vnStat database backup"
-                               [ -L $WWW_D/$ifname ] || ln -s $LIB_D/$ifname $WWW_D/$ifname
-                               return 0
-                       }
-                       sleep 30
-               done
+       [ -n "$pid" ] || {
+               echo "Error: No PidFile set in vnstat.conf" >&2
+               exit 1
        }
-}
 
-start() {
-       [ -d $LIB_D ] || mkdir -p $LIB_D
-       [ -d $WWW_D ] || mkdir -p $WWW_D
+       mkdir -p "$lib"
 
-       config_load system
-       config_foreach system_config system
+       init_ifaces() {
+               local cfg="$1"
+               init_iface() { /usr/bin/vnstat -u -i "$1" >/dev/null; }
+               config_list_foreach "$cfg" interface init_iface
+               return 1
+       }
 
        config_load vnstat
-       config_foreach do_download interface
+       config_foreach init_ifaces vnstat
 
-       [ ! -f $PID_F ] && $VNSTATD_BIN -d
+       /usr/sbin/vnstatd -d
 }
 
 stop() {
-       [ -f $PID_F ] && kill $(cat $PID_F)
-}
-
-reload() {
-       [ -f $PID_F ] && kill -HUP $(cat $PID_F)
+       local pid="$(vnstat_option PidFile)"
+       [ -n "$pid" ] && {
+               service_kill vnstatd "$pid"
+               rm -f "$pid"
+       }
 }
-