File dnf.spec of Package dnf

# spec file for package dnf
# Copyright (c) 2021 SUSE LLC
# Copyright (c) 2020-2021 Neal Gompa <>.
# 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

%global hawkey_version 0.61.1
%global libcomps_version 0.1.8
%global libmodulemd_version 2.9.3
%global rpm_version 4.14.0
%global min_plugins_core 4.0.20
%global min_plugins_extras 4.0.4

%global confdir %{_sysconfdir}/%{name}

%global pluginconfpath %{confdir}/plugins

%global py3pluginpath %{python3_sitelib}/dnf-plugins

%global persistdir %{_prefix}/lib/sysimage/%{name}

# YUM v3 has been removed from openSUSE Tumbleweed as of 20191119
%if 0%{?sle_version} && 0%{?sle_version} < 160000
%bcond_with as_yum
%bcond_without as_yum

%if %{with as_yum}
%global yum_subpackage_name yum
%global yum_subpackage_name dnf-yum

# Tests fail (possibly due to failures in libdnf tests on SUSE)
# Until those are resolved, these will remain disabled
%bcond_with tests

Name:           dnf
Version:        4.7.0
Release:        0
Summary:        Package manager forked from Yum, using libsolv as a dependency resolver
# For a breakdown of the licensing, see PACKAGE-LICENSING
License:        GPL-2.0-or-later AND GPL-2.0-only
Group:          System/Packages
Source0:        %{url}/archive/%{version}/%{name}-%{version}.tar.gz

# Backports from upstream

# Fixes proposed upstream

# openSUSE specific fixes
## Migrate DNF persistent state directory to /usr/lib/sysimage
Patch1001:      dnf-4.6.0-Use-usr-lib-sysimage-for-the-persistent-state-dir.patch
## We defalut allow_vendor_change to False, upstream has it as True
Patch1002:      dnf-4.6_vendor_change_doc.patch

BuildRequires:  bash-completion
BuildRequires:  cmake
BuildRequires:  gettext
BuildRequires:  python3-Sphinx
BuildRequires:  python3-bugzilla
BuildRequires:  systemd-rpm-macros
Requires:       python3-dnf = %{version}-%{release}
Recommends:     %{name}-lang >= %{version}
Recommends:     dnf-plugins-core
Recommends:     %{yum_subpackage_name}
Conflicts:      dnf-plugins-core < %{min_plugins_core}
Provides:       dnf-command(autoremove)
Provides:       dnf-command(check-update)
Provides:       dnf-command(clean)
Provides:       dnf-command(distro-sync)
Provides:       dnf-command(downgrade)
Provides:       dnf-command(group)
Provides:       dnf-command(history)
Provides:       dnf-command(info)
Provides:       dnf-command(install)
Provides:       dnf-command(list)
Provides:       dnf-command(makecache)
Provides:       dnf-command(mark)
Provides:       dnf-command(provides)
Provides:       dnf-command(reinstall)
Provides:       dnf-command(remove)
Provides:       dnf-command(repolist)
Provides:       dnf-command(repoquery)
Provides:       dnf-command(repository-packages)
Provides:       dnf-command(search)
Provides:       dnf-command(updateinfo)
Provides:       dnf-command(upgrade)
Provides:       dnf-command(upgrade-to)
BuildArch:      noarch

DNF is a package manager for RPM systems that was forked from Yum. Among the
many improvements, it uses libsolv as a dependency resolver.

%package data
Summary:        Common data and configuration files for DNF
Group:          System/Packages
Obsoletes:      dnf-conf < 4.4.2
Provides:       dnf-conf = %{version}-%{release}
Recommends:     logrotate

%description data
This package provides the common data and configuration files for DNF.

%package -n %{yum_subpackage_name}
Summary:        As a Yum CLI compatibility layer, supplies %{_bindir}/yum redirecting to DNF
Group:          System/Packages
Requires:       dnf = %{version}-%{release}
%if %{with as_yum}
Obsoletes:      dnf-yum < %{version}-%{release}
Obsoletes:      yum < 4.0.0
Provides:       dnf-yum = %{version}-%{release}
# SUSE-specific split up of yum-utils features obsoleted by DNF itself...
%global yum_replaces() \
Obsoletes:      %{1} < 4.0.0 \
Provides:       %{1} = %{version}-%{release}

