mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 14:32:22 +08:00
👷 gucc: add function to generate refind config
This commit is contained in:
parent
62aff01db7
commit
e7289af9c4
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -47,6 +47,7 @@ jobs:
|
||||
./gucc/tests/test-locale
|
||||
./gucc/tests/test-package_profiles
|
||||
./gucc/tests/test-btrfs
|
||||
./gucc/tests/test-refind_config_gen
|
||||
shell: bash
|
||||
build-cmake_withoutdev:
|
||||
name: Build with CMake (DEVENV OFF)
|
||||
@ -100,6 +101,7 @@ jobs:
|
||||
./gucc/tests/test-locale
|
||||
./gucc/tests/test-package_profiles
|
||||
./gucc/tests/test-btrfs
|
||||
./gucc/tests/test-refind_config_gen
|
||||
shell: bash
|
||||
build-meson_withoutdev:
|
||||
name: Build with Meson (DEVENV OFF)
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <optional> // for optional
|
||||
#include <string> // for string
|
||||
#include <string_view> // for string_view
|
||||
#include <vector> // for vector
|
||||
|
||||
namespace gucc::bootloader {
|
||||
|
||||
@ -77,6 +78,9 @@ auto install_grub(const GrubConfig& grub_config, const GrubInstallConfig& grub_i
|
||||
// Installs & configures systemd-boot on system
|
||||
auto install_systemd_boot(std::string_view root_mountpoint, std::string_view efi_directory, bool is_volume_removable) noexcept -> bool;
|
||||
|
||||
// Generate refind config into system
|
||||
auto gen_refind_config(const std::vector<std::string>& kernel_params) noexcept -> std::string;
|
||||
|
||||
} // namespace gucc::bootloader
|
||||
|
||||
#endif // BOOTLOADER_HPP
|
||||
|
@ -256,4 +256,14 @@ auto install_grub(const GrubConfig& grub_config, const GrubInstallConfig& grub_i
|
||||
return true;
|
||||
}
|
||||
|
||||
auto gen_refind_config(const std::vector<std::string>& kernel_params) noexcept -> std::string {
|
||||
const auto& kernel_params_str = utils::join(kernel_params, ' ');
|
||||
|
||||
std::string refind_config{};
|
||||
refind_config += fmt::format(FMT_COMPILE("\"Boot with standard options\" \"{}\"\n"), kernel_params_str);
|
||||
refind_config += fmt::format(FMT_COMPILE("\"Boot to single-user mode\" \"{}\" single\n"), kernel_params_str);
|
||||
|
||||
return refind_config;
|
||||
}
|
||||
|
||||
} // namespace gucc::bootloader
|
||||
|
@ -85,3 +85,11 @@ executable(
|
||||
link_with: [gucc_lib],
|
||||
include_directories: [include_directories('../include')],
|
||||
install: false)
|
||||
|
||||
executable(
|
||||
'test-refind_config_gen',
|
||||
files('unit-refind_config_gen.cpp'),
|
||||
dependencies: deps,
|
||||
link_with: [gucc_lib],
|
||||
include_directories: [include_directories('../include')],
|
||||
install: false)
|
||||
|
103
gucc/tests/unit-refind_config_gen.cpp
Normal file
103
gucc/tests/unit-refind_config_gen.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
#include "gucc/bootloader.hpp"
|
||||
#include "gucc/kernel_params.hpp"
|
||||
#include "gucc/logger.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <spdlog/sinks/callback_sink.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
using namespace std::string_literals;
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
static constexpr auto REFIND_CONFIG_SUBVOL_TEST = R"("Boot with standard options" "quiet splash rw rootflags=subvol=/@ root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"
|
||||
"Boot to single-user mode" "quiet splash rw rootflags=subvol=/@ root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f" single
|
||||
)"sv;
|
||||
|
||||
static constexpr auto REFIND_CONFIG_TEST = R"("Boot with standard options" "quiet splash rw root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"
|
||||
"Boot to single-user mode" "quiet splash rw root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f" single
|
||||
)"sv;
|
||||
|
||||
static constexpr auto REFIND_CONFIG_SWAP_TEST = R"("Boot with standard options" "quiet splash rw root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f resume=UUID=59848b1b-c6be-48f4-b3e1-48179ea72dec"
|
||||
"Boot to single-user mode" "quiet splash rw root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f resume=UUID=59848b1b-c6be-48f4-b3e1-48179ea72dec" single
|
||||
)"sv;
|
||||
|
||||
static constexpr auto REFIND_CONFIG_LUKS_TEST = R"("Boot with standard options" "quiet splash rw cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device root=/dev/mapper/luks_device"
|
||||
"Boot to single-user mode" "quiet splash rw cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device root=/dev/mapper/luks_device" single
|
||||
)"sv;
|
||||
|
||||
static constexpr auto REFIND_CONFIG_LUKS_SWAP_TEST = R"("Boot with standard options" "quiet splash rw cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device root=/dev/mapper/luks_device resume=/dev/mapper/luks_swap_device"
|
||||
"Boot to single-user mode" "quiet splash rw cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device root=/dev/mapper/luks_device resume=/dev/mapper/luks_swap_device" single
|
||||
)"sv;
|
||||
|
||||
static constexpr auto REFIND_CONFIG_ZFS_TEST = R"("Boot with standard options" "quiet splash rw root=ZFS=zpcachyos/ROOT root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"
|
||||
"Boot to single-user mode" "quiet splash rw root=ZFS=zpcachyos/ROOT root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f" single
|
||||
)"sv;
|
||||
|
||||
static constexpr auto REFIND_CONFIG_LUKS_SUBVOL_TEST = R"("Boot with standard options" "quiet splash rw rootflags=subvol=/@ cryptdevice=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f:luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f root=/dev/mapper/luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"
|
||||
"Boot to single-user mode" "quiet splash rw rootflags=subvol=/@ cryptdevice=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f:luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f root=/dev/mapper/luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f" single
|
||||
)"sv;
|
||||
|
||||
int main() {
|
||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||
// noop
|
||||
});
|
||||
auto logger = std::make_shared<spdlog::logger>("default", callback_sink);
|
||||
spdlog::set_default_logger(logger);
|
||||
gucc::logger::set_logger(logger);
|
||||
|
||||
// btrfs with subvolumes
|
||||
{
|
||||
const std::vector<std::string> kernel_params{
|
||||
"quiet", "splash", "rw", "rootflags=subvol=/@", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
||||
|
||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||
assert(refind_config_text == REFIND_CONFIG_SUBVOL_TEST);
|
||||
}
|
||||
// basic xfs
|
||||
{
|
||||
const std::vector<std::string> kernel_params{
|
||||
"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||
assert(refind_config_text == REFIND_CONFIG_TEST);
|
||||
}
|
||||
// swap xfs
|
||||
{
|
||||
const std::vector<std::string> kernel_params{
|
||||
"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "resume=UUID=59848b1b-c6be-48f4-b3e1-48179ea72dec"};
|
||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||
assert(refind_config_text == REFIND_CONFIG_SWAP_TEST);
|
||||
}
|
||||
// luks xfs
|
||||
{
|
||||
const std::vector<std::string> kernel_params{
|
||||
"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device"};
|
||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||
assert(refind_config_text == REFIND_CONFIG_LUKS_TEST);
|
||||
}
|
||||
// luks swap xfs
|
||||
{
|
||||
const std::vector<std::string> kernel_params{
|
||||
"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device", "resume=/dev/mapper/luks_swap_device"};
|
||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||
assert(refind_config_text == REFIND_CONFIG_LUKS_SWAP_TEST);
|
||||
}
|
||||
// valid zfs
|
||||
{
|
||||
const std::vector<std::string> kernel_params{
|
||||
"quiet", "splash", "rw", "root=ZFS=zpcachyos/ROOT", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||
assert(refind_config_text == REFIND_CONFIG_ZFS_TEST);
|
||||
}
|
||||
// luks btrfs with subvolumes
|
||||
{
|
||||
const std::vector<std::string> kernel_params{
|
||||
"quiet", "splash", "rw", "rootflags=subvol=/@", "cryptdevice=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f:luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "root=/dev/mapper/luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||
assert(refind_config_text == REFIND_CONFIG_LUKS_SUBVOL_TEST);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user