File dhcp.spec of Package dhcp

#
# spec file for package dhcp
#
# Copyright (c) 2015 SUSE LINUX 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/
#


%define isc_version   4.3.3
%define susefw2dir    %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services
%define omc_prefix    /usr/share/omc
%define omc_svcdir    %{omc_prefix}/svcinfo.d
# always on
%define with_ldap         1
# on sles, but sles_version is gone
%define with_ldapcasa     0%{?sles_version} >= 10 || (%suse_version >= 1110 && %suse_version < 1140)
# doc package is new on 11.3
%define with_doc_package  %suse_version >= 1130
%if 0%{?suse_version} >= 1310
%bcond_without  systemd
%else
%bcond_with     systemd
%endif

Name:           dhcp
%if %{with_ldap}
%if %{with_ldapcasa}
BuildRequires:  CASA-devel
%endif
BuildRequires:  openldap2-devel
%endif
BuildRequires:  dos2unix
BuildRequires:  libtool
Version:        4.3.3
Release:        0
Summary:        Common Files Used by ISC DHCP Software
License:        BSD-3-Clause
Group:          Productivity/Networking/Boot/Servers
Url:            http://www.isc.org/software/dhcp
Source0:        dhcp-%{isc_version}.tar.gz
Source1:        dhcp-%{isc_version}.tar.gz.asc
Source2:        %{name}.keyring
#
Source10:       dhcpd.script
Source11:       dhcrelay.script
%if %{with systemd}
Source12:       dhcpd.service
Source13:       dhcpd6.service
Source14:       dhcrelay.service
Source15:       dhcrelay6.service
%else
Source12:       rc.dhcpd
Source13:       rc.dhcpd6
Source14:       rc.dhcrelay
Source15:       rc.dhcrelay6
%endif
Source17:       sysconfig.dhcpd
Source18:       sysconfig.dhcrelay
Source19:       if-up.d.dhcpd-restart-hook
#
Source20:       dhclient.conf
Source21:       dhclient6.conf
Source22:       dhcpd.conf
Source23:       dhcpd6.conf
Source26:       sysconfig.syslog-dhcpd
Source27:       dhclient-script
#
Source30:       dhcpd.xml
Source31:       dhcpd6.xml
Source32:       SuSEfirewall2.dhcp-server
Source33:       SuSEfirewall2.dhcp6-server
#
Source41:       dhcp.README
Source43:       DDNS-howto.txt
Source44:       contrib.tar.gz
Source45:       examples.tar.gz
Patch1:         0001-dhcp-4.1.1-default-paths.patch
# paranoia patch is included now, but not the
# additional patch by thomas@suse.de not ...
Patch2:         0002-dhcp-4.1.1-paranoia.patch
Patch3:         0003-dhcp-4.2.2-man-includes.patch
Patch4:         0004-dhcp-4.1.1-tmpfile.patch
Patch5:         0005-dhcp-4.1.1-dhclient-exec-filedes.patch
Patch6:         0006-dhcp-4.3.2-dhclient-send-hostname-or-fqdn.patch
# PATCH-FIX-UPSTREAM lpf-bind-msg-fix bnc#617795
Patch7:         0007-dhcp-4.1.1-P1-lpf-bind-msg-fix.patch
# PATCH-FIX-SLE dhclient-option-checks bnc#675052
Patch8:         0008-dhcp-4.2.2-dhclient-option-checks.patch
# PATCH-FIX-OPENSUSE close-on-exec bnc#732910
Patch9:         0009-dhcp-4.2.6-close-on-exec.patch
# PATCH-FIX-OPENSUSE quiet-dhclient bnc#711420
Patch10:        0010-dhcp-4.2.2-quiet-dhclient.patch
# PATCH-FIX-UPSTREAM use-getifaddrs bnc#791289,ISC-Bugs#31992
Patch11:        0011-Fixed-linux-interface-discovery-using-getifaddrs.patch
# PATCH-FIX-OPENSUSE dhcp-4.2.x-chown-server-leases bnc#868253
Patch12:        0012-dhcp-4.2.x-chown-server-leases.bnc868253.patch
# PATCH-FIX-SLE dhcp-4.2.x-dhcpv6-decline-on-DAD-failure bnc#872609
Patch13:        0013-dhcp-4.2.x-dhcpv6-decline-on-DAD-failure.872609.patch
# PATCH-FIX-SLE dhclient6-unsigned-lifetimes-for-script bsc#926159
Patch14:        0014-dhclient6-unsigned-lifetimes-for-script-bsc-926159.patch
# PATCH-FIX-SLE Expose-next-server-DHCPv4-option-to-dhclient-script bsc#928390
Patch15:        0015-Expose-next-server-DHCPv4-option-to-dhclient-script.patch
# PATCH-FIX-SLE infiniband-support bnc#870535,bsc#909189,bsc#910984
Patch16:        0016-infiniband-support.patch
# PATCH-FIX-SLE server-no-success-report-before-send bsc#919959
Patch17:        0017-server-no-success-report-before-send.919959.patch
# PATCH-FIX-SLE client-fail-on-script-pre-init-error bsc#912098
Patch18:        0018-client-fail-on-script-pre-init-error-bsc-912098.patch
# PATCH-FIX-SLE dhcp-4.2.4-P1-interval bsc#947780
Patch19:        0019-dhcp-4.2.4-P1-interval.patch
##
PreReq:         /bin/touch /sbin/chkconfig sysconfig
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  automake

