🧹 move generic arch-chroot into gucc

This commit is contained in:
Vladislav Nepogodin 2024-06-27 00:23:09 +04:00
parent 0dec883c88
commit 062323223e
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
3 changed files with 22 additions and 13 deletions

View File

@ -10,6 +10,7 @@ namespace gucc::utils {
auto safe_getenv(const char* env_name) noexcept -> std::string_view;
void exec(const std::vector<std::string>& 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

View File

@ -10,6 +10,7 @@
#include <algorithm> // for transform
#include <fstream> // for ofstream
#include <fmt/compile.h>
#include <fmt/ranges.h>
#include <spdlog/spdlog.h>
@ -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

View File

@ -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<std::string>(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<std::int32_t>(config_data["HEADLESS_MODE"]);
#ifdef NDEVENV
if (follow) {
const auto& headless_mode = std::get<std::int32_t>(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;
const bool follow_headless = follow && headless_mode;
if (!follow || follow_headless) {
gucc::utils::arch_chroot(command, mountpoint, follow_headless);
}
#ifdef NDEVENV
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
}