From 7d793a238535659dd42c97f941c7ef27c3578aea Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Wed, 11 Sep 2024 09:59:02 +0200 Subject: [PATCH] automatic: Use original dnf4 config file location Since the automatic configuration file remains compatible, this change makes the upgrade dnf4->dnf5 easier for the user. Having so many automatic config files seems overly complicated so the change also deprecates /etc/dnf/dnf5-plugins/automatic.conf location and warns the user if they are using it. --- dnf5-plugins/automatic_plugin/automatic.cpp | 21 ++++++++++++++++----- dnf5.spec | 2 ++ doc/changes.rst | 1 - doc/dnf5_plugins/automatic.8.rst | 4 ++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/dnf5-plugins/automatic_plugin/automatic.cpp b/dnf5-plugins/automatic_plugin/automatic.cpp index d53555b70..48484865e 100644 --- a/dnf5-plugins/automatic_plugin/automatic.cpp +++ b/dnf5-plugins/automatic_plugin/automatic.cpp @@ -281,22 +281,33 @@ void AutomaticCommand::pre_configure() { // read the config files in following order (/etc overrides /usr): // - [installroot]/usr/share/dnf5/dnf5-plugins/automatic.conf - // - [installroot]/etc/dnf/dnf5-plugins/automatic.conf + // - [installroot]/etc/dnf/dnf5-plugins/automatic.conf [deprecated] + // - [installroot]/etc/dnf/automatic.conf auto & main_config = base.get_config(); bool use_host_config{main_config.get_use_host_config_option().get_value()}; std::filesystem::path installroot_path{main_config.get_installroot_option().get_value()}; - std::vector possible_paths{"/usr/share/dnf5/dnf5-plugins", "/etc/dnf/dnf5-plugins"}; - for (const auto & pth : possible_paths) { + std::vector> possible_paths{ + {"/usr/share/dnf5/dnf5-plugins", false}, {"/etc/dnf/dnf5-plugins", true}, {"/etc/dnf", false}}; + auto & logger = *base.get_logger(); + for (const auto & [pth, deprecated] : possible_paths) { std::filesystem::path conf_file_path{pth / "automatic.conf"}; if (!use_host_config) { conf_file_path = installroot_path / conf_file_path.relative_path(); } if (std::filesystem::exists(conf_file_path)) { + if (deprecated) { + auto msg = libdnf5::utils::sformat( + _("Warning: Configuration file location \"{}\" for dnf automatic is deprecated. See " + "dnf5-automatic(8) for details."), + conf_file_path.string()); + logger.warning(msg); + std::cerr << msg << std::endl; + } libdnf5::ConfigParser parser; parser.read(conf_file_path); base.get_config().load_from_parser( - parser, "base", *base.get_vars(), *base.get_logger(), libdnf5::Option::Priority::AUTOMATICCONFIG); - config_automatic.load_from_parser(parser, *base.get_vars(), *base.get_logger()); + parser, "base", *base.get_vars(), logger, libdnf5::Option::Priority::AUTOMATICCONFIG); + config_automatic.load_from_parser(parser, *base.get_vars(), logger); } } diff --git a/dnf5.spec b/dnf5.spec index 8ce3d42cc..cd16d439d 100644 --- a/dnf5.spec +++ b/dnf5.spec @@ -756,6 +756,8 @@ automatically and regularly from systemd timers, cron jobs or similar. %ghost %{_sysconfdir}/motd.d/dnf5-automatic %{_libdir}/dnf5/plugins/automatic_cmd_plugin.so %{_datadir}/dnf5/dnf5-plugins/automatic.conf +%ghost %config(noreplace) %{_sysconfdir}/dnf/automatic.conf +%ghost %config(noreplace) %{_sysconfdir}/dnf/dnf5-plugins/automatic.conf %{_mandir}/man8/dnf*-automatic.8.* %{_unitdir}/dnf5-automatic.service %{_unitdir}/dnf5-automatic.timer diff --git a/doc/changes.rst b/doc/changes.rst index 5b9dd8ba1..916e37dd3 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -146,7 +146,6 @@ Changes to individual commands ``automatic`` * Now a DNF5 plugin. - * Configuration file has been moved from ``/etc/dnf/automatic.conf`` to ``/etc/dnf/dnf5-plugins/automatic.conf``. However, its contents remain compatible. * The specific systemd units, ``dnf-automatic-download``, ``dnf-automatic-install``, and ``dnf-automatic-notifyonly``, have been dropped. Only one ``dnf5-automatic`` timer is shipped. * See the :ref:`Automatic command ` for more information. diff --git a/doc/dnf5_plugins/automatic.8.rst b/doc/dnf5_plugins/automatic.8.rst index 60fc89933..082724fc7 100644 --- a/doc/dnf5_plugins/automatic.8.rst +++ b/doc/dnf5_plugins/automatic.8.rst @@ -33,7 +33,7 @@ Description Alternative CLI to ``dnf upgrade`` with specific facilities to make it suitable to be executed automatically and regularly from systemd timers, cron jobs and similar. -The operation of the tool is controlled by configuration files. Default values are set from ``/usr/share/dnf5/dnf5-plugins/automatic.conf`` config file. Host-specific overrides from ``/etc/dnf/dnf5-plugins/automatic.conf`` are then applied. +The operation of the tool is controlled by configuration files. Default values are set from ``/usr/share/dnf5/dnf5-plugins/automatic.conf`` config file. Host-specific overrides from ``/etc/dnf/automatic.conf`` are then applied. The tool synchronizes package metadata as needed and then checks for updates available for the given system and then either exits, downloads the packages or downloads and applies the updates. The outcome of the operation is then reported by a selected mechanism, for instance via the standard output, email or MOTD messages. @@ -65,7 +65,7 @@ The following options can be used to override values from the configuration file Run dnf5 automatic service ========================== -The service is typically executed using the systemd timer ``dnf5-automatic.timer``. To configure the service, customize the ``/etc/dnf/dnf5-plugins/automatic.conf`` file. You can either copy the distribution config file from ``/usr/share/dnf5/dnf5-plugins/automatic.conf`` and use it as a baseline, or create your own configuration file from scratch with only the required overrides. +The service is typically executed using the systemd timer ``dnf5-automatic.timer``. To configure the service, customize the ``/etc/dnf/automatic.conf`` file. You can either copy the distribution config file from ``/usr/share/dnf5/dnf5-plugins/automatic.conf`` and use it as a baseline, or create your own configuration file from scratch with only the required overrides. Then enable the timer unit: