👷 add partition field to the config

This commit is contained in:
Vladislav Nepogodin 2023-01-28 02:05:07 +04:00
parent 66e01de191
commit 42b24fce70
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
5 changed files with 79 additions and 1 deletions

View File

@ -86,6 +86,34 @@ Example configuration:
"device": "/dev/nvme0n1" "device": "/dev/nvme0n1"
``` ```
--- ---
### `partitions`
This declares partitions map.
Required in `HEADLESS` mode!
The `partitions` provide information, which will be used
during the partition and mount steps.
There is no default for this option.
Example configuration:
```json
"partitions": [
{
"name": "/dev/nvme0n1p3",
"mountpoint": "/",
"size": "450G",
"type": "root"
},
{
"name": "/dev/nvme0n1p1",
"mountpoint": "/boot",
"size": "512M",
"type": "boot"
}
]
```
---
### `fs_name` ### `fs_name`
This sets the target device filesystem. This sets the target device filesystem.

View File

@ -3,6 +3,20 @@
"headless_mode": false, "headless_mode": false,
"device": "/dev/nvme0n1", "device": "/dev/nvme0n1",
"fs_name": "btrfs", "fs_name": "btrfs",
"partitions": [
{
"name": "/dev/nvme0n1p3",
"mountpoint": "/",
"size": "450G",
"type": "root"
},
{
"name": "/dev/nvme0n1p1",
"mountpoint": "/boot",
"size": "512M",
"type": "boot"
}
],
"hostname": "cachyos", "hostname": "cachyos",
"locale": "en_US", "locale": "en_US",
"xkbmap": "us", "xkbmap": "us",

View File

@ -35,6 +35,7 @@ bool Config::initialize() noexcept {
s_config->m_data["LVM"] = 0; s_config->m_data["LVM"] = 0;
s_config->m_data["LVM_LV_NAME"] = ""; // Name of LV to create or use s_config->m_data["LVM_LV_NAME"] = ""; // Name of LV to create or use
s_config->m_data["LVM_SEP_BOOT"] = 0; s_config->m_data["LVM_SEP_BOOT"] = 0;
s_config->m_data["READY_PARTITIONS"] = std::vector<std::string>{};
// Mounting // Mounting
s_config->m_data["MOUNTPOINT"] = "/mnt"; s_config->m_data["MOUNTPOINT"] = "/mnt";

View File

@ -103,6 +103,7 @@ void menu_simple() noexcept {
const auto& device_info = std::get<std::string>(config_data["DEVICE"]); const auto& device_info = std::get<std::string>(config_data["DEVICE"]);
const auto& fs_name = std::get<std::string>(config_data["FILESYSTEM_NAME"]); const auto& fs_name = std::get<std::string>(config_data["FILESYSTEM_NAME"]);
const auto& mount_opts_info = std::get<std::string>(config_data["MOUNT_OPTS"]); const auto& mount_opts_info = std::get<std::string>(config_data["MOUNT_OPTS"]);
const auto& ready_parts = std::get<std::vector<std::string>>(config_data["READY_PARTITIONS"]);
const auto& hostname = std::get<std::string>(config_data["HOSTNAME"]); const auto& hostname = std::get<std::string>(config_data["HOSTNAME"]);
const auto& locale = std::get<std::string>(config_data["LOCALE"]); const auto& locale = std::get<std::string>(config_data["LOCALE"]);

View File

@ -1537,7 +1537,7 @@ void install_cachyos_repo() noexcept {
spdlog::info("{} is supported", isa_level); spdlog::info("{} is supported", isa_level);
const auto& repo_list = detail::pacmanconf::get_repo_list("/etc/pacman.conf"); const auto& repo_list = detail::pacmanconf::get_repo_list("/etc/pacman.conf");
if (ranges::contains(repo_list, fmt::format("[{}]", repo_name))) { if (ranges::contains(repo_list, fmt::format(FMT_COMPILE("[{}]"), repo_name))) {
spdlog::info("'{}' is already added!", repo_name); spdlog::info("'{}' is already added!", repo_name);
return; return;
} }
@ -1775,6 +1775,40 @@ bool parse_config() noexcept {
return false; return false;
} }
if (doc.HasMember("partitions")) {
assert(doc["partitions"].IsArray());
std::vector<std::string> ready_parts{};
for (const auto& partition_map : doc["partitions"].GetArray()) {
assert(partition_map.IsObject());
const auto& part_obj = partition_map.GetObject();
assert(partition_map["name"].IsString());
assert(partition_map["mountpoint"].IsString());
assert(partition_map["size"].IsString());
assert(partition_map["type"].IsString());
// Validate partition type.
const auto& part_type = std::string{partition_map["type"].GetString()};
using namespace std::literals;
static constexpr std::array valid_types{"root"sv, "boot"sv, "additional"sv};
if (!ranges::contains(valid_types, part_type)) {
fmt::print(stderr, "partition type '{}' is invalid! Valid types: {}.\n", part_type, valid_types);
return false;
}
// Just to save some space push as single string instead of a new type.
auto&& part_data = fmt::format(FMT_COMPILE("{}\t{}\t{}\t{}"), partition_map["name"].GetString(),
partition_map["mountpoint"].GetString(), partition_map["size"].GetString(), part_type);
ready_parts.push_back(std::move(part_data));
}
config_data["READY_PARTITIONS"] = std::move(ready_parts);
} else if (headless_mode) {
fmt::print(stderr, "\"partitions\" field is required in HEADLESS mode!\n");
return false;
}
if (doc.HasMember("fs_name")) { if (doc.HasMember("fs_name")) {
assert(doc["fs_name"].IsString()); assert(doc["fs_name"].IsString());
config_data["FILESYSTEM_NAME"] = std::string{doc["fs_name"].GetString()}; config_data["FILESYSTEM_NAME"] = std::string{doc["fs_name"].GetString()};