File openresolv.spec of Package openresolv

#
# spec file for package openresolv
#
# Copyright (c) 2023 SUSE LLC
#
# 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 https://bugs.opensuse.org/
#


%if "@BUILD_FLAVOR@" == ""
%define flavor libc
%else
%define flavor @BUILD_FLAVOR@
%endif
%define flavors libc bind dnsmasq pdns-recursor unbound
%define other_flavors %(set -x ; echo %{flavors} | tr ' ' '\\n' | grep -v %{flavor} | tr '\\n' ' ')
Name:           openresolv
Version:        3.12.0
Release:        0
Summary:        POSIX resolvconf implementation
License:        BSD-2-Clause
URL:            https://roy.marples.name/projects/openresolv
Source:         https://github.com/NetworkConfiguration/%{name}/archive/refs/tags/%{name}-%{version}.tar.gz#/%name-%version.tar.gz
Source1:        bind-resolvconf.service
Source2:        bind-resolvconf.conf
Source3:        resolvconf-bind.conf
Source4:        dnsmasq-resolvconf.service
Source5:        dnsmasq-resolvconf.conf
Source6:        resolvconf-dnsmasq.conf
Source7:        pdns-recursor-resolvconf.service
Source8:        pdns-recursor-resolvconf.conf
Source9:        resolvconf-pdns-recursor.conf
Source10:       unbound-resolvconf.service
Source11:       unbound-resolvconf.conf
Source12:       resolvconf-unbound.conf
BuildRequires:  systemd-rpm-macros
Requires:       %{name}-config
# No support for wicked ATM
Conflicts:      wicked
BuildArch:      noarch

%description
The middleman between the network configuration services and %{_sysconfdir}/resolv.conf. resolvconf itself is just a script that stores, removes and lists a full resolv.conf generated for the interface. It then calls all the helper scripts it knows about so it can configure the real %{_sysconfdir}/resolv.conf and optionally any local nameservers other than libc.

 * Works with POSIX shell and userland
 * Prefer configs via IF_METRIC for dynamic ordering
 * Configures zones for local resolvers other than libc - split DNS

openresolv ships with helpers for:

 * unbound
 * dnsmasq
 * ISC BIND
 * PowerDNS Recursor

%package %{flavor}
Summary:        openresolv configuration for %{flavor}
%(set -x ; for i in %{other_flavors} ; do
        echo Conflicts: %{name}-$i "<=" %{version}-%{release};
        echo Obsoletes: %{name}-$i "<=" %{version}-%{release};
        done)
Provides:       %{name}-config
%systemd_requires

%description %{flavor}
openresolv configuration and service for %{flavor}

%if "%{flavor}" == "libc"
%prep
%autosetup -p1 -n %{name}-%{name}-%{version}

%build
%configure --libexecdir=%{_libexecdir}/%{name}
%make_build

%install
%make_install
# rpmlint complains about non-executable scripts
chmod 755 %{buildroot}/%{_libexecdir}/%{name}/* %{buildroot}/%{_libexecdir}/%{name}/libc.d/*

%post
if [ $1 -eq 1 ]; then
[ -x /usr/bin/nmcli ] && /usr/bin/nmcli g reload ||:
fi

%postun
if [ $1 -eq 0 ]; then
[ -x /usr/bin/nmcli ] && /usr/bin/nmcli g reload ||:
fi

%post %{flavor}
resolvconf=%{_sbindir}/resolvconf
if [ -x $resolvconf ] ; then
    $resolvconf -u
fi

%postun %{flavor}
resolvconf=%{_sbindir}/resolvconf
if [ -x $resolvconf ] ; then
    $resolvconf -u
fi

%files
%license LICENSE
%doc README.md
%{_libexecdir}/%{name}
%{_sbindir}/resolvconf
%{_mandir}/man5/resolvconf.conf.5%{?ext_man}
%{_mandir}/man8/resolvconf.8%{?ext_man}

%else
%install
install -v -m 644 -D %{_sourcedir}/resolvconf-%{flavor}.conf %{buildroot}/%{_sysconfdir}/resolvconf.conf
install -v -m 644 -D -t %{buildroot}%{_sysconfdir}/%{flavor} %{_sourcedir}/%{flavor}-resolvconf.conf
install -v -m 644 -D -t %{buildroot}/%{_unitdir} %{_sourcedir}/%{flavor}-resolvconf.service

%pre %{flavor}
%service_add_pre %{flavor}-resolvconf.service

%post %{flavor}
%service_add_post %{flavor}-resolvconf.service
resolvconf=%{_sbindir}/resolvconf
if [ -x $resolvconf ] ; then
    $resolvconf -u
fi

%preun %{flavor}
%service_del_preun %{flavor}-resolvconf.service

%postun %{flavor}
%service_del_postun %{flavor}-resolvconf.service
resolvconf=%{_sbindir}/resolvconf
if [ -x $resolvconf ] ; then
    $resolvconf -u
fi
%endif

%files %{flavor}
%{_sysconfdir}/resolvconf.conf
%if "%{flavor}" != "libc"
%{_unitdir}/%{flavor}-resolvconf.service
%dir %{_sysconfdir}/%{flavor}
%{_sysconfdir}/%{flavor}/%{flavor}-resolvconf.conf
%ghost %{_sysconfdir}/%{flavor}/%{flavor}-resolvconf-zones.conf
%ghost %{_sysconfdir}/%{flavor}/%{flavor}-resolvconf-resolv.conf
%endif

%changelog
openSUSE Build Service is sponsored by