mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 14:32:22 +08:00
👷 add partition field to the config
This commit is contained in:
parent
66e01de191
commit
42b24fce70
@ -86,6 +86,34 @@ Example configuration:
|
||||
"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`
|
||||
|
||||
This sets the target device filesystem.
|
||||
|
@ -3,6 +3,20 @@
|
||||
"headless_mode": false,
|
||||
"device": "/dev/nvme0n1",
|
||||
"fs_name": "btrfs",
|
||||
"partitions": [
|
||||
{
|
||||
"name": "/dev/nvme0n1p3",
|
||||
"mountpoint": "/",
|
||||
"size": "450G",
|
||||
"type": "root"
|
||||
},
|
||||
{
|
||||
"name": "/dev/nvme0n1p1",
|
||||
"mountpoint": "/boot",
|
||||
"size": "512M",
|
||||
"type": "boot"
|
||||
}
|
||||
],
|
||||
"hostname": "cachyos",
|
||||
"locale": "en_US",
|
||||
"xkbmap": "us",
|
||||
|
@ -35,6 +35,7 @@ bool Config::initialize() noexcept {
|
||||
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_SEP_BOOT"] = 0;
|
||||
s_config->m_data["READY_PARTITIONS"] = std::vector<std::string>{};
|
||||
|
||||
// Mounting
|
||||
s_config->m_data["MOUNTPOINT"] = "/mnt";
|
||||
|
@ -103,6 +103,7 @@ void menu_simple() noexcept {
|
||||
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& 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& locale = std::get<std::string>(config_data["LOCALE"]);
|
||||
|
@ -1537,7 +1537,7 @@ void install_cachyos_repo() noexcept {
|
||||
spdlog::info("{} is supported", isa_level);
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@ -1775,6 +1775,40 @@ bool parse_config() noexcept {
|
||||
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")) {
|
||||
assert(doc["fs_name"].IsString());
|
||||
config_data["FILESYSTEM_NAME"] = std::string{doc["fs_name"].GetString()};
|
||||
|
Loading…
Reference in New Issue
Block a user