%package server
Summary:        ISC DHCP Server
Group:          Productivity/Networking/Boot/Servers
Requires:       dhcp = %{version}
Requires:       net-tools
PreReq:         %insserv_prereq %fillup_prereq /bin/cat /bin/mkdir /bin/cp /usr/sbin/useradd

%package client
Summary:        ISC DHCP Client
Group:          Productivity/Networking/Boot/Clients
Requires:       /sbin/arping
Requires:       /usr/bin/host
Requires:       dhcp = %{version}
Requires:       iproute2
Requires:       net-tools
PreReq:         %insserv_prereq %fillup_prereq /bin/cat /bin/mkdir /bin/cp /bin/grep

%package relay
Summary:        ISC DHCP Relay Agent
Group:          Productivity/Networking/Boot/Servers
Requires:       dhcp = %{version}
Requires:       net-tools
PreReq:         %insserv_prereq %fillup_prereq /bin/cat /bin/mkdir /bin/cp 

%package devel
Summary:        Header Files and Libraries for dhcpctl API
Group:          Development/Libraries/C and C++
Requires:       dhcp = %{version}

%if %{with_doc_package}

%package doc
Summary:        Documentation
Group:          Productivity/Networking/Boot/Servers
%endif

%description
This package contains common programs used by both the ISC DHCP
server ("dhcp-server" package) and client ("dhcp-client") as the
omshell and common manual pages.

Authors:
--------
    Internet Systems Consortium, Inc. <info@isc.org>


%description server
This package contains the ISC DHCP server.

Please read the documentation in /usr/share/doc/packages/dhcp-server
regarding configuration of the DHCP server.

Authors:
--------
    Internet Systems Consortium, Inc. <info@isc.org>


%description client
This is an alternative DHCP client, the ISC DHCP client for Linux. Like
"dhcpcd" (the client that is installed by default), it can be used to
configure the network setup.  IP address, hostname, routing,
nameserver, netmask, and broadcast can be dynamically assigned while
booting the machine.

It is configurable via the configuration file /etc/dhclient.conf and
you can define your own 'hooks' to be used by the /sbin/dhclient-script
(which is called by the daemon).

Authors:
--------
    Internet Systems Consortium, Inc. <info@isc.org>

%description relay
This is the ISC DHCP relay agent. It can be used as a 'gateway' for
DHCP messages across physical network segments. This is necessary
because requests can be broadcast, and they will normally not be
routed.


