bumps vnstat to 1.6 and add uci files
authorJohn Crispin <john@openwrt.org>
Mon, 28 Jul 2008 19:34:31 +0000 (19:34 +0000)
committerJohn Crispin <john@openwrt.org>
Mon, 28 Jul 2008 19:34:31 +0000 (19:34 +0000)
SVN-Revision: 11976

net/vnstat/Makefile
net/vnstat/files/vnstat.conf [new file with mode: 0644]
net/vnstat/files/vnstat.init [new file with mode: 0644]

index 89b38075f56f865171fe54c1d506c65352ab2581..2b940b4121b5a5157f72bc9d8d4106c6ae04fa7f 100644 (file)
@@ -9,12 +9,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=vnstat
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=vnstat
-PKG_VERSION:=1.4
+PKG_VERSION:=1.6
 PKG_RELEASE:=1
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://humdi.net/vnstat
 PKG_RELEASE:=1
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://humdi.net/vnstat
-PKG_MD5SUM:=9184f79b5e60499bc059f670032291e5
+PKG_MD5SUM:=ccaffe8e70d47e0cf2f25e52daa25712
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
 
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
 
@@ -34,6 +34,10 @@ define Package/vnstat/description
        so vnStat can be used without root permissions.
 endef
 
        so vnStat can be used without root permissions.
 endef
 
+define Package/vnstat/conffiles
+/etc/config/vnstat
+endef
+
 define Build/Compile
        $(MAKE) -C $(PKG_BUILD_DIR) \
                $(TARGET_CONFIGURE_OPTS) \
 define Build/Compile
        $(MAKE) -C $(PKG_BUILD_DIR) \
                $(TARGET_CONFIGURE_OPTS) \
@@ -43,6 +47,26 @@ endef
 define Package/vnstat/install  
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/vnstat $(1)/usr/bin/
 define Package/vnstat/install  
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/vnstat $(1)/usr/bin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/vnstat.conf $(1)/etc/config/vnstat
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/vnstat.init $(1)/etc/init.d/vnstat
+endef
+
+define Package/vnstat/postinst
+#!/bin/sh
+BIN=$${IPKG_INSTROOT}/usr/bin/vnstat
+CRONTAB=$${IPKG_INSTROOT}/etc/crontabs/root
+LIB_D=$${IPKG_INSTROOT}/var/lib/vnstat
+mkdir -p $${IPKG_INSTROOT}/etc/crontabs/
+[ -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 )
+fi
+grep -q "$$BIN -u" $$CRONTAB 2>/dev/null
+[ $$? -ne 0 ] && echo "0-55/5 *   * * *   root    if [ -x $$BIN ] && [ \`ls $$LIB_D | wc -l\` -ge 1 ]; then $$BIN -u; fi" >> $$CRONTAB
+true
 endef
 
 $(eval $(call BuildPackage,vnstat))
 endef
 
 $(eval $(call BuildPackage,vnstat))
diff --git a/net/vnstat/files/vnstat.conf b/net/vnstat/files/vnstat.conf
new file mode 100644 (file)
index 0000000..44c02c2
--- /dev/null
@@ -0,0 +1,4 @@
+config interface               wan
+       option enabled          0
+       option remote_host      <webserver>
+       option remote_path      <directory>
diff --git a/net/vnstat/files/vnstat.init b/net/vnstat/files/vnstat.init
new file mode 100644 (file)
index 0000000..07db20c
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2008 OpenWrt.org
+
+START=99
+LIB_D=/var/lib/vnstat
+WWW_D=/www/vnstat
+
+system_config() {
+       local cfg="$1"
+
+       config_get hostname "$cfg" hostname
+       hostname="${hostname:-OpenWrt}"
+}
+
+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
+
+       config_get_bool enabled "$cfg" "enabled" "1"
+       if [ "$enabled" -gt 0 ]; then
+               config_get remote_path "$cfg" "remote_path"
+               [ -n "$remote_path" ] || return 0
+               config_get remote_host "$cfg" "remote_host"
+               [ -n "$remote_host" ] || return 0
+
+               [ -x /usr/bin/wget ] && download_command="wget http://$remote_host/$remote_path/${hostname}_$ifname -O $LIB_D/$ifname"
+               [ -n "$download_command" ] || return 0
+
+               while [ ! -e $LIB_D/$ifname ]; do
+                       $download_command 2>/dev/null
+                       [ -e $LIB_D/$ifname ] && {
+                               logger -s -t "vnstat" "Successfully downloaded ${ifname}'s vnStat database backup"
+                               [ -x /bin/ln ] && ln -sf $LIB_D/$ifname $WWW_D/$ifname
+                               return 0
+                       }
+                       sleep 30
+               done
+       fi
+}
+
+start() {
+       [ -d $LIB_D ] || mkdir -p $LIB_D
+       [ -d $WWW_D ] || mkdir -p $WWW_D
+
+       config_load system
+       config_foreach system_config system
+
+       config_load vnstat
+       config_foreach do_download interface
+}