mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 14:32:22 +08:00
🧹 move autologin into gucc
This commit is contained in:
parent
cfd260855c
commit
7c75e4600d
@ -26,6 +26,7 @@ add_library(${PROJECT_NAME} SHARED
|
||||
src/crypttab.cpp include/gucc/crypttab.hpp
|
||||
src/bootloader.cpp include/gucc/bootloader.hpp
|
||||
src/systemd_services.cpp include/gucc/systemd_services.hpp
|
||||
src/autologin.cpp include/gucc/autologin.hpp
|
||||
#src/chwd_profiles.cpp src/chwd_profiles.hpp
|
||||
#src/disk.cpp src/disk.hpp
|
||||
)
|
||||
|
13
gucc/include/gucc/autologin.hpp
Normal file
13
gucc/include/gucc/autologin.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef AUTOLOGIN_HPP
|
||||
#define AUTOLOGIN_HPP
|
||||
|
||||
#include <string_view> // for string_view
|
||||
|
||||
namespace gucc::user {
|
||||
|
||||
// Enables autologin for user
|
||||
auto enable_autologin(std::string_view displaymanager, std::string_view username, std::string_view root_mountpoint) noexcept -> bool;
|
||||
|
||||
} // namespace gucc::user
|
||||
|
||||
#endif // AUTOLOGIN_HPP
|
@ -16,6 +16,7 @@ gucc_lib = library('gucc',
|
||||
'src/crypttab.cpp',
|
||||
'src/bootloader.cpp',
|
||||
'src/systemd_services.cpp',
|
||||
'src/autologin.cpp',
|
||||
],
|
||||
include_directories : [include_directories('include')],
|
||||
dependencies: deps
|
||||
|
48
gucc/src/autologin.cpp
Normal file
48
gucc/src/autologin.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "gucc/autologin.hpp"
|
||||
#include "gucc/io_utils.hpp"
|
||||
#include "gucc/user.hpp"
|
||||
|
||||
#include <fmt/compile.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
namespace gucc::user {
|
||||
|
||||
auto enable_autologin(std::string_view displaymanager, std::string_view username, std::string_view root_mountpoint) noexcept -> bool {
|
||||
// TODO(vnepogodin): check for failed commands
|
||||
|
||||
// enable autologin
|
||||
if (displaymanager == "gdm"sv) {
|
||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^AutomaticLogin=*/AutomaticLogin={}/g' {}/etc/gdm/custom.conf"), username, root_mountpoint));
|
||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^AutomaticLoginEnable=*/AutomaticLoginEnable=true/g' {}/etc/gdm/custom.conf"), root_mountpoint));
|
||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^TimedLoginEnable=*/TimedLoginEnable=true/g' {}/etc/gdm/custom.conf"), root_mountpoint));
|
||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^TimedLogin=*/TimedLoginEnable={}/g' {}/etc/gdm/custom.conf"), username, root_mountpoint));
|
||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^TimedLoginDelay=*/TimedLoginDelay=0/g' {}/etc/gdm/custom.conf"), root_mountpoint));
|
||||
} else if (displaymanager == "lightdm"sv) {
|
||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^#autologin-user=/autologin-user={}/' {}/etc/lightdm/lightdm.conf"), username, root_mountpoint));
|
||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^#autologin-user-timeout=0/autologin-user-timeout=0/' {}/etc/lightdm/lightdm.conf"), root_mountpoint));
|
||||
|
||||
// create autologin group
|
||||
if (!user::create_group("autologin"sv, root_mountpoint, true)) {
|
||||
spdlog::error("Failed to create autologin group");
|
||||
return false;
|
||||
}
|
||||
// add group to user
|
||||
const auto& groupadd_cmd = fmt::format(FMT_COMPILE("gpasswd -a {} autologin"), username);
|
||||
if (!utils::arch_chroot_checked(groupadd_cmd, root_mountpoint)) {
|
||||
spdlog::error("Failed to add autologin group to user: {}", username);
|
||||
return false;
|
||||
}
|
||||
} else if (displaymanager == "sddm"sv) {
|
||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^User=/User={}/g' {}/etc/sddm.conf"), username, root_mountpoint));
|
||||
} else if (displaymanager == "lxdm"sv) {
|
||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^# autologin=dgod/autologin={}/g' {}/etc/lxdm/lxdm.conf"), username, root_mountpoint));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gucc::user
|
@ -6,6 +6,7 @@
|
||||
#include "widgets.hpp"
|
||||
|
||||
// import gucc
|
||||
#include "gucc/autologin.hpp"
|
||||
#include "gucc/bootloader.hpp"
|
||||
#include "gucc/cpu.hpp"
|
||||
#include "gucc/file_utils.hpp"
|
||||
@ -1746,26 +1747,14 @@ void set_keymap() noexcept {
|
||||
gucc::utils::exec(fmt::format(FMT_COMPILE("loadkeys {}"), keymap));
|
||||
}
|
||||
|
||||
void enable_autologin([[maybe_unused]] const std::string_view& dm, [[maybe_unused]] const std::string_view& user) noexcept {
|
||||
void enable_autologin([[maybe_unused]] const std::string_view& dm, [[maybe_unused]] const std::string_view& username) noexcept {
|
||||
#ifdef NDEVENV
|
||||
// enable autologin
|
||||
if (dm == "gdm") {
|
||||
gucc::utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^AutomaticLogin=*/AutomaticLogin={}/g' /mnt/etc/gdm/custom.conf"), user));
|
||||
gucc::utils::exec("sed -i 's/^AutomaticLoginEnable=*/AutomaticLoginEnable=true/g' /mnt/etc/gdm/custom.conf");
|
||||
gucc::utils::exec("sed -i 's/^TimedLoginEnable=*/TimedLoginEnable=true/g' /mnt/etc/gdm/custom.conf");
|
||||
gucc::utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^TimedLogin=*/TimedLoginEnable={}/g' /mnt/etc/gdm/custom.conf"), user));
|
||||
gucc::utils::exec("sed -i 's/^TimedLoginDelay=*/TimedLoginDelay=0/g' /mnt/etc/gdm/custom.conf");
|
||||
} else if (dm == "lightdm") {
|
||||
gucc::utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^#autologin-user=/autologin-user={}/' /mnt/etc/lightdm/lightdm.conf"), user));
|
||||
gucc::utils::exec("sed -i 's/^#autologin-user-timeout=0/autologin-user-timeout=0/' /mnt/etc/lightdm/lightdm.conf");
|
||||
auto* config_instance = Config::instance();
|
||||
auto& config_data = config_instance->data();
|
||||
const auto& mountpoint = std::get<std::string>(config_data["MOUNTPOINT"]);
|
||||
|
||||
// TODO(vnepogodin): refactor with gucc
|
||||
utils::arch_chroot("groupadd -r autologin", false);
|
||||
utils::arch_chroot(fmt::format(FMT_COMPILE("gpasswd -a {} autologin"), user), false);
|
||||
} else if (dm == "sddm") {
|
||||
gucc::utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^User=/User={}/g' /mnt/etc/sddm.conf"), user));
|
||||
} else if (dm == "lxdm") {
|
||||
gucc::utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^# autologin=dgod/autologin={}/g' /mnt/etc/lxdm/lxdm.conf"), user));
|
||||
if (!gucc::user::enable_autologin(dm, username, mountpoint)) {
|
||||
spdlog::error("Failed to enable autologin");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ void id_system() noexcept;
|
||||
void show_iwctl() noexcept;
|
||||
|
||||
void set_keymap() noexcept;
|
||||
void enable_autologin(const std::string_view& dm, const std::string_view& user) noexcept;
|
||||
void enable_autologin(const std::string_view& dm, const std::string_view& username) noexcept;
|
||||
bool parse_config() noexcept;
|
||||
void setup_luks_keyfile() noexcept;
|
||||
void grub_mkconfig() noexcept;
|
||||
|
Loading…
Reference in New Issue
Block a user