File wireguard.spec of Package wireguard

%define realname wireguard-tools
%define realver  1.0.20210914
%define srcext   tar.xz

%define modver   1.0.20211208

%bcond_without systemd

# turn off the generation of debuginfo rpm  (RH9) ??
%global debug_package %{nil}

# Common info
Name:          wireguard
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       GPL-2.0
Group:         Productivity/Networking/Security
URL:           https://www.wireguard.io/
Summary:       Fast, modern, secure kernel VPN tunnel

# Install-time parameters
Provides:      wireguard-tools = %{version}-%{release}

%if %{with systemd}
BuildRequires: systemd-devel
Requires:      systemd
%endif

# Build-time parameters
ExclusiveOS:   linux
BuildRequires: pkgconfig
BuildRequires: xz
BuildRequires: pkgconfig(libmnl)
%if 0%{?opensuse_bs}
BuildRequires: dkms
%endif
BuildRoot:     %{_tmppath}/%{name}-root
Source0:       wireguard-tools-%{realver}.%{srcext}
Source1:       wireguard-linux-compat-%{modver}.%{srcext}

%description
WireGuard is a novel VPN that runs inside the Linux Kernel and utilizes
state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more
useful than IPSec, while avoiding the massive headache. It intends to be
considerably more performant than OpenVPN. WireGuard is designed as a general
purpose VPN for running on embedded interfaces and super computers alike, fit
for many different circumstances. It runs over UDP.

%package dkms
Version:       %{modver}
Group:         System/Kernel
Summary:       WireGuard secure network tunnel
Requires:      dkms kernel-devel >= 3.10
%if 0%{?suse_version} && ! 0%{?sles_version}
BuildArch:     noarch
%endif

%description dkms
Kernel module for WireGuard

WireGuard is a secure, fast, and easy to use replacement for IPSec
that uses modern cryptography and clever networking tricks. It's
designed to be fairly general purpose and abstract enough to fit most
use cases, while at the same time remaining extremely simple to
configure. See www.wireguard.io for more info.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver} -a1

%build
%{__make} -C src %{?_smp_mflags} \
 WIREGUARD_TOOLS_VERSION=%{realver} \
 WITH_BASHCOMPLETION=yes \
 WITH_WGQUICK=yes \
%if 0%{?_unitdir:1}
 WITH_SYSTEMDUNITS=yes \
 RUNSTATEDIR=%{_rundir} \
%endif
 V=1

%install
%{__install} -d -m0755 %{buildroot}%{_prefix}/src
%{__cp} -r wireguard-linux-compat-%{modver}/src %{buildroot}%{_prefix}/src/wireguard-%{modver}
%{__rm} -f %{buildroot}%{_prefix}/src/wireguard-%{modver}/Makefile
%{__make} -C src install DESTDIR=%{buildroot} \
 WITH_BASHCOMPLETION=yes \
 WITH_WGQUICK=yes \
%if 0%{?_unitdir:1}
 WITH_SYSTEMDUNITS=yes \
%endif
 V=1

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%files
%defattr(-,root,root)
%doc COPYING README.md
%dir %{_sysconfdir}/%{name}
%{_bindir}/*
%{_datadir}/bash-completion/completions/wg*
%if 0%{?_unitdir:1}
%{_unitdir}/*.service
%{_unitdir}/*.target
%endif
%doc %{_mandir}/man8/*

%files dkms
%defattr(-,root,root)
%doc wireguard-linux-compat-%{modver}/COPYING wireguard-linux-compat-%{modver}/README.md
%dir %{_prefix}/src/wireguard-%{modver}
%{_prefix}/src/wireguard-%{modver}/*

%if 0%{?suse_version} && 0%{?_unitdir:1}

%pre
%{service_add_pre wg-quick.target}
%{service_add_pre wg-quick@.service}

%post
%{service_add_post wg-quick.target}
%{service_add_post wg-quick@.service}

%preun
%{service_del_preun wg-quick.target}
%{service_del_preun wg-quick@.service}

%postun
%{service_del_postun wg-quick.target}
%{service_del_postun wg-quick@.service}

%endif

%post dkms
for ver in $(%{_sbindir}/dkms status | awk -v M=%{name} -v V=%{version} -F '[,:] *' '$1 == M && $2 != V {print $2}'); do
    %{_sbindir}/dkms remove -q --all -m %{name} -v $ver || :
done
%{_sbindir}/dkms add -q -m %{name} -v %{version} || :

%preun dkms
if [ $1 -eq 0 ]; then
    %{_sbindir}/dkms remove -q --all -m %{name} -v %{version} || :
fi

%changelog
openSUSE Build Service is sponsored by