#
# spec file for package rpcbind
#
# Copyright (c) 2012 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:           rpcbind
Version:        0.2.0_git201103171419
Release:        8.1
Summary:        Transport independent RPC portmapper
License:        BSD-3-Clause
Group:          Productivity/Networking/System
Url:            http://git.infradead.org/users/steved/rpcbind.git
Source:         %{name}-%{version}.tar.bz2
Source1:        rpcbind.init
Source2:        sysconfig.rpcbind
Source3:        rpcbind.xml
Source4:        pmap_set.c
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
#BuildRequires:  libtirpc-devel
#BuildRequires:  libtool
#BuildRequires:  pkgconfig
#BuildRequires:  tcpd-devel
Provides:       portmap = 6.0+git20070716
Obsoletes:      portmap <= 6.0+git20070716
# hopefully soon we will have this autogenerated from rpm
Provides:       sysvinit(portmap)
Provides:       sysvinit(rpcbind)
#PreReq:         %insserv_prereq %fillup_prereq /sbin/checkproc sysvinit(network)
Patch0:         0001-systemd-add-support-for-system-bus-activation.patch
Patch1:         socket-activation-don-t-unlink-socket-we-didn-t-create
Patch2:         socket-activation-fix-rpcbind-service-to-use-separate-sockets
Patch3:         rpcbind-journal.patch
Patch4:         move-lock-file-to-run-fs.patch
%define statefile /var/lib/portmap.state
#%if 0%{?suse_version} > 1140
#BuildRequires:  systemd-devel
#%{?systemd_requires}
%define has_systemd 0
#%endif

%description
Rpcbind is a replacement for portmap. Whereas portmap supports only UDP
and TCP transports over INET (IPv4), rpcbind can be configured to work
on various transports supported by the TI-RPC. This includes TCP and
UDP over IPv6. Moreover, rpcbind provides additional functions in
regards to portmap.



Authors:
--------
    Gilles Quillard <gilles.quillard@bull.net>
    Vincent ROQUETA <vincent.roqueta@ext.bull.net>

%prep
%setup -q
cp %{SOURCE4} .
#%patch0 -p1
#%patch1 -p1
#%patch2 -p1
#%patch3
#%patch4 -p1

%build
autoreconf -fiv
export  CFLAGS="$RPM_OPT_FLAGS -fpie"
export LDFLAGS="-pie -Wl,-z,relro,-z,now"
%configure \
	    --bindir=/sbin \
	    --enable-libwrap \
	    --enable-warmstarts \
	    --with-statedir=%{_localstatedir}/lib/rpcbind

%{__make} %{?jobs:-j%jobs}
%{__cc} -fwhole-program -Wl,-z,relro,-z,now %{optflags} pmap_set.c -o pmap_set

%install
make install DESTDIR=$RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/etc/init.d/
install -m 755 %{SOURCE1} $RPM_BUILD_ROOT/etc/init.d/rpcbind
ln -s /etc/init.d/rpcbind $RPM_BUILD_ROOT/sbin/rcrpcbind
mkdir -p $RPM_BUILD_ROOT%_localstatedir/lib/rpcbind
# fillup template
mkdir -p $RPM_BUILD_ROOT/var/adm/fillup-templates
install -m 644 %{SOURCE2} $RPM_BUILD_ROOT/var/adm/fillup-templates/
mkdir -p $RPM_BUILD_ROOT%_datadir/omc/svcinfo.d
install -m 644 %{SOURCE3} $RPM_BUILD_ROOT%_datadir/omc/svcinfo.d/
#
install -m 755 pmap_set $RPM_BUILD_ROOT/sbin/pmap_set2

%clean
rm -rf $RPM_BUILD_ROOT

%pre
# upgrade case from portmap
# 1. if portmap is running, dump portmap tables
if test -x /sbin/portmap && /sbin/checkproc /sbin/portmap; then
	rm -f %statefile
	test -x /sbin/pmap_dump && /sbin/pmap_dump > %statefile
fi
# 2. disable portmap service to be able to enable rpcbind	
if test -x /sbin/portmap && /sbin/chkconfig -c portmap 3; then
        /sbin/insserv -f -r portmap
fi
%if 0%{?has_systemd}
%service_add_pre %{name}.service %{name}.socket
%endif

%preun
%stop_on_removal rpcbind
%if 0%{?has_systemd}
%service_del_preun %{name}.service %{name}.socket
%endif

%post
%fillup_and_insserv rpcbind
# if portmap is running, we need to stop portmap *now*,
# start rpcbind and restore the old tables
if test -r %statefile; then
	/etc/init.d/portmap stop > /dev/null || :
	/etc/init.d/rpcbind start > /dev/null || :
	/sbin/pmap_set2 < %statefile
	rm -f %statefile
fi
%if 0%{?has_systemd}
%service_add_post %{name}.service %{name}.socket
%endif

%postun
%restart_on_update rpcbind
%insserv_cleanup
%if 0%{?has_systemd}
%service_del_postun %{name}.service %{name}.socket
%endif

