mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-02-02 22:07:13 +08:00
👷 cache information about partition scheme
This commit is contained in:
parent
1ca45defa7
commit
c322aba3ff
@ -28,6 +28,7 @@
|
|||||||
#include <fmt/ranges.h>
|
#include <fmt/ranges.h>
|
||||||
|
|
||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
|
using namespace std::string_literals;
|
||||||
using namespace std::string_view_literals;
|
using namespace std::string_view_literals;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -156,6 +157,8 @@ auto make_partitions_prepared(std::string_view bootloader, std::string_view root
|
|||||||
if (ready_parts.empty()) { spdlog::error("Invalid use! ready parts empty."); return false; }
|
if (ready_parts.empty()) { spdlog::error("Invalid use! ready parts empty."); return false; }
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
|
const auto& mountpoint_info = std::get<std::string>(config_data["MOUNTPOINT"]);
|
||||||
|
|
||||||
std::vector<gucc::fs::Partition> partitions{};
|
std::vector<gucc::fs::Partition> partitions{};
|
||||||
|
|
||||||
std::string root_part{};
|
std::string root_part{};
|
||||||
@ -178,6 +181,10 @@ auto make_partitions_prepared(std::string_view bootloader, std::string_view root
|
|||||||
utils::get_cryptroot();
|
utils::get_cryptroot();
|
||||||
utils::get_cryptboot();
|
utils::get_cryptboot();
|
||||||
spdlog::info("boot partition: name={}", part_name);
|
spdlog::info("boot partition: name={}", part_name);
|
||||||
|
|
||||||
|
// TODO(vnepogodin): handle boot partition mount options
|
||||||
|
auto part_struct = gucc::fs::Partition{.fstype = part_fs, .mountpoint = part_mountpoint, .device = part_name, .mount_opts = "defaults"s};
|
||||||
|
partitions.emplace_back(std::move(part_struct));
|
||||||
continue;
|
continue;
|
||||||
} else if (part_type == "root"sv) {
|
} else if (part_type == "root"sv) {
|
||||||
config_data["PARTITION"] = part_name;
|
config_data["PARTITION"] = part_name;
|
||||||
@ -192,7 +199,8 @@ auto make_partitions_prepared(std::string_view bootloader, std::string_view root
|
|||||||
// If the root partition is btrfs, offer to create subvolumes
|
// If the root partition is btrfs, offer to create subvolumes
|
||||||
if (root_fs == "btrfs"sv) {
|
if (root_fs == "btrfs"sv) {
|
||||||
// Check if there are subvolumes already on the btrfs partition
|
// Check if there are subvolumes already on the btrfs partition
|
||||||
const auto& subvolumes = fmt::format(FMT_COMPILE("btrfs subvolume list \"{}\" 2>/dev/null"), part_mountpoint);
|
const auto& mount_dir = fmt::format(FMT_COMPILE("{}{}"), mountpoint_info, part_mountpoint);
|
||||||
|
const auto& subvolumes = fmt::format(FMT_COMPILE("btrfs subvolume list \"{}\" 2>/dev/null"), mount_dir);
|
||||||
const auto& subvolumes_count = gucc::utils::exec(fmt::format(FMT_COMPILE("{} | wc -l"), subvolumes));
|
const auto& subvolumes_count = gucc::utils::exec(fmt::format(FMT_COMPILE("{} | wc -l"), subvolumes));
|
||||||
const auto& lines_count = utils::to_int(subvolumes_count);
|
const auto& lines_count = utils::to_int(subvolumes_count);
|
||||||
|
|
||||||
@ -214,6 +222,9 @@ auto make_partitions_prepared(std::string_view bootloader, std::string_view root
|
|||||||
utils::select_filesystem(part_fs);
|
utils::select_filesystem(part_fs);
|
||||||
tui::mount_current_partition(true);
|
tui::mount_current_partition(true);
|
||||||
|
|
||||||
|
auto part_struct = gucc::fs::Partition{.fstype = part_fs, .mountpoint = part_mountpoint, .device = part_name, .mount_opts = std::string{mount_opts_info}};
|
||||||
|
partitions.emplace_back(std::move(part_struct));
|
||||||
|
|
||||||
// Determine if a separate /boot is used.
|
// Determine if a separate /boot is used.
|
||||||
// 0 = no separate boot,
|
// 0 = no separate boot,
|
||||||
// 1 = separate non-lvm boot,
|
// 1 = separate non-lvm boot,
|
||||||
|
35
src/tui.cpp
35
src/tui.cpp
@ -86,7 +86,7 @@ bool exit_done() noexcept {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void btrfs_subvolumes() noexcept {
|
void btrfs_subvolumes(std::vector<gucc::fs::Partition>& partitions) noexcept {
|
||||||
const std::vector<std::string> menu_entries = {
|
const std::vector<std::string> menu_entries = {
|
||||||
"automatic",
|
"automatic",
|
||||||
"manual",
|
"manual",
|
||||||
@ -105,16 +105,6 @@ void btrfs_subvolumes() noexcept {
|
|||||||
if (btrfsvols_mode.empty()) { return; }
|
if (btrfsvols_mode.empty()) { return; }
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
auto* config_instance = Config::instance();
|
|
||||||
auto& config_data = config_instance->data();
|
|
||||||
|
|
||||||
const auto& mount_opts_info = std::get<std::string>(config_data["MOUNT_OPTS"]);
|
|
||||||
const auto& root_part = std::get<std::string>(config_data["ROOT_PART"]);
|
|
||||||
|
|
||||||
std::vector<gucc::fs::Partition> partitions{
|
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .device = root_part, .mount_opts = mount_opts_info},
|
|
||||||
};
|
|
||||||
|
|
||||||
utils::btrfs_create_subvols(partitions, btrfsvols_mode);
|
utils::btrfs_create_subvols(partitions, btrfsvols_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1730,10 +1720,10 @@ void mount_partitions() noexcept {
|
|||||||
auto screen = ScreenInteractive::Fullscreen();
|
auto screen = ScreenInteractive::Fullscreen();
|
||||||
std::int32_t selected{};
|
std::int32_t selected{};
|
||||||
bool success{};
|
bool success{};
|
||||||
const auto& partitions = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
const auto& partitions_lines = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
||||||
|
|
||||||
auto ok_callback = [&] {
|
auto ok_callback = [&] {
|
||||||
const auto& src = partitions[static_cast<std::size_t>(selected)];
|
const auto& src = partitions_lines[static_cast<std::size_t>(selected)];
|
||||||
const auto& lines = gucc::utils::make_multiline(src, false, ' ');
|
const auto& lines = gucc::utils::make_multiline(src, false, ' ');
|
||||||
config_data["PARTITION"] = lines[0];
|
config_data["PARTITION"] = lines[0];
|
||||||
config_data["ROOT_PART"] = lines[0];
|
config_data["ROOT_PART"] = lines[0];
|
||||||
@ -1742,7 +1732,7 @@ void mount_partitions() noexcept {
|
|||||||
};
|
};
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
static constexpr auto sel_root_body = "\nSelect ROOT Partition.\nThis is where CachyOS will be installed.\n"sv;
|
static constexpr auto sel_root_body = "\nSelect ROOT Partition.\nThis is where CachyOS will be installed.\n"sv;
|
||||||
detail::menu_widget(partitions, ok_callback, &selected, &screen, sel_root_body, {.text_size = size(HEIGHT, GREATER_THAN, 1)});
|
detail::menu_widget(partitions_lines, ok_callback, &selected, &screen, sel_root_body, {.text_size = size(HEIGHT, GREATER_THAN, 1)});
|
||||||
if (!success) { return; }
|
if (!success) { return; }
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
}
|
}
|
||||||
@ -1791,7 +1781,7 @@ void mount_partitions() noexcept {
|
|||||||
const auto& create_subvolumes = detail::yesno_widget("\nWould you like to create subvolumes in it? \n", size(HEIGHT, LESS_THAN, 15) | size(WIDTH, LESS_THAN, 75));
|
const auto& create_subvolumes = detail::yesno_widget("\nWould you like to create subvolumes in it? \n", size(HEIGHT, LESS_THAN, 15) | size(WIDTH, LESS_THAN, 75));
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
if (create_subvolumes) {
|
if (create_subvolumes) {
|
||||||
tui::btrfs_subvolumes();
|
tui::btrfs_subvolumes(partitions);
|
||||||
}
|
}
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
}
|
}
|
||||||
@ -1825,10 +1815,10 @@ void mount_partitions() noexcept {
|
|||||||
const auto& partition = std::get<std::string>(config_data["PARTITION"]);
|
const auto& partition = std::get<std::string>(config_data["PARTITION"]);
|
||||||
while (number_partitions > 0) {
|
while (number_partitions > 0) {
|
||||||
{
|
{
|
||||||
const auto& partitions = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
const auto& partitions_lines = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
||||||
std::vector<std::string> temp{"Done -"};
|
std::vector<std::string> temp{"Done -"};
|
||||||
temp.reserve(partitions.size());
|
temp.reserve(partitions_lines.size());
|
||||||
std::copy(partitions.begin(), partitions.end(), std::back_inserter(temp));
|
std::copy(partitions_lines.begin(), partitions_lines.end(), std::back_inserter(temp));
|
||||||
|
|
||||||
auto screen = ScreenInteractive::Fullscreen();
|
auto screen = ScreenInteractive::Fullscreen();
|
||||||
std::int32_t selected{};
|
std::int32_t selected{};
|
||||||
@ -1883,6 +1873,15 @@ void mount_partitions() noexcept {
|
|||||||
tui::mount_current_partition();
|
tui::mount_current_partition();
|
||||||
// utils::delete_partition_in_list(partition);
|
// utils::delete_partition_in_list(partition);
|
||||||
|
|
||||||
|
// TODO(vnepogodin): parse luks information
|
||||||
|
const auto& mount_opts_info = std::get<std::string>(config_data["MOUNT_OPTS"]);
|
||||||
|
|
||||||
|
const auto& part_fs = gucc::fs::utils::get_mountpoint_fs(mountpoint_info);
|
||||||
|
auto part_struct = gucc::fs::Partition{.fstype = part_fs, .mountpoint = mount_dev, .device = partition, .mount_opts = mount_opts_info};
|
||||||
|
|
||||||
|
// insert root partition
|
||||||
|
partitions.emplace_back(std::move(part_struct));
|
||||||
|
|
||||||
// Determine if a separate /boot is used.
|
// Determine if a separate /boot is used.
|
||||||
// 0 = no separate boot,
|
// 0 = no separate boot,
|
||||||
// 1 = separate non-lvm boot,
|
// 1 = separate non-lvm boot,
|
||||||
|
Loading…
Reference in New Issue
Block a user