Переглянути джерело

vnstat: import from packages, add myself as maintainer

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Jo-Philipp Wich 10 роки тому
джерело
коміт
177bfef1c7

+ 109
- 0
net/vnstat/Makefile Переглянути файл

@@ -0,0 +1,109 @@
1
+#
2
+# Copyright (C) 2006-2014 OpenWrt.org
3
+#
4
+# This is free software, licensed under the GNU General Public License v2.
5
+# See /LICENSE for more information.
6
+#
7
+
8
+include $(TOPDIR)/rules.mk
9
+
10
+PKG_NAME:=vnstat
11
+PKG_VERSION:=1.11
12
+PKG_RELEASE:=4
13
+
14
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
15
+PKG_SOURCE_URL:=http://humdi.net/vnstat
16
+PKG_MD5SUM:=a5a113f9176cd61fb954f2ba297f5fdb
17
+PKG_MAINTAINER:=Jo-Philipp Wich <jow@openwrt.org>
18
+
19
+PKG_INSTALL:=1
20
+
21
+PKG_BUILD_DEPENDS:=libgd
22
+PKG_BUILD_PARALLEL:=1
23
+
24
+include $(INCLUDE_DIR)/package.mk
25
+
26
+define Package/vnstat/Default
27
+  SECTION:=net
28
+  CATEGORY:=Network
29
+  URL:=http://humdi.net/vnstat/
30
+endef
31
+
32
+define Package/vnstat
33
+$(call Package/vnstat/Default)
34
+  TITLE:=Console-based network traffic monitor
35
+endef
36
+
37
+define Package/vnstat/description
38
+	vnStat is a network traffic monitor for Linux that keeps a log of daily
39
+	network traffic for the selected interface(s). vnStat isn't a packet
40
+	sniffer. The traffic information is analyzed from the /proc -filesystem,
41
+	so vnStat can be used without root permissions.
42
+endef
43
+
44
+define Package/vnstati
45
+$(call Package/vnstat/Default)
46
+  DEPENDS+=vnstat +libgd
47
+  TITLE:=PNG image output support for vnStat
48
+endef
49
+
50
+define Package/vnstati/description
51
+	The purpose of vnstati is to provide image output support for statistics
52
+	collected using vnstat(1). However, the image file format is limited to
53
+	png. All basic outputs of vnStat are supported excluding live traffic
54
+	features. The image can be outputted either to a file or to standard
55
+	output.
56
+endef
57
+
58
+define Package/vnstat/conffiles
59
+/etc/vnstat.conf
60
+/etc/config/vnstat
61
+endef
62
+
63
+define Build/Compile/vnstat
64
+	+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
65
+		$(TARGET_CONFIGURE_OPTS) \
66
+		CFLAGS="$(TARGET_CFLAGS)"
67
+endef
68
+
69
+define Build/Compile/vnstati
70
+	+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
71
+		$(TARGET_CONFIGURE_OPTS) \
72
+		CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include" \
73
+		LDFLAGS="$(TARGET_LDFLAGS) -Wl,-rpath-link,$(STAGING_DIR)/usr/lib" \
74
+		all
75
+endef
76
+
77
+define Build/Compile
78
+$(call Build/Compile/vnstat)
79
+$(call Build/Compile/vnstati)
80
+endef
81
+
82
+define Package/vnstat/install
83
+	$(INSTALL_DIR) $(1)/usr/bin
84
+	$(CP) $(PKG_INSTALL_DIR)/usr/bin/vnstat $(1)/usr/bin/
85
+	$(INSTALL_DIR) $(1)/usr/sbin
86
+	$(CP) $(PKG_INSTALL_DIR)/usr/sbin/vnstatd $(1)/usr/sbin/
87
+	$(INSTALL_DIR) $(1)/etc
88
+	$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/vnstat.conf $(1)/etc/
89
+	$(INSTALL_DIR) $(1)/etc/config
90
+	$(INSTALL_CONF) ./files/vnstat.config $(1)/etc/config/vnstat
91
+	$(INSTALL_DIR) $(1)/etc/init.d
92
+	$(INSTALL_BIN) ./files/vnstat.init $(1)/etc/init.d/vnstat
93
+	$(INSTALL_DIR) $(1)/etc/uci-defaults
94
+	$(INSTALL_BIN) ./files/vnstat.defaults $(1)/etc/uci-defaults/vnstat
95
+endef
96
+
97
+define Package/vnstati/install
98
+	$(INSTALL_DIR) $(1)/usr/bin
99
+	$(CP) $(PKG_INSTALL_DIR)/usr/bin/vnstati $(1)/usr/bin/
100
+endef
101
+
102
+define Package/vnstat/postinst
103
+#!/bin/sh
104
+[ -n "$${IPKG_INSTROOT}" ] || (. /etc/uci-defaults/vnstat) && rm -f /etc/uci-defaults/vnstat
105
+exit 0
106
+endef
107
+
108
+$(eval $(call BuildPackage,vnstat))
109
+$(eval $(call BuildPackage,vnstati))

