Skip to content

Commit

Permalink
automatic: Change location of automatic.conf
Browse files Browse the repository at this point in the history
The configuration is now read from /etc/dnf/dnf5-plugins/automatic.conf.
If this file does not exist, then the distribution configuration file
from /usr/share/dnf5/dnf5-plugins/automatic.conf is used.

The commit also removes config file in
/etc/dnf/dnf5-plugins/automatic.conf from package to make the
distribution configuration file work. Otherwise it would never be used.
Config values from automatic.conf are those hardcoded in the code.
  • Loading branch information
m-blaha authored and j-mracek committed Feb 19, 2024
1 parent 5e73570 commit 5b93250
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 141 deletions.
1 change: 0 additions & 1 deletion dnf5-plugins/automatic_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ target_link_libraries(automatic_cmd_plugin PRIVATE libdnf5 libdnf5-cli)
target_link_libraries(automatic_cmd_plugin PRIVATE dnf5)

install(TARGETS automatic_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/)
install(DIRECTORY "config/etc/" DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}")
install(DIRECTORY "config/usr/" DESTINATION "${CMAKE_INSTALL_PREFIX}")

install(PROGRAMS bin/dnf-automatic TYPE BIN)
Expand Down
43 changes: 16 additions & 27 deletions dnf5-plugins/automatic_plugin/automatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,6 @@ void AutomaticCommand::set_argument_parser() {
auto & context = get_context();
auto & parser = context.get_argument_parser();

auto arg_config_file = parser.add_new_positional_arg(
"config_path", libdnf5::cli::ArgumentParser::PositionalArg::OPTIONAL, nullptr, nullptr);
arg_config_file->set_description(_("Path to dnf5-automatic config file."));
arg_config_file->set_parse_hook_func(
[&]([[maybe_unused]] libdnf5::cli::ArgumentParser::PositionalArg * arg, int argc, const char * const argv[]) {
if (argc > 0) {
config_automatic.automatic_config_file_path.set(argv[0]);
}
return true;
});
cmd.register_positional_arg(arg_config_file);

timer = std::make_unique<libdnf5::cli::session::BoolOption>(
*this, "timer", '\0', _("Apply random delay before execution."), false);
auto downloadupdates = std::make_unique<libdnf5::cli::session::BoolOption>(
Expand Down Expand Up @@ -290,25 +278,26 @@ void AutomaticCommand::pre_configure() {
base.set_download_callbacks(std::move(download_callbacks_uptr));
download_callbacks_set = true;

// read the config file, use the first existing file in following locations:
// - [installroot]/etc/dnf/dnf5-plugins/automatic.conf
// - [installroot]/usr/share/dnf5/d nf5-plugins/automatic.conf
auto & main_config = base.get_config();
bool use_host_config{main_config.get_use_host_config_option().get_value()};
bool user_defined_config_file_name{
config_automatic.automatic_config_file_path.get_priority() >= libdnf5::Option::Priority::COMMANDLINE};
std::filesystem::path conf_file_path{config_automatic.automatic_config_file_path.get_value()};
if (!use_host_config) {
if (!user_defined_config_file_name) {
// unless the --use-host-config was used or config file was passed on cmdline,
// prepend the installroot
std::filesystem::path installroot_path{main_config.get_installroot_option().get_value()};
std::filesystem::path installroot_path{main_config.get_installroot_option().get_value()};
std::vector<std::filesystem::path> possible_paths{"/etc/dnf/dnf5-plugins", "/usr/share/dnf5/dnf5-plugins"};
for (const auto & pth : 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 (user_defined_config_file_name || std::filesystem::exists(conf_file_path)) {
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());
if (std::filesystem::exists(conf_file_path)) {
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());
break;
}
}

context.set_output_stream(output_stream);
Expand Down
102 changes: 0 additions & 102 deletions dnf5-plugins/automatic_plugin/config/etc/dnf/automatic.conf

This file was deleted.

2 changes: 0 additions & 2 deletions dnf5-plugins/automatic_plugin/config_automatic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ class ConfigAutomatic {
libdnf5::Logger & logger,
libdnf5::Option::Priority priority = libdnf5::Option::Priority::AUTOMATICCONFIG);

libdnf5::OptionString automatic_config_file_path{"/etc/dnf/automatic.conf"};

ConfigAutomaticCommands config_commands;
ConfigAutomaticEmitters config_emitters;
ConfigAutomaticEmail config_email;
Expand Down
3 changes: 2 additions & 1 deletion dnf5.spec
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ It supports RPM packages, modulemd modules, and comps groups & environments.
%config %{_datadir}/dnf5/aliases.d/compatibility.conf
%dir %{_libdir}/dnf5
%dir %{_libdir}/dnf5/plugins
%dir %{_datadir}/dnf5/dnf5-plugins
%dir %{_sysconfdir}/dnf/dnf5-plugins
%doc %{_libdir}/dnf5/plugins/README
%dir %{_libdir}/libdnf5/plugins
%dir %{_datadir}/bash-completion/
Expand Down Expand Up @@ -702,7 +704,6 @@ automatically and regularly from systemd timers, cron jobs or similar.

%files plugin-automatic -f dnf5-plugin-automatic.lang
%ghost %{_sysconfdir}/motd.d/dnf5-automatic
%config(noreplace) %{_sysconfdir}/dnf/automatic.conf
%{_libdir}/dnf5/plugins/automatic_cmd_plugin.so
%{_unitdir}/dnf-automatic-download.service
%{_unitdir}/dnf-automatic-download.timer
Expand Down
5 changes: 5 additions & 0 deletions dnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ install(FILES "README.plugins" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/pl
install(DIRECTORY "config/usr/" DESTINATION "${CMAKE_INSTALL_PREFIX}" PATTERN ".gitkeep" EXCLUDE)
install(DIRECTORY "config/etc/" DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}" PATTERN ".gitkeep" EXCLUDE)

# Makes an empty directory for dnf5-plugins configuration files
install(DIRECTORY DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}/dnf/dnf5-plugins")
# Makes an empty directory for distribution dnf5-plugins configuration files
install(DIRECTORY DESTINATION "${CMAKE_INSTALL_PREFIX}/share/dnf5/dnf5-plugins")


add_subdirectory(po)
add_subdirectory("include")
10 changes: 2 additions & 8 deletions doc/dnf5_plugins/automatic.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Synopsis
==========

``dnf5 automatic [options] [<config file>]``
``dnf5 automatic [options]``


Options
Expand All @@ -47,12 +47,6 @@ Options
Do not automatically install downloaded updates.


Arguments
=========

``<config file>``
Path to configuration file. Defaults to ``/etc/dnf/automatic.conf``.


Description
=============
Expand Down Expand Up @@ -97,7 +91,7 @@ Setting the mode of operation of the program.
Whether packages comprising the available updates should be applied by ``dnf-automatic.timer``, i.e. installed via RPM. Implies ``download_updates``. Note that if this is set to ``False``, downloaded packages will be left in the cache till the next successful DNF transaction. Note that the other timer units override this setting.

``download_updates``
boolean, default: False
boolean, default: True

Whether packages comprising the available updates should be downloaded by ``dnf-automatic.timer``. Note that the other timer units override this setting.

Expand Down

0 comments on commit 5b93250

Please sign in to comment.