From 062323223ec0a68a74ad22470ba8b622f5823bd4 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Thu, 27 Jun 2024 00:23:09 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20move=20generic=20arch-chroot=20i?= =?UTF-8?q?nto=20gucc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gucc/include/gucc/io_utils.hpp | 1 + gucc/src/io_utils.cpp | 12 ++++++++++++ src/utils.cpp | 20 ++++++++------------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/gucc/include/gucc/io_utils.hpp b/gucc/include/gucc/io_utils.hpp index 4f73a8f..35a6348 100644 --- a/gucc/include/gucc/io_utils.hpp +++ b/gucc/include/gucc/io_utils.hpp @@ -10,6 +10,7 @@ namespace gucc::utils { auto safe_getenv(const char* env_name) noexcept -> std::string_view; void exec(const std::vector& vec) noexcept; auto exec(std::string_view command, bool interactive = false) noexcept -> std::string; +void arch_chroot(std::string_view command, std::string_view mountpoint, bool interactive = false) noexcept; } // namespace gucc::utils diff --git a/gucc/src/io_utils.cpp b/gucc/src/io_utils.cpp index 0856d75..f4f50b8 100644 --- a/gucc/src/io_utils.cpp +++ b/gucc/src/io_utils.cpp @@ -10,6 +10,7 @@ #include // for transform #include // for ofstream +#include #include #include @@ -88,4 +89,15 @@ auto exec(std::string_view command, bool interactive) noexcept -> std::string { return result; } +void arch_chroot(std::string_view command, std::string_view mountpoint, bool interactive) noexcept { + // TODO(vnepogodin): refactor to move output into variable and print into log + const auto& cmd_formatted = fmt::format(FMT_COMPILE("arch-chroot {} {} 2>>/tmp/cachyos-install.log 2>&1"), mountpoint, command); + +#ifdef NDEVENV + gucc::utils::exec(cmd_formatted, interactive); +#else + spdlog::info("Running with arch-chroot(interactive='{}'): '{}'", interactive, cmd_formatted); +#endif +} + } // namespace gucc::utils diff --git a/src/utils.cpp b/src/utils.cpp index 24d1a5f..aedaebe 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -125,21 +125,17 @@ void arch_chroot(const std::string_view& command, bool follow) noexcept { auto& config_data = config_instance->data(); const auto& mountpoint = std::get(config_data["MOUNTPOINT"]); - const auto& cmd_formatted = fmt::format(FMT_COMPILE("arch-chroot {} {} 2>>/tmp/cachyos-install.log 2>&1"), mountpoint, command); + const auto& headless_mode = std::get(config_data["HEADLESS_MODE"]); + const bool follow_headless = follow && headless_mode; + if (!follow || follow_headless) { + gucc::utils::arch_chroot(command, mountpoint, follow_headless); + } #ifdef NDEVENV - if (follow) { - const auto& headless_mode = std::get(config_data["HEADLESS_MODE"]); - if (headless_mode) { - gucc::utils::exec(cmd_formatted, true); - } else { - tui::detail::follow_process_log_widget({"/bin/sh", "-c", cmd_formatted}); - } - return; + else { + const auto& cmd_formatted = fmt::format(FMT_COMPILE("arch-chroot {} {} 2>>/tmp/cachyos-install.log 2>&1"), mountpoint, command); + tui::detail::follow_process_log_widget({"/bin/sh", "-c", cmd_formatted}); } - gucc::utils::exec(cmd_formatted); -#else - spdlog::info("Running with arch-chroot(follow='{}'): '{}'", follow, cmd_formatted); #endif }