Authors:
--------
    Internet Systems Consortium, Inc. <info@isc.org>

%if %{with_doc_package}

%description doc
This package contains additional documentation files provided with
the software. The manual pages are in the corresponding packages.

Authors:
--------
    Internet Systems Consortium, Inc. <info@isc.org>

%endif

%description devel
This package contains all of the libraries and headers for developing
with the Internet Software Consortium (ISC) dhcpctl API.

Authors:
--------
    Internet Systems Consortium, Inc. <info@isc.org>


%prep
%setup -q -n %{name}-%{isc_version} -a 44 -a 45
##
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
##
find . -type f -name \*.cat\* -exec rm -f {} \;
dos2unix contrib/ms2isc/*
# Remove GPL licensed files to make sure,
# they're not used to build (bnc#714004).
pushd bind
gunzip -c bind.tar.gz | tar xf -
rm -rf bind-*/contrib/dbus
bind_dir=$(ls -1d bind-*)
for i in /usr/share/automake-*/config.{sub,guess} ; do
	install -v -m755 $i $bind_dir/
done
popd
##

%build
%if %suse_version >= 1210
CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE -W -Wall -Wno-unused"
%else
CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE -W -Wall -fno-strict-aliasing -Wno-unused"
%endif
%ifarch ppc ppc64 s390x
  # bugs 134590, 171532
  CFLAGS="$CFLAGS -fsigned-char"
%endif
%ifarch ia64 %sparc alpha s390x ppc64 x86_64
  CFLAGS="$CFLAGS -fPIE" 
%else
  CFLAGS="$CFLAGS -fpie" 
%endif
%if %suse_version >= 1210
LDFLAGS="-Wl,-z,relro,-z,now -pie"
%else
LDFLAGS="-pie"
%endif
FFLAGS="$CFLAGS"
CXXFLAGS="$CFLAGS"
export RPM_OPT_FLAGS LDFLAGS
export CFLAGS FFLAGS CXXFLAGS
#
%{?suse_update_config:%{suse_update_config -f}}
#libtoolize --force
#autoreconf -f -i
#
%configure \
	--enable-dhcpv6 \
	--enable-failover \
	--enable-paranoia \
	--enable-early-chroot \
%if %{with_ldap}
	--with-ldap \
	--with-ldapcrypto \
%if %{with_ldapcasa}
	--with-ldapcasa \
%endif
%endif
	--with-cli-pid-file=%{_localstatedir}/run/dhclient.pid \
	--with-cli-lease-file=%{_localstatedir}/lib/dhcp/dhclient.leases \
	--with-cli6-pid-file=%{_localstatedir}/run/dhclient6.pid \
	--with-cli6-lease-file=%{_localstatedir}/lib/dhcp6/dhclient.leases \
	--with-srv-pid-file=%{_localstatedir}/run/dhcpd.pid \
	--with-srv-lease-file=%{_localstatedir}/lib/dhcp/db/dhcpd.leases \
	--with-srv6-pid-file=%{_localstatedir}/run/dhcpd6.pid \
	--with-srv6-lease-file=%{_localstatedir}/lib/dhcp6/db/dhcpd6.leases
#
: building bind sources
make -C bind all
cat bind/configure.log
cat bind/build.log
cat bind/install.log
: building dhcp sources
make %{?_smp_mflags}

%check
# check example config, see if it runs
./server/dhcpd -4 -t -cf $RPM_SOURCE_DIR/dhcpd.conf
./server/dhcpd -6 -t -cf $RPM_SOURCE_DIR/dhcpd6.conf
# check syntax in our scripts
%if !%{with systemd}
bash -n $RPM_SOURCE_DIR/rc.dhcpd
bash -n $RPM_SOURCE_DIR/rc.dhcpd6
bash -n $RPM_SOURCE_DIR/rc.dhcrelay
bash -n $RPM_SOURCE_DIR/rc.dhcrelay6
%endif
bash -n $RPM_SOURCE_DIR/dhcpd.script
bash -n $RPM_SOURCE_DIR/dhcrelay.script
bash -n $RPM_SOURCE_DIR/dhclient-script