%yum_replaces  yum-aliases
%yum_replaces  yum-allowdowngrade
%yum_replaces  yum-basearchonly
%yum_replaces  yum-downloadonly
%yum_replaces  yum-fastestmirror
%yum_replaces  yum-priorities
%yum_replaces  yum-protect-packages
%yum_replaces  yum-protectbase
%yum_replaces  yum-refresh-updatesd
%yum_replaces  yum-tsflags

# yum-utils plugins with no replacement
Conflicts:      yum-filter-data
Conflicts:      yum-list-data
Conflicts:      yum-tmprepo
Conflicts:      yum-upgrade-helper
Conflicts:      yum-verify
Conflicts:      yum

%description -n %{yum_subpackage_name}
As a Yum CLI compatibility layer, it supplies %{_bindir}/yum redirecting to DNF.

%package -n python3-dnf
Summary:        Python 3 interface to DNF
Group:          System/Packages
BuildRequires:  python3-curses
BuildRequires:  python3-devel
BuildRequires:  python3-gpg
BuildRequires:  python3-hawkey >= %{hawkey_version}
BuildRequires:  python3-libcomps >= %{libcomps_version}
BuildRequires:  python3-libmodulemd >= %{libmodulemd_version}
BuildRequires:  python3-rpm >= %{rpm_version}
Recommends:     (python3-dbus-python if NetworkManager)
Requires:       deltarpm
Requires:       dnf-data = %{version}-%{release}
Requires:       python3-curses
Requires:       python3-gpg
Requires:       python3-hawkey >= %{hawkey_version}
Requires:       python3-libcomps >= %{libcomps_version}
Requires:       python3-libmodulemd >= %{libmodulemd_version}
Requires:       python3-rpm >= %{rpm_version}
Recommends:     bash-completion
# DNF 2.0 doesn't work with old plugins
Conflicts:      python3-dnf-plugins-core < %{min_plugins_core}
Conflicts:      python3-dnf-plugins-extras-common < %{min_plugins_extras}
# Python 2 subpackage is no longer provided
Obsoletes:      python2-dnf < 4.0.10

%description -n python3-dnf
This package provides the Python 3 interface to DNF.


%package automatic
Summary:        Alternative CLI to "dnf upgrade" suitable for automatic, regular execution
Group:          System/Packages
BuildRequires:  systemd-rpm-macros
Requires:       dnf = %{version}-%{release}

%description automatic
Alternative CLI to "dnf upgrade" suitable for automatic, regular execution.

%autosetup -p1

# Fix sphinx-build run...
sed -e "s/sphinx-build-3/sphinx-build-%{python3_version}/" -i doc/CMakeLists.txt

%cmake -DPYTHON_DESIRED:FILEPATH=%{__python3}
make doc-man

pushd ./build

%find_lang %{name}

mkdir -p %{buildroot}%{confdir}/repos.d
mkdir -p %{buildroot}%{confdir}/vars
mkdir -p %{buildroot}%{pluginconfpath}
mkdir -p %{buildroot}%{py3pluginpath}
mkdir -p %{buildroot}%{persistdir}
mkdir -p %{buildroot}%{_sharedstatedir}
ln -sf %{persistdir} %{buildroot}%{_sharedstatedir}/%{name}
mkdir -p %{buildroot}%{_localstatedir}/log
mkdir -p %{buildroot}%{_var}/cache/dnf
touch %{buildroot}%{_localstatedir}/log/%{name}.log

ln -sr %{buildroot}%{_bindir}/dnf-3 %{buildroot}%{_bindir}/dnf
mv %{buildroot}%{_bindir}/dnf-automatic-3 %{buildroot}%{_bindir}/dnf-automatic
ln -sr %{buildroot}%{_bindir}/dnf-3 %{buildroot}%{_bindir}/yum

%if %{with as_yum}
mkdir -p %{buildroot}%{_sysconfdir}/yum
ln -sr  %{buildroot}%{confdir}/%{name}.conf %{buildroot}%{_sysconfdir}/yum/yum.conf
ln -sr  %{buildroot}%{pluginconfpath} %{buildroot}%{_sysconfdir}/yum/pluginconf.d
ln -sr  %{buildroot}%{confdir}/protected.d %{buildroot}%{_sysconfdir}/yum/protected.d
ln -sr  %{buildroot}%{confdir}/repos.d %{buildroot}%{_sysconfdir}/yum/repos.d
ln -sr  %{buildroot}%{confdir}/vars %{buildroot}%{_sysconfdir}/yum/vars
# We don't want this just yet...
rm -f %{buildroot}%{confdir}/protected.d/yum.conf

