Name: bwctl
Summary: bwctl - network throughput tester
Version: @VERSION@
Release: @PATCH_LEVEL@%{?dist}
License: Apache License v2.0
Group: *Development/Libraries*
URL: http://e2epi.internet2.edu/bwctl/
Source: %{name}-%{version}.tar.gz
Packager: Aaron Brown <aaron@internet2.edu>
BuildRequires:  libtool, I2util
Requires: bwctl-client, bwctl-server, iperf3 >= 3.0.11
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-buildroot

%description
BWCTL is a command line client application and a scheduling and policy daemon
that wraps Iperf, Thrulay or nuttcp.

%files


%package client
Summary: bwctl client
Group: Applications/Network
Requires:   iperf, iperf3 >= 3.0.11
%description client
bwctl command line tool for scheduling bandwidth measurements with a bwctl
server.

%package server
Summary: bwctl server
Group: Applications/Network
Requires: I2util, chkconfig, initscripts, shadow-utils, coreutils
Requires:   iperf, iperf3 >= 3.0.11
%description server
bwctl server

%package devel
Group: Development/Libraries
Summary: bwctl library headers.
%description devel
This package includes header files, and static link libraries for building
applications that use the bwctl library.


# Thrulay and I2Util get installed, but really, shouldn't be instaled.
#%define _unpackaged_files_terminate_build      0

%prep
%setup -q

%build
# The CFLAGS defined here enable some hardening options for gcc
# -fstack-protector-all -Wstack-protector:
#   Put numbers at the beginning of each stack frame and check that they
#   are the same.  If a stack buffer if overflowed, it writes over the
#   canary number and then on return when that number is checked, it won't
#   be the same and the program will exit with a "Stack smashing detected"
#   error instead of being exploited.
# -D_FORTIFY_SOURCE=2
#   Does some checking for potentially exploitable code patterns in the
#   source such overflowing a statically defined buffer.

CFLAGS="-fstack-protector-all -Wstack-protector -D_FORTIFY_SOURCE=2" 
%configure --prefix=%{_prefix} --with-thrulay=no --with-I2util=no --with-iperf3 --enable-nuttcp --enable-debug

make

%install
%makeinstall
%{__install} -D -p -m 0755 conf/bwctld.init %{buildroot}%{_sysconfdir}/rc.d/init.d/bwctld
%{__install} -D -p -m 0755 conf/bwctld.limits %{buildroot}%{_sysconfdir}/bwctld/bwctld.limits
%{__install} -D -p -m 0755 conf/bwctld.limits %{buildroot}%{_sysconfdir}/bwctld/bwctld.limits.default
%{__install} -D -p -m 0755 conf/bwctld.conf %{buildroot}%{_sysconfdir}/bwctld/bwctld.conf
%{__install} -D -p -m 0755 conf/bwctld.conf %{buildroot}%{_sysconfdir}/bwctld/bwctld.conf.default

%clean
rm -rf $RPM_BUILD_ROOT 

%post server
if [ "$1" = "1" ]; then
    # If this is a first time install, add the users and enable it by default
	/sbin/chkconfig --add bwctld
	/usr/sbin/useradd -r -s /bin/nologin -d /tmp bwctl || :
else
    /sbin/service bwctld cond-restart
fi

%preun server
if [ "$1" = "0" ]; then
    # If this is an actual uninstall, stop the service and remove its links
    /sbin/chkconfig --del bwctld
    /sbin/service bwctld stop
fi

%postun server
if [ "$1" = "0" ]; then
    # If this is an actual uninstall, delete the user after the software has been removed
	/usr/sbin/userdel bwctl || :
fi

%files client
%defattr(-,root,root,0755)
%doc README
%{_bindir}/bwctl
%{_bindir}/bwping
%{_bindir}/bwtraceroute
%{_mandir}/man1/bwctl.1.gz
%{_mandir}/man1/bwping.1.gz
%{_mandir}/man1/bwtraceroute.1.gz

%files server
%defattr(-,root,root,0755)
%doc README contrib/sample_hook.pl
%{_bindir}/bwctld
%{_mandir}/man5/*
%{_mandir}/man8/*
%{_sysconfdir}/rc.d/init.d/bwctld
%config(noreplace) %{_sysconfdir}/bwctld/*

%files devel
%defattr(-,root,root,0755)
%{_libdir}/libbwlib.a
%{_includedir}/bwctl/*

%changelog
* Fri Aug 20 2010 Tom Throckmorton <throck@mcnc.org> - 1.3-4
- minor spec changes to enable rebuilds via mock
- disable I2util, thrulay at buildtime; enable nuttcp

* Fri Jan 11 2008 aaron@internet2.edu 1.0-1
- Initial RPM