%install
export RPM_BUILD_ROOT
make install DESTDIR="$RPM_BUILD_ROOT"
#
# directories
install -d -m0755 $RPM_BUILD_ROOT/sbin
install -d -m0755 $RPM_BUILD_ROOT%{_sysconfdir}/dhcpd{,6}.d
install -d -m0755 $RPM_BUILD_ROOT/%{susefw2dir}
install -d -m0755 $RPM_BUILD_ROOT/%{omc_svcdir}
%if %{with_ldap}
install -d -m0755 $RPM_BUILD_ROOT%{_sysconfdir}/openldap/schema
%endif
install -d -m0755 $RPM_BUILD_ROOT%{_localstatedir}/run
install -d -m0755 $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates
# chroot jail
install -d -m0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/{dhcp,dhcp6}/etc
install -d -m0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/{dhcp,dhcp6}/dev
install -d -m0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/{dhcp,dhcp6}/%_lib
install -d -m0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/{dhcp,dhcp6}/var/run
install -d -m0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/{dhcp,dhcp6}/db
# move the dhclient binary to /sbin
mv -f $RPM_BUILD_ROOT/usr/sbin/dhclient $RPM_BUILD_ROOT/sbin/
# provide a ...6 link, so we know it supports DHCPv6
ln -sf dhcpd      $RPM_BUILD_ROOT%{_sbindir}/dhcpd6
ln -sf dhcrelay   $RPM_BUILD_ROOT%{_sbindir}/dhcrelay6
ln -sf dhclient   $RPM_BUILD_ROOT/sbin/dhclient6
# install our adopted config examples and dhclient-script:
install    -m0644 $RPM_SOURCE_DIR/dhcpd.conf      $RPM_BUILD_ROOT%{_sysconfdir}/
install    -m0644 $RPM_SOURCE_DIR/dhcpd6.conf     $RPM_BUILD_ROOT%{_sysconfdir}/
install    -m0644 $RPM_SOURCE_DIR/dhclient.conf   $RPM_BUILD_ROOT%{_sysconfdir}/
install    -m0644 $RPM_SOURCE_DIR/dhclient6.conf  $RPM_BUILD_ROOT%{_sysconfdir}/
install    -m0750 $RPM_SOURCE_DIR/dhclient-script $RPM_BUILD_ROOT/sbin/
# helper / wrapper scripts
install -d -m0755 $RPM_BUILD_ROOT/usr/lib/dhcp
install    -m0755 $RPM_SOURCE_DIR/dhcpd.script              \
                  $RPM_BUILD_ROOT/usr/lib/dhcp/dhcpd
sed -e 's/@LIBDIR@/%{_lib}/g' -i $RPM_BUILD_ROOT/usr/lib/dhcp/dhcpd
install    -m0755 $RPM_SOURCE_DIR/dhcrelay.script           \
                  $RPM_BUILD_ROOT/usr/lib/dhcp/dhcrelay
%if %{with systemd}
# service units
install -d -m0755 $RPM_BUILD_ROOT%{_unitdir}
install    -m0644 $RPM_SOURCE_DIR/dhcpd.service             \
                  $RPM_BUILD_ROOT%{_unitdir}/dhcpd.service
install    -m0644 $RPM_SOURCE_DIR/dhcpd6.service            \
                  $RPM_BUILD_ROOT%{_unitdir}/dhcpd6.service
install    -m0644 $RPM_SOURCE_DIR/dhcrelay.service          \
                  $RPM_BUILD_ROOT%{_unitdir}/dhcrelay.service
install    -m0644 $RPM_SOURCE_DIR/dhcrelay6.service         \
                  $RPM_BUILD_ROOT%{_unitdir}/dhcrelay6.service