+ 5
- 0
net/vnstat/files/vnstat.config Переглянути файл

@@ -0,0 +1,5 @@
1
+config vnstat
2
+	list interface		br-lan
3
+#	list interface		eth0.1
4
+#	option remote		http://example.org/vnstat/
5
+#	option symlink		/www/vnstat

+ 13
- 0
net/vnstat/files/vnstat.defaults Переглянути файл

@@ -0,0 +1,13 @@
1
+#!/bin/sh
2
+
3
+wan="$(uci -P/var/state get network.wan.ifname)"
4
+
5
+if [ -n "$wan" ]; then
6
+	uci -q batch <<-EOF >/dev/null
7
+		del_list vnstat.@vnstat[-1].interface=$wan
8
+		add_list vnstat.@vnstat[-1].interface=$wan
9
+		commit vnstat
10
+	EOF
11
+fi
12
+
13
+exit 0

+ 82
- 0
net/vnstat/files/vnstat.init Переглянути файл

@@ -0,0 +1,82 @@
1
+#!/bin/sh /etc/rc.common
2
+# Copyright (C) 2008-2011 OpenWrt.org
3
+
4
+START=99
5
+
6
+vnstat_option() {
7
+	sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
8
+		/etc/vnstat.conf
9
+}
10
+
11
+start() {
12
+	local lib="$(vnstat_option DatabaseDir)"
13
+	local pid="$(vnstat_option PidFile)"
14
+
15
+	[ -n "$lib" ] || {
16
+		echo "Error: No DatabaseDir set in vnstat.conf" >&2
17
+		exit 1
18
+	}
19
+
20
+	[ -n "$pid" ] || {
21
+		echo "Error: No PidFile set in vnstat.conf" >&2
22
+		exit 1
23
+	}
24
+
25
+	mkdir -p "$lib"
26
+
27
+	init_ifaces() {
28
+		local cfg="$1"
29
+		local url lnk
30
+
31
+		init_iface() {
32
+			local ifn="$1"
33
+
34
+			[ -n "$url" ] && {
35
+				local try=0
36
+				local max=3
37
+				local hostname="$(cat /proc/sys/kernel/hostname)"
38
+
39
+				while [ $((++try)) -le $max ]; do
40
+					if wget -q -O "$lib/$ifn" "$url/${hostname}_$ifn" 2>/dev/null && [ -e "$lib/$ifn" ]; then
41
+						logger -t "vnstat" "Downloaded backup for database $ifn"
42
+						break
43
+					else
44
+						logger -t "vnstat" "Download try $try/$max for database $ifn failed"
45
+						sleep 30
46
+					fi
47
+				done
48
+			}
49
+
50
+			/usr/bin/vnstat -u -i "$ifn" >/dev/null
51
+
52
+			[ -n "$lnk" ] && {
53
+				mkdir -p "$lnk"
54
+				[ -L "$lnk/$ifn" ] || ln -s "$lib/$ifn" "$lnk/$ifn"
55
+			}
56
+		}
57
+
58
+		config_get url "$cfg" remote
59
+		config_get lnk "$cfg" symlink
60
+		config_list_foreach "$cfg" interface init_iface
61
+
62
+		return 1
63
+	}
64
+
65
+	config_load vnstat
66
+	config_foreach init_ifaces vnstat
67
+
68
+	SERVICE_PID_FILE="${pid}"
69
+	service_start /usr/sbin/vnstatd -d
70
+}
71
+
72
+stop() {
73
+	local pid="$(vnstat_option PidFile)"
74
+
75
+	[ -n "$pid" ] || {
76
+		echo "Error: No PidFile set in vnstat.conf" >&2
77
+		exit 1
78
+	}
79
+
80
+	SERVICE_PID_FILE="${pid}"
81
+	service_stop /usr/sbin/vnstatd
82
+}

+ 19
- 0
net/vnstat/patches/001-conf.patch Переглянути файл

@@ -0,0 +1,19 @@
1
+--- a/cfg/vnstat.conf
2
++++ b/cfg/vnstat.conf
3
+@@ -72,13 +72,13 @@ TrafficlessDays 1
4
+ ##
5
+ 
6
+ # how often (in seconds) interface data is updated
7
+-UpdateInterval 30
8
++UpdateInterval 60
9
+ 
10
+ # how often (in seconds) interface status changes are checked
11
+-PollInterval 5
12
++PollInterval 30
13
+ 
14
+ # how often (in minutes) data is saved to file
15
+-SaveInterval 5
16
++SaveInterval 30
17
+ 
18
+ # how often (in minutes) data is saved when all interface are offline
19
+ OfflineSaveInterval 30

