Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>lilik-openwrt-22.03
@ -0,0 +1,109 @@ | |||
# | |||
# Copyright (C) 2006-2014 OpenWrt.org | |||
# | |||
# This is free software, licensed under the GNU General Public License v2. | |||
# See /LICENSE for more information. | |||
# | |||
include $(TOPDIR)/rules.mk | |||
PKG_NAME:=vnstat | |||
PKG_VERSION:=1.11 | |||
PKG_RELEASE:=4 | |||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz | |||
PKG_SOURCE_URL:=http://humdi.net/vnstat | |||
PKG_MD5SUM:=a5a113f9176cd61fb954f2ba297f5fdb | |||
PKG_MAINTAINER:=Jo-Philipp Wich <jow@openwrt.org> | |||
PKG_INSTALL:=1 | |||
PKG_BUILD_DEPENDS:=libgd | |||
PKG_BUILD_PARALLEL:=1 | |||
include $(INCLUDE_DIR)/package.mk | |||
define Package/vnstat/Default | |||
SECTION:=net | |||
CATEGORY:=Network | |||
URL:=http://humdi.net/vnstat/ | |||
endef | |||
define Package/vnstat | |||
$(call Package/vnstat/Default) | |||
TITLE:=Console-based network traffic monitor | |||
endef | |||
define Package/vnstat/description | |||
vnStat is a network traffic monitor for Linux that keeps a log of daily | |||
network traffic for the selected interface(s). vnStat isn't a packet | |||
sniffer. The traffic information is analyzed from the /proc -filesystem, | |||
so vnStat can be used without root permissions. | |||
endef | |||
define Package/vnstati | |||
$(call Package/vnstat/Default) | |||
DEPENDS+=vnstat +libgd | |||
TITLE:=PNG image output support for vnStat | |||
endef | |||
define Package/vnstati/description | |||
The purpose of vnstati is to provide image output support for statistics | |||
collected using vnstat(1). However, the image file format is limited to | |||
png. All basic outputs of vnStat are supported excluding live traffic | |||
features. The image can be outputted either to a file or to standard | |||
output. | |||
endef | |||
define Package/vnstat/conffiles | |||
/etc/vnstat.conf | |||
/etc/config/vnstat | |||
endef | |||
define Build/Compile/vnstat | |||
+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \ | |||
$(TARGET_CONFIGURE_OPTS) \ | |||
CFLAGS="$(TARGET_CFLAGS)" | |||
endef | |||
define Build/Compile/vnstati | |||
+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \ | |||
$(TARGET_CONFIGURE_OPTS) \ | |||
CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include" \ | |||
LDFLAGS="$(TARGET_LDFLAGS) -Wl,-rpath-link,$(STAGING_DIR)/usr/lib" \ | |||
all | |||
endef | |||
define Build/Compile | |||
$(call Build/Compile/vnstat) | |||
$(call Build/Compile/vnstati) | |||
endef | |||
define Package/vnstat/install | |||
$(INSTALL_DIR) $(1)/usr/bin | |||
$(CP) $(PKG_INSTALL_DIR)/usr/bin/vnstat $(1)/usr/bin/ | |||
$(INSTALL_DIR) $(1)/usr/sbin | |||
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/vnstatd $(1)/usr/sbin/ | |||
$(INSTALL_DIR) $(1)/etc | |||
$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/vnstat.conf $(1)/etc/ | |||
$(INSTALL_DIR) $(1)/etc/config | |||
$(INSTALL_CONF) ./files/vnstat.config $(1)/etc/config/vnstat | |||
$(INSTALL_DIR) $(1)/etc/init.d | |||
$(INSTALL_BIN) ./files/vnstat.init $(1)/etc/init.d/vnstat | |||
$(INSTALL_DIR) $(1)/etc/uci-defaults | |||
$(INSTALL_BIN) ./files/vnstat.defaults $(1)/etc/uci-defaults/vnstat | |||
endef | |||
define Package/vnstati/install | |||
$(INSTALL_DIR) $(1)/usr/bin | |||
$(CP) $(PKG_INSTALL_DIR)/usr/bin/vnstati $(1)/usr/bin/ | |||
endef | |||
define Package/vnstat/postinst | |||
#!/bin/sh | |||
[ -n "$${IPKG_INSTROOT}" ] || (. /etc/uci-defaults/vnstat) && rm -f /etc/uci-defaults/vnstat | |||
exit 0 | |||
endef | |||
$(eval $(call BuildPackage,vnstat)) | |||
$(eval $(call BuildPackage,vnstati)) |
@ -0,0 +1,5 @@ | |||
config vnstat | |||
list interface br-lan | |||
# list interface eth0.1 | |||
# option remote http://example.org/vnstat/ | |||
# option symlink /www/vnstat |
@ -0,0 +1,13 @@ | |||
#!/bin/sh | |||
wan="$(uci -P/var/state get network.wan.ifname)" | |||
if [ -n "$wan" ]; then | |||
uci -q batch <<-EOF >/dev/null | |||
del_list vnstat.@vnstat[-1].interface=$wan | |||
add_list vnstat.@vnstat[-1].interface=$wan | |||
commit vnstat | |||
EOF | |||
fi | |||
exit 0 |
@ -0,0 +1,82 @@ | |||
#!/bin/sh /etc/rc.common | |||
# Copyright (C) 2008-2011 OpenWrt.org | |||
START=99 | |||
vnstat_option() { | |||
sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \ | |||
/etc/vnstat.conf | |||
} | |||
start() { | |||
local lib="$(vnstat_option DatabaseDir)" | |||
local pid="$(vnstat_option PidFile)" | |||
[ -n "$lib" ] || { | |||
echo "Error: No DatabaseDir set in vnstat.conf" >&2 | |||
exit 1 | |||
} | |||
[ -n "$pid" ] || { | |||
echo "Error: No PidFile set in vnstat.conf" >&2 | |||
exit 1 | |||
} | |||
mkdir -p "$lib" | |||
init_ifaces() { | |||
local cfg="$1" | |||
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 | |||
} | |||
config_load vnstat | |||
config_foreach init_ifaces vnstat | |||
SERVICE_PID_FILE="${pid}" | |||
service_start /usr/sbin/vnstatd -d | |||
} | |||
stop() { | |||
local pid="$(vnstat_option PidFile)" | |||
[ -n "$pid" ] || { | |||
echo "Error: No PidFile set in vnstat.conf" >&2 | |||
exit 1 | |||
} | |||
SERVICE_PID_FILE="${pid}" | |||
service_stop /usr/sbin/vnstatd | |||
} |
@ -0,0 +1,19 @@ | |||
--- a/cfg/vnstat.conf | |||
+++ b/cfg/vnstat.conf | |||
@@ -72,13 +72,13 @@ TrafficlessDays 1 | |||
## | |||
# how often (in seconds) interface data is updated | |||
-UpdateInterval 30 | |||
+UpdateInterval 60 | |||
# how often (in seconds) interface status changes are checked | |||
-PollInterval 5 | |||
+PollInterval 30 | |||
# how often (in minutes) data is saved to file | |||
-SaveInterval 5 | |||
+SaveInterval 30 | |||
# how often (in minutes) data is saved when all interface are offline | |||
OfflineSaveInterval 30 |
@ -0,0 +1,35 @@ | |||
--- a/Makefile | |||
+++ b/Makefile | |||
@@ -54,11 +54,11 @@ install: | |||
# install everything else | |||
install -d -m 755 $(BIN) $(SBIN) $(MAN)/man1 $(MAN)/man5 $(DESTDIR)/var/lib/vnstat | |||
- install -s -m 755 src/vnstat $(BIN) | |||
- install -s -m 755 src/vnstatd $(SBIN) | |||
+ install -m 755 src/vnstat $(BIN) | |||
+ install -m 755 src/vnstatd $(SBIN) | |||
@if [ -f "src/vnstati" ]; \ | |||
- then echo install -s -m 755 src/vnstati $(BIN); \ | |||
- install -s -m 755 src/vnstati $(BIN); \ | |||
+ then echo install -m 755 src/vnstati $(BIN); \ | |||
+ install -m 755 src/vnstati $(BIN); \ | |||
fi | |||
# update man pages, gzip it if previous version was done so | |||
@@ -127,12 +127,12 @@ bsdinstall: | |||
# install binaries | |||
install -d -m 755 $(DESTDIR)/var/db/vnstat | |||
- install -s -m 755 src/vnstat $(BIN_BSD) | |||
- install -s -m 755 src/vnstatd $(SBIN_BSD) | |||
+ install -m 755 src/vnstat $(BIN_BSD) | |||
+ install -m 755 src/vnstatd $(SBIN_BSD) | |||
@if [ -f "src/vnstati" ]; \ | |||
- then echo install -s -m 755 src/vnstati $(BIN_BSD); \ | |||
- install -s -m 755 src/vnstati $(BIN_BSD); \ | |||
+ then echo install -m 755 src/vnstati $(BIN_BSD); \ | |||
+ install -m 755 src/vnstati $(BIN_BSD); \ | |||
fi | |||
# install default config if such doesn't exist |
@ -0,0 +1,15 @@ | |||
--- a/Makefile | |||
+++ b/Makefile | |||
@@ -22,12 +22,6 @@ clean: | |||
install: | |||
@echo "Installing vnStat..." | |||
-# check that system is really Linux | |||
- @if [ `uname` != "Linux" ]; \ | |||
- then echo "This isn't a Linux system. Maybe 'make bsdinstall' is what you need?"; \ | |||
- false; \ | |||
- fi | |||
- | |||
# check that there's something to install | |||
@if [ ! -f "src/vnstat" ] || [ ! -f "src/vnstatd" ]; \ | |||
then echo "Nothing to install, run make first."; \ |
@ -0,0 +1,21 @@ | |||
--- a/Makefile | |||
+++ b/Makefile | |||
@@ -43,7 +43,8 @@ install: | |||
# install default config if such doesn't exist | |||
@if [ ! -f "$(DESTDIR)/etc/vnstat.conf" ]; \ | |||
then echo "Installing config to $(DESTDIR)/etc/vnstat.conf"; \ | |||
- install -D -m 644 cfg/vnstat.conf $(DESTDIR)/etc/vnstat.conf; \ | |||
+ install -d -m 755 $(DESTDIR)/etc; \ | |||
+ install -m 644 cfg/vnstat.conf $(DESTDIR)/etc/vnstat.conf; \ | |||
fi | |||
# install everything else | |||
@@ -63,7 +64,7 @@ install: | |||
then echo install -m 644 man/vnstati.1 $(MAN)/man1; \ | |||
install -m 644 man/vnstati.1 $(MAN)/man1; \ | |||
fi | |||
- | |||
+ | |||
@if [ -f $(MAN)/man1/vnstat.1.gz ]; \ | |||
then gzip -f9 $(MAN)/man1/vnstat.1; \ | |||
gzip -f9 $(MAN)/man1/vnstatd.1; \ |