# rcservice links
ln -sf %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rcdhcpd
ln -sf %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rcdhcpd6
ln -sf %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rcdhcrelay
ln -sf %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rcdhcrelay6
%else
# service scripts
install -d -m0755 $RPM_BUILD_ROOT%{_sysconfdir}/init.d
install    -m0755 $RPM_SOURCE_DIR/rc.dhcpd                  \
                  $RPM_BUILD_ROOT%{_sysconfdir}/init.d/dhcpd
install    -m0755 $RPM_SOURCE_DIR/rc.dhcpd6                 \
                  $RPM_BUILD_ROOT%{_sysconfdir}/init.d/dhcpd6
install    -m0755 $RPM_SOURCE_DIR/rc.dhcrelay               \
                  $RPM_BUILD_ROOT%{_sysconfdir}/init.d/dhcrelay
install    -m0755 $RPM_SOURCE_DIR/rc.dhcrelay6              \
                  $RPM_BUILD_ROOT%{_sysconfdir}/init.d/dhcrelay6
# rcservice links
ln -sf %{_sysconfdir}/init.d/dhcpd     $RPM_BUILD_ROOT%{_sbindir}/rcdhcpd 
ln -sf %{_sysconfdir}/init.d/dhcpd6    $RPM_BUILD_ROOT%{_sbindir}/rcdhcpd6
ln -sf %{_sysconfdir}/init.d/dhcrelay  $RPM_BUILD_ROOT%{_sbindir}/rcdhcrelay
ln -sf %{_sysconfdir}/init.d/dhcrelay6 $RPM_BUILD_ROOT%{_sbindir}/rcdhcrelay6
%endif
%if %suse_version > 1310
# rcservice actions
legacy_actionsdir=$RPM_BUILD_ROOT/usr/lib/initscripts/legacy-actions
cat >dhcpd.action <<'EOF'
#!/bin/bash
exec /usr/lib/dhcp/dhcpd -4 ${0##*/}
EOF
install -d -m0755 ${legacy_actionsdir}/dhcpd
install    -m0755 dhcpd.action  ${legacy_actionsdir}/dhcpd/syntax-check
ln -sf            syntax-check  ${legacy_actionsdir}/dhcpd/check-syntax
ln -sf            syntax-check  ${legacy_actionsdir}/dhcpd/check-lease
rm -f             dhcpd.action
cat >dhcpd.action <<'EOF'
#!/bin/bash
exec /usr/lib/dhcp/dhcpd -6 ${0##*/}
EOF
install -d -m0755 ${legacy_actionsdir}/dhcpd6
install    -m0755 dhcpd.action  ${legacy_actionsdir}/dhcpd6/syntax-check
ln -sf            syntax-check  ${legacy_actionsdir}/dhcpd6/check-syntax
ln -sf            syntax-check  ${legacy_actionsdir}/dhcpd6/check-lease
rm -f             dhcpd.action
%endif
# sysconfig files
install    -m0644 $RPM_SOURCE_DIR/sysconfig.dhcpd           \
                  $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/
install    -m0644 $RPM_SOURCE_DIR/sysconfig.syslog-dhcpd    \
                  $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/
install    -m0644 $RPM_SOURCE_DIR/sysconfig.dhcrelay        \
                  $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/
# another config files and scripts
%if %{with_ldap}
install    -m0644 contrib/ldap/dhcp.schema                       \
                  $RPM_BUILD_ROOT%{_sysconfdir}/openldap/schema
%endif
install    -m0644 $RPM_SOURCE_DIR/dhcpd.xml                 \
                  $RPM_SOURCE_DIR/dhcpd6.xml                \
                  $RPM_BUILD_ROOT/%{omc_svcdir}/
install    -m0644 $RPM_SOURCE_DIR/SuSEfirewall2.dhcp-server \
                  $RPM_BUILD_ROOT/%{susefw2dir}/dhcp-server
install    -m0644 $RPM_SOURCE_DIR/SuSEfirewall2.dhcp6-server \
                  $RPM_BUILD_ROOT/%{susefw2dir}/dhcp6-server
install -d -m0755 $RPM_BUILD_ROOT/etc/sysconfig/network/if-up.d
install -d -m0755 $RPM_BUILD_ROOT/etc/sysconfig/network/scripts
install    -m0755 $RPM_SOURCE_DIR/if-up.d.dhcpd-restart-hook \
                  $RPM_BUILD_ROOT/etc/sysconfig/network/scripts/dhcpd-restart-hook
ln -sf            ../scripts/dhcpd-restart-hook \
                  $RPM_BUILD_ROOT/etc/sysconfig/network/if-up.d/60-dhcpd-restart-hook
# fix manual page permissions
find $RPM_BUILD_ROOT/%{_mandir} -type f | xargs chmod 644
# copy some documentation and examples from src dir
install    -m0644 $RPM_SOURCE_DIR/dhcp.README         README.SUSE
install    -m0644 $RPM_SOURCE_DIR/DDNS-howto.txt      .
cp                doc/examples/* ./examples/
rm -f             doc/{References.xml,Makefile*}
rm -f             contrib/dhcp.spec
rm -f             $RPM_BUILD_ROOT/etc/{dhcpd,dhclient}.conf.example
find contrib doc/examples -type f | xargs chmod -x
# install bind libs+includes needed for dhcp-devel
pushd bind
install -d -m0755 $RPM_BUILD_ROOT%_includedir/dhcp/
for i in include/* ; do
	cp -r $i $RPM_BUILD_ROOT%_includedir/dhcp/
done
install -d -m0755 $RPM_BUILD_ROOT%_libdir/dhcp/
for l in lib/lib*.a ; do
	install -m0644 $l $RPM_BUILD_ROOT%_libdir/dhcp/
done
popd
# move also all dhcp-devel files to dhcp subdirectories
mv $RPM_BUILD_ROOT%_includedir/{dhcpctl,isc-dhcp,omapip} \
   $RPM_BUILD_ROOT%_includedir/dhcp/
mv $RPM_BUILD_ROOT%_libdir/lib*.* \
   $RPM_BUILD_ROOT%_libdir/dhcp/

%pre server
/usr/sbin/useradd -r -g nogroup -s /bin/false -c "DHCP server daemon" -d /var/lib/dhcp dhcpd 2> /dev/null ||:
%if %{with systemd}
%service_add_pre dhcpd.service
%service_add_pre dhcpd6.service
%endif

%post server
%if %{with systemd}
%{fillup_only -n   dhcpd dhcpd}
%{fillup_only -ans syslog dhcpd}
%service_add_post dhcpd.service
%service_add_post dhcpd6.service
%else
%{fillup_and_insserv  -n dhcpd dhcpd dhcpd6}
%{fillup_only       -ans syslog dhcpd}
%endif
# FIXME: update?
if [ ${FIRST_ARG:-0} -gt 1 ]; then
    if grep -q '^DHCPD_RUN_AS=.*nobody' etc/sysconfig/dhcpd; then
	tmpfile=$(mktemp -q etc/sysconfig/dhcpd.XXXXXX)
	sed 's|^DHCPD_RUN_AS=.*|DHCPD_RUN_AS="dhcpd"|' etc/sysconfig/dhcpd \
	  > $tmpfile && mv $tmpfile etc/sysconfig/dhcpd
	rm -f $tmpfile
    fi
    if grep -q '^DHCPD_BINARY=.*dhcpd\..*' etc/sysconfig/dhcpd; then
	tmpfile=$(mktemp -q etc/sysconfig/dhcpd.XXXXXX)
	sed 's|^DHCPD_BINARY=.*|DHCPD_BINARY=""|' etc/sysconfig/dhcpd \
	  > $tmpfile && mv $tmpfile etc/sysconfig/dhcpd
	rm -f $tmpfile
    fi
fi

%preun server
%if %{with systemd}
%service_del_preun dhcpd.service
%service_del_preun dhcpd6.service
%else
if test -x /etc/init.d/dhcpd ; then
	%stop_on_removal dhcpd
fi
if test -x /etc/init.d/dhcpd6 ; then
	%stop_on_removal dhcpd6
fi
%endif

%postun server
%if %{with systemd}
%service_del_postun dhcpd.service
%service_del_postun dhcpd6.service
%else
if test -x /etc/init.d/dhcpd ; then
	%restart_on_update dhcpd
fi
if test -x /etc/init.d/dhcpd6 ; then
	%restart_on_update dhcpd6
fi
%insserv_cleanup
%endif

%pre relay
%if %{with systemd}
%service_add_pre dhcrelay.service
%service_add_pre dhcrelay6.service
%endif

%post relay
#
%{rename_sysconfig_variable -f etc/sysconfig/dhcrelay
	DHCRELAY6_LOWER_INTERFACES_ARGS DHCRELAY6_LOWER_INTERFACES}
%{rename_sysconfig_variable -f etc/sysconfig/dhcrelay
	DHCRELAY6_UPPER_INTERFACES_ARGS DHCRELAY6_UPPER_INTERFACES}
#
%if %{with systemd}
%{fillup_only -n dhcrelay dhcrelay}
%service_add_post dhcrelay.service
%service_add_post dhcrelay6.service
%else
%{fillup_and_insserv  -n dhcrelay dhcrelay dhcrelay6}
%endif

%preun relay
%if %{with systemd}
%service_del_preun dhcrelay.service
%service_del_preun dhcrelay6.service
%else
if test -x /etc/init.d/dhcrelay ; then
	%stop_on_removal dhcrelay
fi
if test -x /etc/init.d/dhcrelay6 ; then
	%stop_on_removal dhcrelay6
fi
%endif

%postun relay
%if %{with systemd}
%service_del_postun dhcrelay.service
%service_del_postun dhcrelay6.service
%else
if test -x /etc/init.d/dhcrelay ; then
	%restart_on_update dhcrelay
fi
if test -x /etc/init.d/dhcrelay6 ; then
	%restart_on_update dhcrelay6
fi
%insserv_cleanup
%endif

%post client
test -e %{_localstatedir}/lib/dhcp/dhclient.leases   || \
  touch %{_localstatedir}/lib/dhcp/dhclient.leases
test -e %{_localstatedir}/lib/dhcp6/dhclient6.leases || \
  touch %{_localstatedir}/lib/dhcp6/dhclient6.leases

%clean
if ! test -f /.buildenv; then rm -rf $RPM_BUILD_ROOT; fi

%files
%defattr(-,root,root)
%config %{susefw2dir}/dhcp-server
%config %{susefw2dir}/dhcp6-server
%{_bindir}/omshell
%doc %{_mandir}/man1/omshell.1.gz
%doc %{_mandir}/man5/dhcp-eval.5.gz
%doc %{_mandir}/man5/dhcp-options.5.gz

%files server
%defattr(-,root,root)
%{_sbindir}/dhcpd
%{_sbindir}/dhcpd6
%{_sbindir}/rcdhcpd
%{_sbindir}/rcdhcpd6
%if %{with systemd}
%{_unitdir}/dhcpd.service
%{_unitdir}/dhcpd6.service
%if %suse_version > 1310
%dir /usr/lib/initscripts/legacy-actions/dhcpd
/usr/lib/initscripts/legacy-actions/dhcpd/*
%dir /usr/lib/initscripts/legacy-actions/dhcpd6
/usr/lib/initscripts/legacy-actions/dhcpd6/*
%endif
%else
%config %{_sysconfdir}/init.d/dhcpd
%config %{_sysconfdir}/init.d/dhcpd6
%endif
%config(noreplace) %{_sysconfdir}/dhcpd.conf
%config(noreplace) %{_sysconfdir}/dhcpd6.conf
%attr(755,root,root) %dir %config(noreplace) %ghost %{_sysconfdir}/dhcpd.d/
%attr(755,root,root) %dir %config(noreplace) %ghost %{_sysconfdir}/dhcpd6.d/
%dir /usr/lib/dhcp
/usr/lib/dhcp/dhcpd
%dir %{_localstatedir}/lib/dhcp
%dir %{_localstatedir}/lib/dhcp/etc
%dir %{_localstatedir}/lib/dhcp/dev
%dir %{_localstatedir}/lib/dhcp/%_lib
%dir %{_localstatedir}/lib/dhcp/var
%dir %{_localstatedir}/lib/dhcp/var/run
%attr(755,dhcpd,root) %dir %{_localstatedir}/lib/dhcp/db
%dir %{_localstatedir}/lib/dhcp6
%dir %{_localstatedir}/lib/dhcp6/etc
%dir %{_localstatedir}/lib/dhcp6/dev
%dir %{_localstatedir}/lib/dhcp6/%_lib
%dir %{_localstatedir}/lib/dhcp6/var
%dir %{_localstatedir}/lib/dhcp6/var/run
%attr(755,dhcpd,root) %dir %{_localstatedir}/lib/dhcp6/db
%doc %{_mandir}/man8/dhcpd.8.gz
%doc %{_mandir}/man5/dhcpd.conf.5.gz
%doc %{_mandir}/man5/dhcpd.leases.5.gz
%if %{with_ldap}
%dir %{_sysconfdir}/openldap
%dir %{_sysconfdir}/openldap/schema
%attr(0644, root, root) %config %{_sysconfdir}/openldap/schema/dhcp.schema
%endif
%{omc_svcdir}/dhcpd.xml
%{omc_svcdir}/dhcpd6.xml
%{_sysconfdir}/sysconfig/network/scripts/dhcpd-restart-hook
%{_sysconfdir}/sysconfig/network/if-up.d/60-dhcpd-restart-hook
%{_localstatedir}/adm/fillup-templates/sysconfig.dhcpd
%{_localstatedir}/adm/fillup-templates/sysconfig.syslog-dhcpd
%if %{with_doc_package}

%files doc
%defattr(-,root,root)
%endif
%doc LICENSE README RELNOTES
%doc README.* DDNS-howto.txt doc/*
%doc contrib examples

%files client 
%defattr(-,root,root)
/sbin/dhclient
/sbin/dhclient6
/sbin/dhclient-script
%config(noreplace) %{_sysconfdir}/dhclient.conf
%config(noreplace) %{_sysconfdir}/dhclient6.conf
%doc %{_mandir}/man5/dhclient.conf.5.gz
%doc %{_mandir}/man5/dhclient.leases.5.gz
%doc %{_mandir}/man8/dhclient.8.gz
%doc %{_mandir}/man8/dhclient-script.8.gz
%dir %{_localstatedir}/lib/dhcp
%dir %{_localstatedir}/lib/dhcp6

%files relay 
%defattr(-,root,root)
%{_sbindir}/dhcrelay
%{_sbindir}/dhcrelay6
%{_sbindir}/rcdhcrelay
%{_sbindir}/rcdhcrelay6
%dir /usr/lib/dhcp
/usr/lib/dhcp/dhcrelay
%if %{with systemd}
%{_unitdir}/dhcrelay.service
%{_unitdir}/dhcrelay6.service
%else
%config %{_sysconfdir}/init.d/dhcrelay
%config %{_sysconfdir}/init.d/dhcrelay6
%endif
%doc %{_mandir}/man8/dhcrelay.8.gz
%{_localstatedir}/adm/fillup-templates/sysconfig.dhcrelay

%files devel
%defattr(-,root,root)
%dir %_libdir/dhcp
%_libdir/dhcp/lib*
%dir %{_prefix}/include/dhcp
%{_prefix}/include/dhcp/*
%doc %{_mandir}/man3/omapi.3.gz
%doc %{_mandir}/man3/dhcpctl.3.gz

%changelog