👷 Expose server profile config to config

Allow user to enable server profile from config option,
by using `server_mode: true` in the config file.

Install additional packages for BTFS, ZFS.
This commit is contained in:
Vladislav Nepogodin 2023-02-25 04:08:08 +04:00
parent 71cc7c8189
commit 53d89bdc4e
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
2 changed files with 31 additions and 9 deletions

View File

@ -672,10 +672,14 @@ void lvm_detect(std::optional<std::function<void()>> func_callback) noexcept {
}
auto get_pkglist_base(const std::string_view& packages) noexcept -> std::vector<std::string> {
auto* config_instance = Config::instance();
auto& config_data = config_instance->data();
const auto& zfs = std::get<std::int32_t>(config_data["ZFS"]);
const auto& server_mode = std::get<std::int32_t>(config_data["SERVER_MODE"]);
auto* config_instance = Config::instance();
auto& config_data = config_instance->data();
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_root_fs(mountpoint_info);
const auto& is_root_on_zfs = (root_filesystem == "zfs");
const auto& is_root_on_btrfs = (root_filesystem == "btrfs");
auto pkg_list = utils::make_multiline(packages, false, ' ');
@ -683,14 +687,17 @@ auto get_pkglist_base(const std::string_view& packages) noexcept -> std::vector<
for (std::size_t i = 0; i < pkg_count; ++i) {
const auto& pkg = pkg_list[i];
pkg_list.emplace_back(fmt::format(FMT_COMPILE("{}-headers"), pkg));
if (zfs == 1 && pkg.starts_with("linux-cachyos")) {
if (is_root_on_zfs && pkg.starts_with("linux-cachyos")) {
pkg_list.emplace_back(fmt::format(FMT_COMPILE("{}-zfs"), pkg));
}
}
if (zfs == 1) {
if (is_root_on_zfs) {
pkg_list.insert(pkg_list.cend(), {"zfs-utils"});
}
if (server_mode == 0) {
if (is_root_on_btrfs) {
pkg_list.insert(pkg_list.cend(), {"snapper", "btrfs-assistant-git"});
}
pkg_list.insert(pkg_list.cend(), {"alacritty", "cachy-browser", "cachyos-fish-config", "cachyos-ananicy-rules", "cachyos-hello", "cachyos-hooks", "cachyos-kernel-manager", "power-profiles-daemon"});
pkg_list.insert(pkg_list.cend(), {"cachyos-rate-mirrors", "cachyos-packageinstaller", "cachyos-settings", "cachyos-zsh-config", "mhwd-cachyos", "mhwd-db-cachyos"});
}
@ -1388,6 +1395,10 @@ std::string list_mounted() noexcept {
return utils::exec("echo /dev/* /dev/mapper/* | xargs -n1 2>/dev/null | grep -f /tmp/.mounted");
}
std::string get_root_fs(const std::string_view& mountpoint) noexcept {
return utils::exec(fmt::format(FMT_COMPILE("findmnt -ln -o FSTYPE \"{}\""), mountpoint));
}
std::string list_containing_crypt() noexcept {
return utils::exec("blkid | awk '/TYPE=\"crypto_LUKS\"/{print $1}' | sed 's/.$//'");
}
@ -1855,6 +1866,16 @@ bool parse_config() noexcept {
spdlog::info("Running in NORMAL mode!");
}
auto& server_mode = std::get<std::int32_t>(config_data["SERVER_MODE"]);
if (doc.HasMember("server_mode")) {
assert(doc["server_mode"].IsBool());
server_mode = static_cast<std::int32_t>(doc["server_mode"].GetBool());
}
if (server_mode) {
spdlog::info("Server profile enabled!");
}
if (doc.HasMember("device")) {
assert(doc["device"].IsString());
config_data["DEVICE"] = std::string{doc["device"].GetString()};

View File

@ -34,9 +34,10 @@ void create_new_user(const std::string_view& user, const std::string_view& passw
void set_root_password(const std::string_view& password) noexcept;
[[nodiscard]] bool check_mount() noexcept;
[[nodiscard]] bool check_base() noexcept;
[[nodiscard]] std::string list_mounted() noexcept;
[[nodiscard]] std::string list_containing_crypt() noexcept;
[[nodiscard]] std::string list_non_crypt() noexcept;
[[nodiscard]] auto list_mounted() noexcept -> std::string;
[[nodiscard]] auto get_root_fs(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;
void umount_partitions() noexcept;
void find_partitions() noexcept;