mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 14:32:22 +08:00
🧹 gucc: refactor to use utils::exec_checked
This commit is contained in:
parent
1492d40efe
commit
066a05a934
@ -37,7 +37,7 @@ auto btrfs_create_subvol(std::string_view subvolume, std::string_view root_mount
|
||||
return false;
|
||||
}
|
||||
auto cmd = fmt::format(FMT_COMPILE("btrfs subvolume create {}{} 2>>/tmp/cachyos-install.log"), root_mountpoint, subvolume);
|
||||
return utils::exec(cmd, true) == "0";
|
||||
return utils::exec_checked(cmd);
|
||||
}
|
||||
|
||||
auto btrfs_create_subvols(const std::vector<BtrfsSubvolume>& subvols, std::string_view device, std::string_view root_mountpoint, std::string_view mount_opts) noexcept -> bool {
|
||||
|
@ -109,7 +109,7 @@ auto arch_chroot_checked(std::string_view command, std::string_view mountpoint)
|
||||
const auto& cmd_formatted = fmt::format(FMT_COMPILE("arch-chroot {} {} 2>>/tmp/cachyos-install.log 1>/dev/null"), mountpoint, command);
|
||||
|
||||
#ifdef NDEVENV
|
||||
return utils::exec(cmd_formatted, true) == "0"sv;
|
||||
return utils::exec_checked(cmd_formatted);
|
||||
#else
|
||||
spdlog::info("Running with checked arch-chroot: '{}'", cmd_formatted);
|
||||
return true;
|
||||
|
@ -12,17 +12,17 @@ namespace gucc::crypto {
|
||||
|
||||
auto luks1_open(std::string_view luks_pass, std::string_view partition, std::string_view luks_name) noexcept -> bool {
|
||||
auto cmd = fmt::format(FMT_COMPILE("echo \"{}\" | cryptsetup open --type luks1 {} {} &>/dev/null"), luks_pass, partition, luks_name);
|
||||
return utils::exec(cmd, true) == "0";
|
||||
return utils::exec_checked(cmd);
|
||||
}
|
||||
|
||||
auto luks1_format(std::string_view luks_pass, std::string_view partition, std::string_view additional_flags) noexcept -> bool {
|
||||
auto cmd = fmt::format(FMT_COMPILE("echo \"{}\" | cryptsetup -q {} --type luks1 luksFormat {} &>/dev/null"), luks_pass, additional_flags, partition);
|
||||
return utils::exec(cmd, true) == "0";
|
||||
return utils::exec_checked(cmd);
|
||||
}
|
||||
|
||||
auto luks1_add_key(std::string_view dest_file, std::string_view partition, std::string_view additional_flags) noexcept -> bool {
|
||||
auto cmd = fmt::format(FMT_COMPILE("cryptsetup -q {} luksAddKey {} {} &>/dev/null"), additional_flags, partition, dest_file);
|
||||
return utils::exec(cmd, true) == "0";
|
||||
return utils::exec_checked(cmd);
|
||||
}
|
||||
|
||||
// see https://wiki.archlinux.org/title/Dm-crypt/Device_encryption#With_a_keyfile_embedded_in_the_initramfs
|
||||
|
@ -11,21 +11,21 @@ namespace gucc::mount {
|
||||
|
||||
auto mount_partition(std::string_view partition, std::string_view mount_dir, std::string_view mount_opts) noexcept -> bool {
|
||||
if (!mount_opts.empty()) {
|
||||
return utils::exec(fmt::format(FMT_COMPILE("mount -o {} {} {}"), mount_opts, partition, mount_dir)) == "0";
|
||||
return utils::exec_checked(fmt::format(FMT_COMPILE("mount -o {} {} {}"), mount_opts, partition, mount_dir));
|
||||
}
|
||||
return utils::exec(fmt::format(FMT_COMPILE("mount {} {}"), partition, mount_dir)) == "0";
|
||||
return utils::exec_checked(fmt::format(FMT_COMPILE("mount {} {}"), partition, mount_dir));
|
||||
}
|
||||
|
||||
auto query_partition(std::string_view partition, std::int32_t& is_luks, std::int32_t& is_lvm, std::string& luks_name, std::string& luks_dev, std::string& luks_uuid) noexcept -> bool {
|
||||
// Identify if mounted partition is type "crypt" (LUKS on LVM, or LUKS alone)
|
||||
if (utils::exec(fmt::format(FMT_COMPILE("lsblk -lno TYPE {} | grep -q 'crypt'"), partition), true) == "0") {
|
||||
if (utils::exec_checked(fmt::format(FMT_COMPILE("lsblk -lno TYPE {} | grep -q 'crypt'"), partition))) {
|
||||
// cryptname for bootloader configuration either way
|
||||
is_luks = true;
|
||||
luks_name = utils::exec(fmt::format(FMT_COMPILE("echo {} | sed \"s~^/dev/mapper/~~g\""), partition));
|
||||
|
||||
const auto& check_cryptparts = [&](auto&& cryptparts, const auto& functor) {
|
||||
for (const auto& cryptpart : cryptparts) {
|
||||
if (utils::exec(fmt::format(FMT_COMPILE("lsblk -lno NAME {} | grep -q '{}'"), cryptpart, luks_name)) == "0") {
|
||||
if (utils::exec_checked(fmt::format(FMT_COMPILE("lsblk -lno NAME {} | grep -q '{}'"), cryptpart, luks_name))) {
|
||||
functor(cryptpart);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user