From ff6efddf3e1cfaef8a0ac07faab1f320e29d5d63 Mon Sep 17 00:00:00 2001 From: Andre Detsch Date: Fri, 16 Aug 2024 15:31:55 -0300 Subject: [PATCH] main: Add offline support for check, pull, install and update commands Signed-off-by: Andre Detsch --- src/main.cc | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main.cc b/src/main.cc index 1006b444..f811903e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -68,16 +69,33 @@ static int status_main(LiteClient& client, const bpo::variables_map& unused) { return 0; } +static void fillUpdateSource(LocalUpdateSource& local_update_source, const std::string& src_dir) { + const boost::filesystem::path src_dir_path(src_dir); + local_update_source.tuf_repo = (src_dir_path / "tuf").string(); + local_update_source.ostree_repo = (src_dir_path / "ostree_repo").string(); + local_update_source.app_store = (src_dir_path / "apps").string(); +} + static int checkin(LiteClient& client, aklite::cli::CheckMode check_mode, const bpo::variables_map& params) { bool json_output = false; if (params.count("json") > 0) { json_output = params.at("json").as(); } + std::string src_dir; + if (params.count("src-dir") > 0) { + src_dir = params.at("src-dir").as(); + } + std::shared_ptr client_ptr{&client, [](LiteClient* /*unused*/) {}}; AkliteClientExt akclient(client_ptr, false, true); - auto status = aklite::cli::CheckIn(akclient, nullptr, check_mode, json_output); + LocalUpdateSource local_update_source; + if (!src_dir.empty()) { + fillUpdateSource(local_update_source, src_dir); + } + auto status = + aklite::cli::CheckIn(akclient, src_dir.empty() ? nullptr : &local_update_source, check_mode, json_output); return static_cast(status); } @@ -126,6 +144,15 @@ static int install(LiteClient& client, const bpo::variables_map& params, aklite: install_mode = params.at("install-mode").as(); } + LocalUpdateSource local_update_source; + std::string src_dir; + if (params.count("src-dir") > 0) { + src_dir = params.at("src-dir").as(); + } + if (!src_dir.empty()) { + fillUpdateSource(local_update_source, src_dir); + } + std::shared_ptr client_ptr{&client, [](LiteClient* /*unused*/) {}}; AkliteClientExt akclient{client_ptr, false, true}; @@ -138,8 +165,9 @@ static int install(LiteClient& client, const bpo::variables_map& params, aklite: mode = str2Mode.at(install_mode); } } - return static_cast( - aklite::cli::Install(akclient, version, target_name, mode, true, nullptr, pull_mode, check_mode)); + return static_cast(aklite::cli::Install(akclient, version, target_name, mode, true, + src_dir.empty() ? nullptr : &local_update_source, pull_mode, + check_mode)); } // CheckIn, Pull and Install @@ -158,11 +186,21 @@ static int cli_pull(LiteClient& client, const bpo::variables_map& params) { std::string target_name; get_target_id(params, version, target_name); + LocalUpdateSource local_update_source; + std::string src_dir; + if (params.count("src-dir") > 0) { + src_dir = params.at("src-dir").as(); + } + if (!src_dir.empty()) { + fillUpdateSource(local_update_source, src_dir); + } + std::shared_ptr client_ptr{&client, [](LiteClient* /*unused*/) {}}; AkliteClientExt akclient{client_ptr, false, true}; - return static_cast( - aklite::cli::Pull(akclient, version, target_name, true, nullptr, aklite::cli::CheckMode::Current)); + return static_cast(aklite::cli::Pull(akclient, version, target_name, true, + src_dir.empty() ? nullptr : &local_update_source, + aklite::cli::CheckMode::Current)); } static int cli_complete_install(LiteClient& client, const bpo::variables_map& params) { @@ -228,6 +266,7 @@ bpo::variables_map parse_options(int argc, char** argv) { #endif ("interval", bpo::value(), "Override uptane.polling_secs interval to poll for update when in daemon mode.") ("json", bpo::value(), "Output targets information as json ('check' and 'list' commands only)") + ("src-dir", bpo::value(), "Directory that contains an offline update. Enables offline mode for `check`, `pull`, `install` and `update` commands.") ("command", bpo::value(), subs.c_str()); // clang-format on