mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 14:32:22 +08:00
🧹 move fs/mountpoint utils into gucc
This commit is contained in:
parent
61317a83a3
commit
aba9a8d488
@ -13,6 +13,7 @@ add_library(${PROJECT_NAME} SHARED
|
||||
src/io_utils.cpp include/gucc/io_utils.hpp
|
||||
src/string_utils.cpp include/gucc/string_utils.hpp
|
||||
src/file_utils.cpp include/gucc/file_utils.hpp
|
||||
src/fs_utils.cpp include/gucc/fs_utils.hpp
|
||||
src/cpu.cpp include/gucc/cpu.hpp
|
||||
src/pacmanconf_repo.cpp include/gucc/pacmanconf_repo.hpp
|
||||
src/initcpio.cpp include/gucc/initcpio.hpp
|
||||
|
17
gucc/include/gucc/fs_utils.hpp
Normal file
17
gucc/include/gucc/fs_utils.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef FS_UTILS_HPP
|
||||
#define FS_UTILS_HPP
|
||||
|
||||
#include <string> // for string
|
||||
#include <string_view> // for string_view
|
||||
|
||||
namespace gucc::fs::utils {
|
||||
|
||||
// Get FSTYPE of mountpoint
|
||||
auto get_mountpoint_fs(std::string_view mountpoint) noexcept -> std::string;
|
||||
|
||||
// Get SOURCE of mountpoint
|
||||
auto get_mountpoint_source(std::string_view mountpoint) noexcept -> std::string;
|
||||
|
||||
} // namespace gucc::fs::utils
|
||||
|
||||
#endif // FS_UTILS_HPP
|
@ -3,6 +3,7 @@ gucc_lib = library('gucc',
|
||||
'src/io_utils.cpp',
|
||||
'src/file_utils.cpp',
|
||||
'src/string_utils.cpp',
|
||||
'src/fs_utils.cpp',
|
||||
'src/cpu.cpp',
|
||||
'src/pacmanconf_repo.cpp',
|
||||
'src/initcpio.cpp',
|
||||
|
19
gucc/src/fs_utils.cpp
Normal file
19
gucc/src/fs_utils.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "gucc/fs_utils.hpp"
|
||||
#include "gucc/io_utils.hpp"
|
||||
|
||||
#include <fmt/compile.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace gucc::fs::utils {
|
||||
|
||||
auto get_mountpoint_fs(std::string_view mountpoint) noexcept -> std::string {
|
||||
return gucc::utils::exec(fmt::format(FMT_COMPILE("findmnt -ln -o FSTYPE \"{}\""), mountpoint));
|
||||
}
|
||||
|
||||
auto get_mountpoint_source(std::string_view mountpoint) noexcept -> std::string {
|
||||
return gucc::utils::exec(fmt::format(FMT_COMPILE("findmnt -ln -o SOURCE \"{}\""), mountpoint));
|
||||
}
|
||||
|
||||
} // namespace gucc::fs::utils
|
@ -6,6 +6,7 @@
|
||||
#include "widgets.hpp"
|
||||
|
||||
// import gucc
|
||||
#include "gucc/fs_utils.hpp"
|
||||
#include "gucc/io_utils.hpp"
|
||||
#include "gucc/string_utils.hpp"
|
||||
#include "gucc/zfs.hpp"
|
||||
@ -387,7 +388,7 @@ void menu_simple() noexcept {
|
||||
}
|
||||
|
||||
// If the root partition is btrfs, offer to create subvolumes
|
||||
/*if (utils::get_mountpoint_fs(mountpoint) == "btrfs") {
|
||||
/*if (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "btrfs") {
|
||||
// Check if there are subvolumes already on the btrfs partition
|
||||
const auto& subvolumes = fmt::format(FMT_COMPILE("btrfs subvolume list \"{}\" 2>/dev/null"), mountpoint);
|
||||
const auto& subvolumes_count = gucc::utils::exec(fmt::format(FMT_COMPILE("{} | wc -l"), subvolumes));
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "widgets.hpp"
|
||||
|
||||
// import gucc
|
||||
#include "gucc/fs_utils.hpp"
|
||||
#include "gucc/io_utils.hpp"
|
||||
#include "gucc/string_utils.hpp"
|
||||
#include "gucc/zfs.hpp"
|
||||
@ -1157,7 +1158,7 @@ void make_swap() noexcept {
|
||||
std::string answer{};
|
||||
{
|
||||
std::vector<std::string> temp{"None -"};
|
||||
const auto& root_filesystem = utils::get_mountpoint_fs(mountpoint_info);
|
||||
const auto& root_filesystem = gucc::fs::utils::get_mountpoint_fs(mountpoint_info);
|
||||
if (!(root_filesystem == "zfs" || root_filesystem == "btrfs")) {
|
||||
temp.emplace_back("Swapfile -");
|
||||
}
|
||||
@ -1851,7 +1852,7 @@ void mount_partitions() noexcept {
|
||||
|
||||
// check to see if we already have a zfs root mounted
|
||||
const auto& mountpoint_info = std::get<std::string>(config_data["MOUNTPOINT"]);
|
||||
if (utils::get_mountpoint_fs(mountpoint_info) == "zfs"sv) {
|
||||
if (gucc::fs::utils::get_mountpoint_fs(mountpoint_info) == "zfs"sv) {
|
||||
detail::infobox_widget("\nUsing ZFS root on \'/\'\n"sv);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
} else {
|
||||
@ -1895,7 +1896,7 @@ void mount_partitions() noexcept {
|
||||
// get_cryptroot
|
||||
// echo "$LUKS_DEV" > /tmp/.luks_dev
|
||||
// If the root partition is btrfs, offer to create subvolumes
|
||||
if (utils::get_mountpoint_fs(mountpoint_info) == "btrfs") {
|
||||
if (gucc::fs::utils::get_mountpoint_fs(mountpoint_info) == "btrfs") {
|
||||
// Check if there are subvolumes already on the btrfs partition
|
||||
const auto& subvolumes = fmt::format(FMT_COMPILE("btrfs subvolume list \"{}\" 2>/dev/null"), mountpoint_info);
|
||||
const auto& subvolumes_count = gucc::utils::exec(fmt::format(FMT_COMPILE("{} | wc -l"), subvolumes));
|
||||
|
@ -8,6 +8,7 @@
|
||||
// import gucc
|
||||
#include "gucc/cpu.hpp"
|
||||
#include "gucc/file_utils.hpp"
|
||||
#include "gucc/fs_utils.hpp"
|
||||
#include "gucc/initcpio.hpp"
|
||||
#include "gucc/io_utils.hpp"
|
||||
#include "gucc/locale.hpp"
|
||||
@ -573,7 +574,7 @@ auto get_pkglist_base(const std::string_view& packages) noexcept -> std::vector<
|
||||
const auto& server_mode = std::get<std::int32_t>(config_data["SERVER_MODE"]);
|
||||
const auto& mountpoint_info = std::get<std::string>(config_data["MOUNTPOINT"]);
|
||||
|
||||
const auto& root_filesystem = utils::get_mountpoint_fs(mountpoint_info);
|
||||
const auto& root_filesystem = gucc::fs::utils::get_mountpoint_fs(mountpoint_info);
|
||||
const auto& is_root_on_zfs = (root_filesystem == "zfs");
|
||||
const auto& is_root_on_btrfs = (root_filesystem == "btrfs");
|
||||
const auto& is_root_on_bcachefs = (root_filesystem == "bcachefs");
|
||||
@ -853,7 +854,7 @@ void install_base(const std::string_view& packages) noexcept {
|
||||
std::int32_t btrfs_root = 0;
|
||||
std::int32_t zfs_root = 0;
|
||||
|
||||
const auto& filesystem_type = utils::get_mountpoint_fs(mountpoint);
|
||||
const auto& filesystem_type = gucc::fs::utils::get_mountpoint_fs(mountpoint);
|
||||
spdlog::info("filesystem type on '{}' := '{}'", mountpoint, filesystem_type);
|
||||
if (filesystem_type == "btrfs") {
|
||||
btrfs_root = 1;
|
||||
@ -966,7 +967,7 @@ void install_grub_uefi(const std::string_view& bootid, bool as_default) noexcept
|
||||
const auto& grub_installer_path = fmt::format(FMT_COMPILE("{}/usr/bin/grub_installer.sh"), mountpoint);
|
||||
|
||||
// grub config changes for zfs root
|
||||
if (utils::get_mountpoint_fs(mountpoint) == "zfs") {
|
||||
if (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "zfs") {
|
||||
// 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));
|
||||
setenv("ZPOOL_VDEV_NAME_PATH", "YES", 1);
|
||||
@ -979,7 +980,7 @@ pacman -S --noconfirm --needed grub efibootmgr dosfstools
|
||||
sed -e '/GRUB_SAVEDEFAULT/ s/^#*/#/' -i /etc/default/grub
|
||||
# we need to tell grub where the zfs root is)";
|
||||
|
||||
const auto& mountpoint_source = utils::get_mountpoint_source(mountpoint);
|
||||
const auto& mountpoint_source = gucc::fs::utils::get_mountpoint_source(mountpoint);
|
||||
const auto& zroot_var = fmt::format(FMT_COMPILE("zroot=\"zfs={} rw\""), mountpoint_source);
|
||||
|
||||
constexpr auto bash_codepart2 = R"(
|
||||
@ -1229,7 +1230,7 @@ void bios_bootloader(const std::string_view& bootloader) noexcept {
|
||||
}
|
||||
|
||||
// If root is on btrfs volume, amend grub
|
||||
if (utils::get_mountpoint_fs(mountpoint) == "btrfs") {
|
||||
if (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "btrfs") {
|
||||
gucc::utils::exec(fmt::format(FMT_COMPILE("sed -e '/GRUB_SAVEDEFAULT/ s/^#*/#/' -i {}/etc/default/grub"), mountpoint));
|
||||
}
|
||||
|
||||
@ -1241,7 +1242,7 @@ 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 (utils::get_mountpoint_fs(mountpoint) == "zfs") {
|
||||
if (gucc::fs::utils::get_mountpoint_fs(mountpoint) == "zfs") {
|
||||
// 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));
|
||||
setenv("ZPOOL_VDEV_NAME_PATH", "YES", 1);
|
||||
@ -1254,7 +1255,7 @@ pacman -S --noconfirm --needed grub os-prober
|
||||
sed -e '/GRUB_SAVEDEFAULT/ s/^#*/#/' -i /etc/default/grub
|
||||
# we need to tell grub where the zfs root is)";
|
||||
|
||||
const auto& mountpoint_source = utils::get_mountpoint_source(mountpoint);
|
||||
const auto& mountpoint_source = gucc::fs::utils::get_mountpoint_source(mountpoint);
|
||||
const auto& zroot_var = fmt::format(FMT_COMPILE("zroot=\"zfs={} rw\""), mountpoint_source);
|
||||
|
||||
constexpr auto bash_codepart2 = R"(
|
||||
@ -1351,14 +1352,6 @@ std::string list_mounted() noexcept {
|
||||
return gucc::utils::exec("echo /dev/* /dev/mapper/* | xargs -n1 2>/dev/null | grep -f /tmp/.mounted");
|
||||
}
|
||||
|
||||
std::string get_mountpoint_fs(const std::string_view& mountpoint) noexcept {
|
||||
return gucc::utils::exec(fmt::format(FMT_COMPILE("findmnt -ln -o FSTYPE \"{}\""), mountpoint));
|
||||
}
|
||||
|
||||
std::string get_mountpoint_source(const std::string_view& mountpoint) noexcept {
|
||||
return gucc::utils::exec(fmt::format(FMT_COMPILE("findmnt -ln -o SOURCE \"{}\""), mountpoint));
|
||||
}
|
||||
|
||||
std::string list_containing_crypt() noexcept {
|
||||
return gucc::utils::exec("blkid | awk '/TYPE=\"crypto_LUKS\"/{print $1}' | sed 's/.$//'");
|
||||
}
|
||||
|
@ -31,8 +31,6 @@ void set_root_password(const std::string_view& password) noexcept;
|
||||
[[nodiscard]] bool check_mount() noexcept;
|
||||
[[nodiscard]] bool check_base() noexcept;
|
||||
[[nodiscard]] auto list_mounted() noexcept -> std::string;
|
||||
[[nodiscard]] auto get_mountpoint_fs(const std::string_view& mountpoint) noexcept -> std::string;
|
||||
[[nodiscard]] auto get_mountpoint_source(const std::string_view& mountpoint) noexcept -> std::string;
|
||||
[[nodiscard]] auto list_containing_crypt() noexcept -> std::string;
|
||||
[[nodiscard]] auto list_non_crypt() noexcept -> std::string;
|
||||
void lvm_detect(std::optional<std::function<void()>> func_callback = std::nullopt) noexcept;
|
||||
|
Loading…
Reference in New Issue
Block a user