+ 35
- 0
net/vnstat/patches/002-no_install_strip.patch Переглянути файл

@@ -0,0 +1,35 @@
1
+--- a/Makefile
2
++++ b/Makefile
3
+@@ -54,11 +54,11 @@ install:
4
+ 
5
+ # install everything else
6
+ 	install -d -m 755 $(BIN) $(SBIN) $(MAN)/man1 $(MAN)/man5 $(DESTDIR)/var/lib/vnstat
7
+-	install -s -m 755 src/vnstat $(BIN)
8
+-	install -s -m 755 src/vnstatd $(SBIN)
9
++	install -m 755 src/vnstat $(BIN)
10
++	install -m 755 src/vnstatd $(SBIN)
11
+ 	@if [ -f "src/vnstati" ]; \
12
+-	then echo install -s -m 755 src/vnstati $(BIN); \
13
+-	install -s -m 755 src/vnstati $(BIN); \
14
++	then echo install -m 755 src/vnstati $(BIN); \
15
++	install -m 755 src/vnstati $(BIN); \
16
+ 	fi
17
+ 
18
+ # update man pages, gzip it if previous version was done so	
19
+@@ -127,12 +127,12 @@ bsdinstall:
20
+ 
21
+ # install binaries
22
+ 	install -d -m 755 $(DESTDIR)/var/db/vnstat
23
+-	install -s -m 755 src/vnstat $(BIN_BSD)
24
+-	install -s -m 755 src/vnstatd $(SBIN_BSD)
25
++	install -m 755 src/vnstat $(BIN_BSD)
26
++	install -m 755 src/vnstatd $(SBIN_BSD)
27
+ 
28
+ 	@if [ -f "src/vnstati" ]; \
29
+-	then echo install -s -m 755 src/vnstati $(BIN_BSD); \
30
+-	install -s -m 755 src/vnstati $(BIN_BSD); \
31
++	then echo install -m 755 src/vnstati $(BIN_BSD); \
32
++	install -m 755 src/vnstati $(BIN_BSD); \
33
+ 	fi
34
+ 
35
+ # install default config if such doesn't exist

+ 15
- 0
net/vnstat/patches/003-no_install_uname.patch Переглянути файл

@@ -0,0 +1,15 @@
1
+--- a/Makefile
2
++++ b/Makefile
3
+@@ -22,12 +22,6 @@ clean:
4
+ install:
5
+ 	@echo "Installing vnStat..."
6
+ 
7
+-# check that system is really Linux
8
+-	@if [ `uname` != "Linux" ]; \
9
+-	then echo "This isn't a Linux system. Maybe 'make bsdinstall' is what you need?"; \
10
+-	false; \
11
+-	fi
12
+-
13
+ # check that there's something to install
14
+ 	@if [ ! -f "src/vnstat" ] || [ ! -f "src/vnstatd" ]; \
15
+ 	then echo "Nothing to install, run make first."; \

+ 21
- 0
net/vnstat/patches/004-install_bsd_fix.patch Переглянути файл

@@ -0,0 +1,21 @@
1
+--- a/Makefile
2
++++ b/Makefile
3
+@@ -43,7 +43,8 @@ install:
4
+ # install default config if such doesn't exist
5
+ 	@if [ ! -f "$(DESTDIR)/etc/vnstat.conf" ]; \
6
+ 	then echo "Installing config to $(DESTDIR)/etc/vnstat.conf"; \
7
+-	install -D -m 644 cfg/vnstat.conf $(DESTDIR)/etc/vnstat.conf; \
8
++	install -d -m 755 $(DESTDIR)/etc; \
9
++	install -m 644 cfg/vnstat.conf $(DESTDIR)/etc/vnstat.conf; \
10
+ 	fi
11
+ 
12
+ # install everything else
13
+@@ -63,7 +64,7 @@ install:
14
+ 	then echo install -m 644 man/vnstati.1 $(MAN)/man1; \
15
+ 	install -m 644 man/vnstati.1 $(MAN)/man1; \
16
+ 	fi
17
+-	
18
++
19
+ 	@if [ -f $(MAN)/man1/vnstat.1.gz ]; \
20
+ 	then gzip -f9 $(MAN)/man1/vnstat.1; \
21
+ 	gzip -f9 $(MAN)/man1/vnstatd.1; \