%files
%defattr(-,root,root)
%doc AUTHORS ChangeLog COPYING NEWS README
/sbin/pmap_set2
/sbin/rpcbind
/sbin/rpcinfo
%{_mandir}/*/*
%config /etc/init.d/rpcbind
/sbin/rcrpcbind
%{_localstatedir}/lib/rpcbind
/var/adm/fillup-templates/sysconfig.rpcbind
%{_datadir}/omc/svcinfo.d/rpcbind.xml
%if 0%{?has_systemd}
%{_unitdir}/%{name}.service
%{_unitdir}/%{name}.socket
%endif

%changelog
* Wed Nov 28 2012 rmilasan@suse.com
- Move rpcbind.sock and rpcbind.lock to /run to not interfere with
  systemd.
* Thu Oct 25 2012 crrodriguez@opensuse.org
- Instead of using syslog, log to the journal
* Wed Oct 24 2012 crrodriguez@opensuse.org
- There should be no Requires on syslog as it is no longer
  required for anything since the introduction of the journal.
* Wed Apr 18 2012 jeffm@suse.de
- socket-activation: Fix rpcbind.service to use separate
  sockets (bnc#757909).
* Wed Apr 18 2012 jeffm@suse.de
- socket-activation: don't unlink socket we didn't create (bnc#757667).
* Mon Dec 19 2011 crrodriguez@opensuse.org
- Update systemd patches
* Wed Dec  7 2011 crrodriguez@opensuse.org
- Add systemd socket activation patch, based on
  http://www.spinics.net/lists/linux-nfs/msg14371.html
  but does not bundle sd-daemon.[c|h] it uses libsystemd-daemon
  instead.
* Sun Dec  4 2011 crrodriguez@opensuse.org
- Update to version 0.2.0_git201103171419
- Fix rpm source tags to not be conditional.
* Tue Nov 29 2011 crrodriguez@opensuse.org
- Add systemd units
* Fri Nov 25 2011 coolo@suse.com
- add libtool as buildrequire to avoid implicit dependency
* Tue Jun 14 2011 aj@suse.de
- Install rpcinfo man page since glibc does not install its man
  page anymore.
* Wed Jan 12 2011 lnussel@suse.de
- don't enable rpcbind init script by default
* Tue Dec  7 2010 coolo@novell.com
- add some provides and requires for sysvinit scripts to please insserv
* Sun Nov 14 2010 cristian.rodriguez@opensuse.org
- Use full RELRO here
* Tue Oct 26 2010 cristian.rodriguez@opensuse.org
-  Update to a newer GIT snapshot
  * nd: set SO_REUSEADDR on NC_TPI_COTS listening sockets
  * rpcbind: add no-fork mode
* Thu Dec  4 2008 coolo@suse.de
- fix "checkproc: command not found" during installation
* Mon Dec  1 2008 ro@suse.de
- rename installed pmap_set to pmap_set2 to avoid conflict
  with portmap
* Mon Dec  1 2008 mkoenig@suse.de
- if upgrading from portmap:
  * we need to stop portmap and start rpcbind in %%post since the
    restart on upgrade mechanism does not work here
  * dump portmap tables and set them again in rpcbind [bnc#446388]
- add pmap_set.c which is needed to set the old portmap tables
  in rpcbind
* Wed Nov 26 2008 mkoenig@suse.de
- specify runlevel in chkconfig check [bnc#444663]
* Wed Nov  5 2008 mkoenig@suse.de
- fix version comparison in Obsoletes [bnc#440313]
- disable portmap service in pre script to avoid problems when
  upgrading from portmap
* Wed Oct 15 2008 mkoenig@suse.de
- update to 0.1.6 with additional patches from git
  * Fixed an ipv6 related segfault on startup
  * rpcbind needs to also downgrade its gid to a non-priviledgied group
  * Removed the documentation about the non-existent '-L' flag
  * Introduce helpers for ipprot/netid mapping
  * Change how we decide on the netids to use for portmap
  * Simplify port live check in pmap_svc.c
  * Support portmap on AF_LOCAL, too
  * Fix for warm start
  * Properly identify local root user over ipv4/v6
- fixes [bnc#435637]
- remove patch
  rpcbind-0.1.4-iff_up.patch
  rpcbind-0.1.4-localaddr.patch
* Mon Aug 18 2008 mkoenig@suse.de
- use version in Provides/Obsoletes
* Fri Jul 18 2008 mkoenig@suse.de
- update to version 0.1.5
- license change to BSD-3
- patches merged
  rpcbind-0.1.4-compile.patch
  rpcbind-0.1.4-debug.patch
  rpcbind-0.1.4-libwrap.patch
  rpcbind-0.1.4-recvfrom-fix.patch
  rpcbind-0.1.4-rpcuser.patch
  rpcbind-0.1.4-warmstarts-cleanup.patch
  rpcbind-0.1.4-warmstarts.patch
* Wed Apr  2 2008 mkoenig@suse.de
- initial packaging, version 0.1.4 [fate#300607]
- add patches from Steve Dickson, including fixes and
  support for debug and warmstart
- build as PIE