File radvd.spec of Package radvd

# spec file for package radvd
# 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

%if ! %{defined _rundir}
%define _rundir %{_localstatedir}/run

Name:           radvd
Version:        2.11
Release:        0
Summary:        Router ADVertisement Daemon for IPv6
License:        BSD-3-Clause
Group:          Productivity/Networking/Routing
Source2:        sysconfig.radvd
Source3:        radvd.service
Source43:       %{name}.keyring
Patch1:         0001-run-as-user-radvd-by-default.diff
Patch2:         radvd-configure.patch
# PATCH-FIX-OPENSUSE radvd-tmpfile-grpname.patch -- On openSUSE, we add the radvd user to the group daemon. Thus, we also need to create the folders with the respective group owner (otherwise, the systemd-tmpfiles service fails).
Patch3:         radvd-tmpfile-grpname.patch
BuildRequires:  automake
BuildRequires:  bison
BuildRequires:  flex
BuildRequires:  libdaemon-devel
BuildRequires:  pkgconfig
BuildRequires:  systemd-rpm-macros
BuildRequires:  xz
BuildRequires:  pkgconfig(check)
Requires(pre):  %fillup_prereq
Requires(pre):  shadow
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

RADVD is the Router ADVertisement Daemon. It is used for automated
configuration of IPv6 networks. Most people will not need this.

%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1

autoreconf -fiv
%configure \
	--disable-silent-rules \
	--with-configfile=%{_sysconfdir}/radvd.conf \
make %{?_smp_mflags}

make DESTDIR=%{buildroot} install %{?_smp_mflags}
mkdir -p %{buildroot}/run/radvd
mkdir -p %{buildroot}%{_localstatedir}/adm/fillup-templates
mkdir -p %{buildroot}%{_sysconfdir}
install -m 644 %{SOURCE2} %{buildroot}%{_localstatedir}/adm/fillup-templates/
install -m 644 /dev/null %{buildroot}%{_sysconfdir}/radvd.conf

install -D -m 0644 %{SOURCE3} %{buildroot}%{_unitdir}/%{name}.service
install -D -m 0644 redhat/radvd-tmpfs.conf %{buildroot}%{_libexecdir}/tmpfiles.d/radvd-tmpfs.conf
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcradvd

getent passwd %{name} >/dev/null || useradd -r -d %{_localstatedir}/lib/empty -s /sbin/nologin -c "Router ADVertisement Daemon for" %{name}
%service_add_pre %{name}.service

# zap old (<= 11.4) default
test -f %{_sysconfdir}/sysconfig/radvd && sed -ie '/^RADVD_OPTIONS/s/-u daemon//' %{_sysconfdir}/sysconfig/radvd
%{fillup_only radvd}
random() {
	od -An -d -N2 /dev/urandom
if [ ! -e %{_sysconfdir}/radvd.conf ]; then
	# yeah, not quite the rfc4193 algorithm but hopefully
	# random enough
	prefix=`printf "fd%%02x:%%04x:%%04x:0001::/64\n" $(($(random) %% 256)) $(random) $(random)`
	cat > %{_sysconfdir}/radvd.conf <<EOF
interface eth0
	AdvSendAdvert on;

	# life time zero means we don't actually advertise a
	# router but only our ULA address. Remove if you want this
	# host to be advertised as router.
	AdvDefaultLifetime 0;

	# ULA address according to RFC 4193.
	# It was randomly created at installation of the package for
	# use in your local network.
	prefix $prefix
	echo "created %{_sysconfdir}/radvd.conf with ULA prefix $prefix"
install -d -m 755 -o radvd /run/radvd

%service_add_post %{name}.service

%service_del_postun %{name}.service

%service_del_preun %{name}.service

%ghost %dir %attr(0755,radvd,root) /run/radvd/
%ghost %config(noreplace) %{_sysconfdir}/radvd.conf
%doc radvd.conf.example
%dir %{_libexecdir}/tmpfiles.d