File fastd.spec of Package fastd

%bcond_with html_docs
%global docs_type %{?with_html_docs:html}%{!?with_html_docs:text}

Name:			fastd
Version:		22
Release:		1
Summary:		Fast and Secure Tunneling Daemon
Group:			Productivity/Networking/Security
License:		BSD-2-Clause AND BSD-3-Clause
URL:			https://fastd.readthedocs.io/
Source0:		https://github.com/neocturne/%{name}/releases/download/v%{version}/%{name}-%{version}.tar.xz
Patch0:			manpage-fix.diff

BuildRequires:	meson
BuildRequires:	bison
BuildRequires:	gcc
BuildRequires:	pkg-config
BuildRequires:	pkgconfig(libuecc)
BuildRequires:	pkgconfig(libcap)
BuildRequires:	pkgconfig(libsodium)
BuildRequires:	pkgconfig(libcrypto)
BuildRequires:	pkgconfig(json-c)
BuildRequires:	pkgconfig(libmnl)
# for tests
BuildRequires:	pkgconfig(cmocka)
# for docs
BuildRequires:	python3-Sphinx
BuildRequires:	make
# for %%install
BuildRequires:	/usr/bin/find

%description
fastd is a very small VPN daemon which tunnels IP packets and Ethernet frames
over UDP. It supports various modern encryption and authentication schemes and
can be used in many different network topologies (1:1, 1:n, meshed).

%prep
%autosetup -p1

%build
%meson -Dbuild_tests=true
%meson_build
%make_build -C doc %{docs_type}

%install
%meson_install
install -Dm644 doc/examples/fastd@.service %{buildroot}%{_unitdir}/%{name}@.service
%if "%{_sysconfdir}" != "/etc"
	sed -i -e 's#/etc/fastd#%{_sysconfdir}/fastd#g' %{buildroot}%{_unitdir}/%{name}@.service
%endif
install -Dm644 doc/fastd.1 %{buildroot}%{_mandir}/man1/%{name}.1
sed -i -e 's#@PKGDOCDIR@#%{_docdir}/%{name}#g' %{buildroot}%{_mandir}/man1/%{name}.1
install -d %{buildroot}%{_sysconfdir}/%{name}
%{?with_html_docs:rm doc/build/html/.buildinfo}
# don't install as executable in docdir
chmod -x doc/examples/status.pl
# remove all from examples/ except status.{c,pl} so we can install it with %%doc
find doc/examples -mindepth 1 \! -iname 'status.*' -delete
# snip libmnl license statement (we dynamically link it from its own package)
sed -i -e '/libmnl/,$ d' COPYRIGHT

%check
%meson_test

%preun
# note: no %%pre/%%post; package only has template unit with no default
if command -v systemctl >/dev/null \
  && [ -n "${systemd_ver:=$(systemctl --version | grep -Eom1 '\b[[:digit:]]+' | head -n1)}" ] \
  && [ $systemd_ver -lt 250 ]; then
	live_units=( $(systemctl --plain --quiet --type=service list-units "%{name}@*" | cut -d' ' -f1) )
else
	live_units=( "%{name}@*" )
fi
%systemd_preun "${live_units[@]}"

%postun
# note: no %%pre/%%post; package only has template unit with no default
if command -v systemctl >/dev/null \
  && [ -n "${systemd_ver:=$(systemctl --version | grep -Eom1 '\b[[:digit:]]+' | head -n1)}" ] \
  && [ $systemd_ver -lt 250 ]; then
	live_units=( $(systemctl --plain --quiet --type=service list-units "%{name}@*" | cut -d' ' -f1) )
else
	live_units=( "%{name}@*" )
fi
%systemd_postun "${live_units[@]}"

%files
%doc README.md doc/build/%{docs_type}/* doc/examples
%license COPYRIGHT
%dir %{_sysconfdir}/%{name}
%{_mandir}/man1/%{name}.1*
%{_unitdir}/%{name}@.service
%{_bindir}/%{name}

%changelog

openSUSE Build Service is sponsored by