bumps vnstat to 1.6 and add uci files
[openwrt/svn-archive/archive.git] / net / vnstat / files / vnstat.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3
4 START=99
5 LIB_D=/var/lib/vnstat
6 WWW_D=/www/vnstat
7
8 system_config() {
9 local cfg="$1"
10
11 config_get hostname "$cfg" hostname
12 hostname="${hostname:-OpenWrt}"
13 }
14
15 do_download() {
16 include /lib/network
17 scan_interfaces
18
19 local cfg="$1"
20
21 config_get ifname "$cfg" "ifname"
22 [ -n "$ifname" ] || return 0
23 [ -e $LIB_D/$ifname ] && return 0
24
25 config_get_bool enabled "$cfg" "enabled" "1"
26 if [ "$enabled" -gt 0 ]; then
27 config_get remote_path "$cfg" "remote_path"
28 [ -n "$remote_path" ] || return 0
29 config_get remote_host "$cfg" "remote_host"
30 [ -n "$remote_host" ] || return 0
31
32 [ -x /usr/bin/wget ] && download_command="wget http://$remote_host/$remote_path/${hostname}_$ifname -O $LIB_D/$ifname"
33 [ -n "$download_command" ] || return 0
34
35 while [ ! -e $LIB_D/$ifname ]; do
36 $download_command 2>/dev/null
37 [ -e $LIB_D/$ifname ] && {
38 logger -s -t "vnstat" "Successfully downloaded ${ifname}'s vnStat database backup"
39 [ -x /bin/ln ] && ln -sf $LIB_D/$ifname $WWW_D/$ifname
40 return 0
41 }
42 sleep 30
43 done
44 fi
45 }
46
47 start() {
48 [ -d $LIB_D ] || mkdir -p $LIB_D
49 [ -d $WWW_D ] || mkdir -p $WWW_D
50
51 config_load system
52 config_foreach system_config system
53
54 config_load vnstat
55 config_foreach do_download interface
56 }