[packages] vnstat: readd download and symlink functionality
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 15 Jan 2011 02:00:37 +0000 (02:00 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 15 Jan 2011 02:00:37 +0000 (02:00 +0000)
SVN-Revision: 25001

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

index 29995fc..86d6fc5 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=vnstat
 PKG_VERSION:=1.10
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://humdi.net/vnstat
index 339fda4..9da71ed 100644 (file)
@@ -1,3 +1,5 @@
 config vnstat
        list interface          br-lan
 #      list interface          eth0.1
+#      option remote           http://example.org/vnstat/
+#      option symlink          /www/vnstat
index 2febdfa..fab1f34 100644 (file)
@@ -26,8 +26,39 @@ start() {
 
        init_ifaces() {
                local cfg="$1"
-               init_iface() { /usr/bin/vnstat -u -i "$1" >/dev/null; }
+               local url lnk
+
+               init_iface() {
+                       local ifn="$1"
+
+                       [ -n "$url" ] && {
+                               local try=0
+                               local max=3
+                               local hostname="$(cat /proc/sys/kernel/hostname)"
+
+                               while [ $((++try)) -le $max ]; do
+                                       if wget -q -O "$lib/$ifn" "$url/${hostname}_$ifn" 2>/dev/null && [ -e "$lib/$ifn" ]; then
+                                               logger -t "vnstat" "Downloaded backup for database $ifn"
+                                               break
+                                       else
+                                               logger -t "vnstat" "Download try $try/$max for database $ifn failed"
+                                               sleep 30
+                                       fi
+                               done
+                       }
+
+                       /usr/bin/vnstat -u -i "$ifn" >/dev/null
+
+                       [ -n "$lnk" ] && {
+                               mkdir -p "$lnk"
+                               [ -L "$lnk/$ifn" ] || ln -s "$lib/$ifn" "$lnk/$ifn"
+                       }
+               }
+
+               config_get url "$cfg" remote
+               config_get lnk "$cfg" symlink
                config_list_foreach "$cfg" interface init_iface
+
                return 1
        }