Skip to content

Commit

Permalink
🧹 utils: refactor fs info into variable
Browse files Browse the repository at this point in the history
  • Loading branch information
vnepogodin committed Jul 28, 2024
1 parent bba741f commit bac052c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,11 @@ void install_base(const std::string_view& packages) noexcept {

const auto& filesystem_type = gucc::fs::utils::get_mountpoint_fs(mountpoint);
spdlog::info("filesystem type on '{}' := '{}'", mountpoint, filesystem_type);
if (filesystem_type == "btrfs") {
if (filesystem_type == "btrfs"sv) {
btrfs_root = 1;
initcpio.remove_hook("fsck");
initcpio.append_module("btrfs");
} else if (filesystem_type == "zfs") {
} else if (filesystem_type == "zfs"sv) {
zfs_root = 1;
initcpio.remove_hook("fsck");
initcpio.insert_hook("filesystems", "zfs");
Expand Down Expand Up @@ -956,8 +956,10 @@ void install_grub_uefi(const std::string_view& bootid, bool as_default) noexcept
grub_install_config_struct.efi_directory = uefi_mount;
grub_install_config_struct.bootloader_id = bootid;

const auto& root_part_fs = gucc::fs::utils::get_mountpoint_fs(mountpoint);

// grub config changes for zfs root
if (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "zfs") {
if (root_part_fs == "zfs"sv) {
// zfs needs ZPOOL_VDEV_NAME_PATH set to properly find the device
gucc::utils::exec(fmt::format(FMT_COMPILE("echo 'ZPOOL_VDEV_NAME_PATH=YES' >> {}/etc/environment"), mountpoint));

Expand All @@ -981,7 +983,7 @@ pacman -S --noconfirm --needed grub efibootmgr dosfstools
} else {
// we need to disable SAVEDEFAULT if either we are on LVM or BTRFS
const auto is_root_lvm = gucc::utils::exec_checked("lsblk -ino TYPE,MOUNTPOINT | grep ' /$' | grep -q lvm");
if (is_root_lvm || (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "btrfs")) {
if (is_root_lvm || (root_part_fs == "btrfs"sv)) {
grub_config_struct.savedefault = std::nullopt;
}

Expand Down Expand Up @@ -1233,14 +1235,16 @@ void bios_bootloader(const std::string_view& bootloader) noexcept {
grub_install_config_struct.is_efi = false;
grub_install_config_struct.do_recheck = true;

const auto& root_part_fs = gucc::fs::utils::get_mountpoint_fs(mountpoint);

// if /boot is LVM (whether using a seperate /boot mount or not), amend grub
if ((lvm == 1 && lvm_sep_boot == 0) || lvm_sep_boot == 2) {
grub_config_struct.preload_modules = fmt::format(FMT_COMPILE("lvm {}"), grub_config_struct.preload_modules);
grub_config_struct.savedefault = std::nullopt;
}

// If root is on btrfs volume, amend grub
if (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "btrfs") {
if (root_part_fs == "btrfs"sv) {
grub_config_struct.savedefault = std::nullopt;
}

Expand All @@ -1252,12 +1256,12 @@ void bios_bootloader(const std::string_view& bootloader) noexcept {
const auto& grub_installer_path = fmt::format(FMT_COMPILE("{}/usr/bin/grub_installer.sh"), mountpoint);

// grub config changes for zfs root
if (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "zfs") {
if (root_part_fs == "zfs"sv) {
// zfs needs ZPOOL_VDEV_NAME_PATH set to properly find the device
gucc::utils::exec(fmt::format(FMT_COMPILE("echo 'ZPOOL_VDEV_NAME_PATH=YES' >> {}/etc/environment"), mountpoint));

// zfs is considered a sparse filesystem so we can't use SAVEDEFAULT
if (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "btrfs") {
if (root_part_fs == "btrfs") {
grub_config_struct.savedefault = std::nullopt;
}

Expand All @@ -1276,7 +1280,7 @@ pacman -S --noconfirm --needed grub os-prober
} else {
// we need to disable SAVEDEFAULT if either we are on LVM or BTRFS
const auto is_root_lvm = gucc::utils::exec_checked("lsblk -ino TYPE,MOUNTPOINT | grep ' /$' | grep -q lvm");
if (is_root_lvm || (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "btrfs")) {
if (is_root_lvm || (root_part_fs == "btrfs")) {
grub_config_struct.savedefault = std::nullopt;
}

Expand Down

0 comments on commit bac052c

Please sign in to comment.