🧹 tui: refactor to use utils::exec_checked

This commit is contained in:
Vladislav Nepogodin 2024-07-14 02:25:23 +04:00
parent 01dc814f98
commit 66890213bd
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9

View File

@ -445,8 +445,7 @@ void install_grub_uefi() noexcept {
/* clang-format on */ /* clang-format on */
std::string bootid{"cachyos"}; std::string bootid{"cachyos"};
auto ret_status = gucc::utils::exec("efibootmgr | cut -d\\ -f2 | grep -q -o cachyos", true); if (gucc::utils::exec_checked("efibootmgr | cut -d\\ -f2 | grep -q -o cachyos")) {
if (ret_status == "0"sv) {
static constexpr auto bootid_content = "\nInput the name identify your grub installation. Choosing an existing name overwrites it.\n"sv; static constexpr auto bootid_content = "\nInput the name identify your grub installation. Choosing an existing name overwrites it.\n"sv;
if (!detail::inputbox_widget(bootid, bootid_content, size(ftxui::HEIGHT, ftxui::LESS_THAN, 9) | size(ftxui::WIDTH, ftxui::LESS_THAN, 30))) { if (!detail::inputbox_widget(bootid, bootid_content, size(ftxui::HEIGHT, ftxui::LESS_THAN, 9) | size(ftxui::WIDTH, ftxui::LESS_THAN, 30))) {
return; return;
@ -573,12 +572,10 @@ void install_base() noexcept {
auto screen = ScreenInteractive::Fullscreen(); auto screen = ScreenInteractive::Fullscreen();
std::string packages{}; std::string packages{};
auto ok_callback = [&] { auto ok_callback = [&] {
packages = detail::from_checklist_string(available_kernels, kernels_state.get()); packages = detail::from_checklist_string(available_kernels, kernels_state.get());
auto ret_status = gucc::utils::exec(fmt::format(FMT_COMPILE("echo '{}' | grep -q 'linux'"), packages), true); if (!gucc::utils::exec_checked(fmt::format(FMT_COMPILE("echo '{}' | grep -q 'linux'"), packages))) {
if (ret_status != "0"sv) {
// Check if a kernel is already installed // Check if a kernel is already installed
ret_status = gucc::utils::exec(fmt::format(FMT_COMPILE("ls {}/boot/*.img >/dev/null 2>&1"), mountpoint), true); if (!gucc::utils::exec_checked(fmt::format(FMT_COMPILE("ls {}/boot/*.img >/dev/null 2>&1"), mountpoint))) {
if (ret_status != "0"sv) {
static constexpr auto ErrNoKernel = "\nAt least one kernel must be selected.\n"sv; static constexpr auto ErrNoKernel = "\nAt least one kernel must be selected.\n"sv;
detail::msgbox_widget(ErrNoKernel); detail::msgbox_widget(ErrNoKernel);
return; return;
@ -1056,7 +1053,7 @@ void make_swap() noexcept {
return; return;
} }
while (gucc::utils::exec(fmt::format(FMT_COMPILE("echo '{}' | grep 'M\\|G'"), value)).empty()) { while (!gucc::utils::exec_checked(fmt::format(FMT_COMPILE("echo '{}' | grep -q 'M\\|G'")))) {
detail::msgbox_widget(fmt::format(FMT_COMPILE("\n{} Error: M = MB, G = GB\n"), sel_swap_file)); detail::msgbox_widget(fmt::format(FMT_COMPILE("\n{} Error: M = MB, G = GB\n"), sel_swap_file));
value = fmt::format(FMT_COMPILE("{}M"), total_memory); value = fmt::format(FMT_COMPILE("{}M"), total_memory);
if (!detail::inputbox_widget(value, "\nM = MB, G = GB\n", size(ftxui::HEIGHT, ftxui::LESS_THAN, 9) | size(ftxui::WIDTH, ftxui::LESS_THAN, 30))) { if (!detail::inputbox_widget(value, "\nM = MB, G = GB\n", size(ftxui::HEIGHT, ftxui::LESS_THAN, 9) | size(ftxui::WIDTH, ftxui::LESS_THAN, 30))) {
@ -1557,7 +1554,7 @@ void zfs_menu_manual() noexcept {
void zfs_menu() noexcept { void zfs_menu() noexcept {
#ifdef NDEVENV #ifdef NDEVENV
// check for zfs support // check for zfs support
if (gucc::utils::exec("modprobe zfs 2>>/tmp/cachyos-install.log &>/dev/null", true) != "0"sv) { if (!gucc::utils::exec_checked("modprobe zfs 2>>/tmp/cachyos-install.log &>/dev/null")) {
detail::infobox_widget("\nThe kernel modules to support ZFS could not be found\n"sv); detail::infobox_widget("\nThe kernel modules to support ZFS could not be found\n"sv);
std::this_thread::sleep_for(std::chrono::seconds(3)); std::this_thread::sleep_for(std::chrono::seconds(3));
return; return;
@ -1876,7 +1873,7 @@ void mount_partitions() noexcept {
config_data["LVM_SEP_BOOT"] = 1; config_data["LVM_SEP_BOOT"] = 1;
const auto& cmd = fmt::format(FMT_COMPILE("lsblk -lno TYPE {} | grep -q 'lvm'"), partition); const auto& cmd = fmt::format(FMT_COMPILE("lsblk -lno TYPE {} | grep -q 'lvm'"), partition);
const bool is_boot_lvm = gucc::utils::exec(cmd, true) == "0"sv; const bool is_boot_lvm = gucc::utils::exec_checked(cmd);
if (is_boot_lvm) { if (is_boot_lvm) {
config_data["LVM_SEP_BOOT"] = 2; config_data["LVM_SEP_BOOT"] = 2;
} }