# This file is not used...
rm -f %{buildroot}%{confdir}/dnf-strict.conf

# We don't have ABRT/libreport in openSUSE
rm -rf %{buildroot}%{_sysconfdir}/libreport

%if %{with tests}
pushd ./build
make ARGS="-V" test

%dir %{_var}/cache/dnf

%files lang -f %{name}.lang

%files data
%dir %{confdir}
%dir %{pluginconfpath}
%dir %{confdir}/aliases.d
%dir %{confdir}/protected.d
%dir %{confdir}/repos.d
%dir %{confdir}/vars
%config(noreplace) %{confdir}/%{name}.conf
%config(noreplace) %{confdir}/aliases.d/zypper.conf
%config(noreplace) %{confdir}/protected.d/%{name}.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%ghost %{_localstatedir}/log/hawkey.log
%ghost %{_localstatedir}/log/%{name}.log
%ghost %{_localstatedir}/log/%{name}.librepo.log
%ghost %{_localstatedir}/log/%{name}.rpm.log
%ghost %{_localstatedir}/log/%{name}.plugin.log
%dir %{persistdir}
%ghost %{persistdir}/groups.json
%ghost %{persistdir}/yumdb
%ghost %{persistdir}/history
%ghost %{_sharedstatedir}/%{name}

%files -n %{yum_subpackage_name}
%if %{with as_yum}
%dir %{_sysconfdir}/yum
%config(noreplace) %{confdir}/protected.d/yum.conf

%files -n python3-dnf
%exclude %{python3_sitelib}/dnf/automatic
%dir %{py3pluginpath}

%files automatic
%config(noreplace) %{confdir}/automatic.conf

%systemd_post %{name}-makecache.timer

%systemd_preun %{name}-makecache.timer

%systemd_postun_with_restart %{name}-makecache.timer

%post automatic
%systemd_post %{name}-automatic.timer %{name}-automatic-notifyonly.timer %{name}-automatic-download.timer %{name}-automatic-install.timer

%preun automatic
%systemd_preun %{name}-automatic.timer %{name}-automatic-notifyonly.timer %{name}-automatic-download.timer %{name}-automatic-install.timer

%postun automatic
%systemd_postun_with_restart %{name}-automatic.timer %{name}-automatic-notifyonly.timer %{name}-automatic-download.timer %{name}-automatic-install.timer

%pretrans -n %{name}-data -p <lua>
-- Migrate DNF state data to /usr/lib/sysimage if it is still in /var/lib
oldpersistdir = "%{_sharedstatedir}/%{name}"
newpersistdir = "%{persistdir}"
chkoldst = posix.stat(oldpersistdir)
chknewst = posix.stat(newpersistdir)
if chkoldst and chkoldst.type == "directory" then
  if chknewst then
    rmst = os.execute("rm -rf " .. newpersistdir)
  status = os.execute("mv " .. oldpersistdir .. " " .. newpersistdir)
  if status then
    posix.symlink(oldpersistdir, newpersistdir)

%post -n %{name}-data
# Complete migration of DNF state data to /usr/lib/sysimage
if [ ! -L "%{_sharedstatedir}/%{name}" ]; then
   if [ -d "%{persistdir}" ]; then
      ln -sr %{persistdir} %{_sharedstatedir}/%{name}

%if %{with as_yum}
%pretrans -n %{yum_subpackage_name} -p <lua>
-- Backup all legacy YUM package manager configuration subdirectories if they exist
yumconfpath = "%{_sysconfdir}/yum"
chkst = posix.stat(yumconfpath)
if chkst and chkst.type == "directory" then
  yumdirs = {"%{_sysconfdir}/yum/pluginconf.d", "%{_sysconfdir}/yum/protected.d", "%{_sysconfdir}/yum/repos.d", "%{_sysconfdir}/yum/vars"}
  for num,path in ipairs(yumdirs)
    st = posix.stat(path)
    if st and st.type == "directory" then
      status = os.rename(path, path .. ".rpmmoved")
      if not status then
        suffix = 0
        while not status do
          suffix = suffix + 1
          status = os.rename(path .. ".rpmmoved", path .. ".rpmmoved." .. suffix)
        os.rename(path, path .. ".rpmmoved")

openSUSE Build Service is sponsored by