File vnstat.spec of Package vnstat

#
# spec file for package vnstat
#
# Copyright (c) 2005-2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

Name:           vnstat
Version:        1.11
Release:        1
License:        GPL-2.0+
Summary:        Network Traffic Monitor
Url:            http://humdi.net/vnstat/
Group:          Productivity/Networking/Diagnostic
# http://humdi.net/vnstat/vnstat-%%{version}.tar.gz
Source0:        vnstat-%{version}.tar.gz
Source1:        vnstat.init
Source2:        vnstat-cgi.conf
Source3:        vnstat-if.sh
Source4:        vnstat-create-db.sh
Patch0:         vnstat-cron.patch
Patch4:         vnstat-help_script.patch
Requires:       cron
Requires:       /bin/ls
Requires:       /bin/su
Requires:       /usr/bin/killall
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if %{?suse_version:1}0
PreReq:         %fillup_prereq
PreReq:         %insserv_prereq
PreReq:         /usr/sbin/useradd
%endif
BuildRequires:  apache2
BuildRequires:  gcc
BuildRequires:  gd-devel
BuildRequires:  glibc-devel
BuildRequires:  make

%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.

%package cgi
Summary:        Graph Visualization CGI Script for %{name}
Group:          Productivity/Networking/Diagnostic
Requires:       %{name} = %{version}
Requires:       apache2

%description cgi
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.

This package contains a CGI script that visualizes graphs of the
collected traffic statistics.

%prep
%setup -q
%patch0
%patch4
# remove -s from install calls to avoid stripping:
%__sed -i 's/\(\binstall\b.*\)-s/\1/g' Makefile

%build
%__make %{?jobs:-j%{jobs}} CFLAGS="%{optflags}"
%__make %{?jobs:-j%{jobs}} CFLAGS="%{optflags}" -C src vnstati

%install
%__install -d "%{buildroot}%{_sysconfdir}"
%makeinstall
%__install -D -m0644 examples/vnstat.cron "%{buildroot}%{_sysconfdir}/cron.d/vnstat"

%__install -D -m0755 "%{SOURCE1}" "%{buildroot}%{_initddir}/vnstatd"
%__install -d "%{buildroot}%{_prefix}/sbin"
%__ln_s ../../etc/init.d/vnstatd "%{buildroot}%{_sbindir}/rcvnstatd"

%__install -D -m0755 "%{SOURCE3}" "%{buildroot}%{_sysconfdir}/sysconfig/network/scripts/vnstat"
for x in up down; do
    %__install -d "%{buildroot}%{_sysconfdir}/sysconfig/network/if-${x}.d"
    %__ln_s ../scripts/vnstat "%{buildroot}%{_sysconfdir}/sysconfig/network/if-${x}.d/20-vnstat"
done

%__install -D -m0755 examples/vnstat.cgi "%{buildroot}/srv/vnstat/vnstat.cgi"
%__install -D -m0644 "%{SOURCE2}" "%{buildroot}%{_sysconfdir}/apache2/conf.d/vnstat.conf"

%__install -D -m0755 "%{SOURCE4}" "%{buildroot}%{_bindir}/vnstat-create-db"

%pre
if ! /usr/bin/getent group vnstat &>/dev/null; then
  echo "Creating vnstat group"
  /usr/sbin/groupadd -r vnstat
fi
if ! /usr/bin/getent passwd vnstat &>/dev/null; then
  echo "Creating vnstat user"
  /usr/sbin/useradd -r -d /var/lib/vnstat -s /bin/sh -c "vnstat daemon" -g vnstat vnstat
  if test -d /var/lib/vnstat; then
    find /var/lib/vnstat -type f -print0 | xargs -r0 chown -v vnstat
  fi
fi
exit 0

%post
%{fillup_and_insserv -f vnstatd}

%preun
%stop_on_removal vnstatd

%postun
%restart_on_update vnstatd
%insserv_cleanup

%clean
%__rm -rf %{buildroot}

%files
%defattr(-,root,root)
%doc UPGRADE UNINSTALL README FAQ CHANGES
%{_bindir}/vnstat-create-db
%{_bindir}/vnstat
%{_bindir}/vnstati
%{_sbindir}/vnstatd
%config(noreplace) %{_sysconfdir}/vnstat.conf
%config(noreplace) %{_sysconfdir}/cron.d/vnstat
%{_sysconfdir}/sysconfig/network/scripts/vnstat
%{_sysconfdir}/sysconfig/network/if-up.d/20-vnstat
%{_sysconfdir}/sysconfig/network/if-down.d/20-vnstat
%{_sysconfdir}/init.d/vnstatd
%{_sbindir}/rcvnstatd
%attr(0755,vnstat,root) %{_localstatedir}/lib/vnstat
%doc %{_mandir}/man1/vnstat.1*
%doc %{_mandir}/man1/vnstati.1*
%doc %{_mandir}/man1/vnstatd.1*
%doc %{_mandir}/man5/vnstat.conf.5*

%files cgi
%defattr(-,root,root)
%config(noreplace) %{_sysconfdir}/apache2/conf.d/vnstat.conf
/srv/vnstat

%changelog
openSUSE Build Service is sponsored by