%bcond_with systemd

Name:           ipset
Summary:        Manage Linux IP sets
Version:        7.6
Release:        1%{?_dist_release}%{?with_systemd:.systemd}
Group:          Applications/System
Vendor:         Project Vine
Distribution:   Vine Linux

License:        GPLv2
URL:            http://ipset.netfilter.org/
Source0:        http://ipset.netfilter.org/%{name}-%{version}.tar.bz2
Source1:        %{name}.service
Source2:        %{name}.start-stop
Source3:        %{name}.init

BuildRequires:  libmnl-devel

# An explicit requirement is needed here, to avoid cases where a user would
# explicitly update only one of the two (e.g 'yum update ipset')
Requires:         %{name}-libs%{?_isa} = %{version}-%{release}
%if !%{with systemd}
Requires(post): chkconfig
Requires(preun): chkconfig /sbin/service
%endif

%description
IP sets are a framework inside the Linux 2.4.x and 2.6.x kernel, which can be
administered by the ipset utility. Depending on the type, currently an IP set
may store IP addresses, (TCP/UDP) port numbers or IP addresses with MAC
addresses in a way, which ensures lightning speed when matching an entry
against a set.

If you want to:
 - store multiple IP addresses or port numbers and match against the collection
   by iptables at one swoop;
 - dynamically update iptables rules against IP addresses or ports without
   performance penalty;
 - express complex IP address and ports based rulesets with one single iptables
   rule and benefit from the speed of IP sets
then ipset may be the proper tool for you.


%package libs
Summary:       Shared library providing the IP sets functionality
Group:         System Environment/Libraries

%description libs
This package contains the libraries which provide the IP sets funcionality.


%package devel
Summary:       Development files for %{name}
Group:         Development/Libraries
Requires:      %{name}-libs%{?_isa} == %{version}-%{release}
Requires:      kernel-devel

%description devel
This package contains the files required to develop software using the %{name}
libraries.


%if %{with systemd}
%package service
Summary:          %{name} service for %{name}s
Requires:         %{name} = %{version}-%{release}
BuildRequires:    systemd
#Requires:         iptables-services
Requires(post):   systemd
Requires(preun):  systemd
Requires(postun): systemd
BuildArch:        noarch

%description service
This package provides the service %{name} that is split
out of the base package since it is not active by default.


%endif

%prep
%setup -q


%build
%configure --enable-static=no --with-kmod=no

# Just to make absolutely sure we are not building the bundled kernel module
# I have to do it after the configure run unfortunately
rm -fr kernel

# Prevent libtool from defining rpath
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool

make %{?_smp_mflags}


%install
make install DESTDIR=%{buildroot}
find %{buildroot} -name '*.la' -exec rm -f '{}' \;

%if %{with systemd}
# install systemd unit file
install -d -m 755 %{buildroot}/%{_unitdir}
install -c -m 644 %{SOURCE1} %{buildroot}/%{_unitdir}

# install supporting script
install -d -m 755 %{buildroot}%{_libexecdir}/%{name}
install -c -m 755 %{SOURCE2} %{buildroot}%{_libexecdir}/%{name}
%else
mkdir -p %{buildroot}%{_initdir}
install -m755 %{SOURCE3} %{buildroot}%{_initdir}/%{name}
%endif

# Create directory for configuration
mkdir -p %{buildroot}%{_sysconfdir}/%{name}


%if !%{with systemd}
%post
/sbin/chkconfig --add ipset
%endif

%preun
%if !%{with systemd}
if [ "$1" = 0 ]; then
    /sbin/chkconfig --del ipset
fi
%endif
if [[ $1 -eq 0 && -n $(lsmod | grep "^xt_set ") ]]; then
    rmmod xt_set 2>/dev/null
    [[ $? -ne 0 ]] && echo Current iptables configuration requires ipsets && exit 1
fi


%post libs -p /sbin/ldconfig

%postun libs -p /sbin/ldconfig


%if %{with systemd}
%post service
%systemd_post %{name}.service

%preun service
if [[ $1 -eq 0 && -n $(lsmod | grep "^xt_set ") ]]; then
    rmmod xt_set 2>/dev/null
    [[ $? -ne 0 ]] && echo Current iptables configuration requires ipsets && exit 1
fi
%systemd_preun %{name}.service

%postun service
%systemd_postun_with_restart %{name}.service
%endif

%files
%license COPYING
%doc ChangeLog
%doc %{_mandir}/man8/%{name}.8.gz
%{_sbindir}/%{name}
%if !%{with systemd}
%{_initdir}/%{name}
%dir %{_sysconfdir}/%{name}
%endif

%files libs
%license COPYING
%{_libdir}/lib%{name}.so.*

%files devel
%{_includedir}/lib%{name}
%{_libdir}/lib%{name}.so
%{_libdir}/pkgconfig/lib%{name}.pc
%{_mandir}/man3/libipset.3.*

%if %{with systemd}
%files service
%{_unitdir}/%{name}.service
%dir %{_libexecdir}/%{name}
%attr(0755,root,root) %{_libexecdir}/%{name}/%{name}.start-stop
%dir %{_sysconfdir}/%{name}
%endif


%changelog
* Sat Apr 18 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 7.6-1
- new upstream release.

* Mon May  8 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 6.32-1
- new upstream release.

* Sat Nov  1 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 6.23-1
- built for Vine Linux.
- new upstream release.

* Thu Sep 18 2014 Mathieu Bridon <bochecha@fedoraproject.org> - 6.22-1
- New upstream release.

* Sat Aug 16 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 6.21.1-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* Sat Jun 07 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 6.21.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* Tue Mar 11 2014 Mathieu Bridon <bochecha@fedoraproject.org> - 6.21.1-2
- Remove runtime requirement on the kernel.
  https://lists.fedoraproject.org/pipermail/devel/2014-March/196565.html

* Tue Oct 29 2013 Mathieu Bridon <bochecha@fedoraproject.org> - 6.20.1-1
- New upstream release.

* Tue Aug 27 2013 Quentin Armitage <quentin@armitage.org.uk> 6.19-2
- Add service pkg - adds save and reload functionality on shutdown/startup
- Add requires dependency of ipset on matching ipset-libs

* Thu Aug 15 2013 Mathieu Bridon <bochecha@fedoraproject.org> - 6.19-1
- New upstream release.

* Sat Aug 03 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 6.16.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild

* Thu Feb 14 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 6.16.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild

* Wed Sep 26 2012 Mathieu Bridon <bochecha@fedoraproject.org> - 6.16.1-1
- New upstream release.
- Fix a requirement.

* Wed Sep 26 2012 Mathieu Bridon <bochecha@fedoraproject.org> - 6.14-1
- New upstream release.
- Fix scriptlets, ldconfig is needed for the libs subpackage, not the main one.

* Mon Jul 30 2012 Mathieu Bridon <bochecha@fedoraproject.org> - 6.13-1
- New upstream release.
- Split out the library in its own subpackage.

* Thu Jul 19 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 6.11-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

* Mon Feb 06 2012 Mathieu Bridon <bochecha@fedoraproject.org> - 6.11-1
- New upstream release.
- Removed our patch, it has been integrated upstream. As such, we also don't
  need to re-run autoreconf any more.

* Fri Jan 13 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 6.9.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild

* Fri Sep 16 2011 Mathieu Bridon <bochecha@fedoraproject.org> - 6.9.1-2
- Some fixes based on Pierre-Yves' review feedback.

* Wed Sep 14 2011 Mathieu Bridon <bochecha@fedoraproject.org> - 6.9.1-1
- Initial packaging.
