mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-02-02 22:07:13 +08:00
🧹 move setting root password into gucc
This commit is contained in:
parent
0a70f0a9dd
commit
606fc3e6af
@ -26,6 +26,9 @@ auto set_hostname(std::string_view hostname, std::string_view mountpoint) noexce
|
||||
// Set system hosts
|
||||
auto set_hosts(std::string_view hostname, std::string_view mountpoint) noexcept -> bool;
|
||||
|
||||
// Set password for root user
|
||||
auto set_root_password(std::string_view password, std::string_view mountpoint) noexcept -> bool;
|
||||
|
||||
} // namespace gucc::user
|
||||
|
||||
#endif // USER_HPP
|
||||
|
@ -169,4 +169,15 @@ ff02::2 ip6-allrouters
|
||||
return true;
|
||||
}
|
||||
|
||||
auto set_root_password(std::string_view password, std::string_view mountpoint) noexcept -> bool {
|
||||
// TODO(vnepogodin): should encrypt password properly here
|
||||
const auto& encrypted_passwd = utils::exec(fmt::format(FMT_COMPILE("openssl passwd {}"), password));
|
||||
const auto& password_set_cmd = fmt::format(FMT_COMPILE("usermod -p '{}' root"), encrypted_passwd);
|
||||
if (!utils::arch_chroot_checked(password_set_cmd, mountpoint)) {
|
||||
spdlog::error("Failed to set password for root user");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gucc::user
|
||||
|
@ -497,10 +497,9 @@ void set_root_password(const std::string_view& password) noexcept {
|
||||
auto& config_data = config_instance->data();
|
||||
const auto& mountpoint = std::get<std::string>(config_data["MOUNTPOINT"]);
|
||||
|
||||
std::error_code err{};
|
||||
gucc::utils::exec(fmt::format(FMT_COMPILE("echo -e \"{0}\n{0}\" > /tmp/.passwd"), password));
|
||||
gucc::utils::exec(fmt::format(FMT_COMPILE("arch-chroot {} passwd root < /tmp/.passwd &>/dev/null"), mountpoint));
|
||||
fs::remove("/tmp/.passwd", err);
|
||||
if (!gucc::user::set_root_password(password, mountpoint)) {
|
||||
spdlog::error("Failed to set root password");
|
||||
}
|
||||
#else
|
||||
spdlog::debug("root password := {}", password);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user