👷 add autologin

This commit is contained in:
Vladislav Nepogodin 2022-02-15 01:07:59 +04:00
parent 5dc58c5745
commit a348f980ce
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
4 changed files with 81 additions and 14 deletions

View File

@ -100,23 +100,20 @@ Main Menu
| │ └── Add New User(s) (seems broken)
| │
│ ├── Install Custom Packages
│ ├── System Tweaks (TODO)
│ ├── System Tweaks
| │ ├── Enable Automatic Login
| │ ├── Enable Hibernation
| │ ├── Performance
| │ ├── Performance (TODO)
| | │ ├── I/O schedulers
| | │ ├── Swap configuration
| | │ └── Preload
| | │ └── zram
| | │
| │ ├── Security and systemd Tweaks
| | │ ├── Amend journald Logging
| | │ ├── Disable Coredump Logging
| | │ └── Restrict Access to Kernel Logs
| | │
| │ └── Restrict Access to Kernel Logs
| │ └── Security and systemd Tweaks (TODO)
| | ├── Amend journald Logging
| | ├── Disable Coredump Logging
| | └── Restrict Access to Kernel Logs
| │
│ ├── Review Configuration Files (TODO)
│ └── Chroot into Installation (TODO)
│ └── Chroot into Installation
|
└── System Rescue
├── Install Hardware Drivers (TODO)
@ -130,7 +127,7 @@ Main Menu
├── Install Custom Packages
├── Remove Packages
├── Review Configuration Files (TODO)
├── Chroot into Installation (TODO)
├── Chroot into Installation
├── Data Recovery (TODO)
│ └── Btrfs snapshots..

View File

@ -1192,7 +1192,53 @@ grub-install --target=i386-pc --recheck)";
#endif
}
void install_bootloader() {
void enable_autologin() {
// detect displaymanager
const auto& dm = utils::exec("file /mnt/etc/systemd/system/display-manager.service 2>/dev/null | awk -F'/' '{print $NF}' | cut -d. -f1");
const auto& content = fmt::format(FMT_COMPILE("\nThis option enables autologin using {}.\n\nProceed?\n"), dm);
/* clang-format off */
if (!detail::yesno_widget(content, size(HEIGHT, LESS_THAN, 15) | size(WIDTH, LESS_THAN, 75))) { return; }
if (utils::exec("echo /mnt/home/* | xargs -n1 | wc -l") != "1") { return; }
/* clang-format on */
const auto& autologin_user = utils::exec("echo /mnt/home/* | cut -d/ -f4");
utils::enable_autologin(dm, autologin_user);
}
void performance_menu() { }
void security_menu() { }
void tweaks_menu() noexcept {
const std::vector<std::string> menu_entries = {
"Enable Automatic Login",
"Performance",
"Security and systemd Tweaks",
"Back",
};
auto screen = ScreenInteractive::Fullscreen();
std::int32_t selected{};
auto ok_callback = [&] {
switch (selected) {
case 0:
tui::enable_autologin();
break;
case 1:
tui::performance_menu();
break;
case 2:
tui::security_menu();
break;
default:
screen.ExitLoopClosure()();
break;
}
};
static constexpr auto tweaks_body = "Various configuration options";
detail::menu_widget(menu_entries, ok_callback, &selected, &screen, tweaks_body, {.text_size = size(HEIGHT, GREATER_THAN, 1)});
}
void install_bootloader() noexcept {
/* clang-format off */
if (!utils::check_base()) { return; }
/* clang-format on */
@ -2048,7 +2094,7 @@ void install_core_menu() noexcept {
if (!utils::check_base()) {
screen.ExitLoopClosure()();
}
// tweaks_menu
tui::tweaks_menu();
break;
case 6:
if (!utils::check_base()) {

View File

@ -666,6 +666,29 @@ void set_keymap() noexcept {
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 {
#ifdef NDEVENV
// enable autologin
if (dm == "gdm") {
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^AutomaticLogin=*/AutomaticLogin={}/g' /mnt/etc/gdm/custom.conf"), user));
utils::exec("sed -i 's/^AutomaticLoginEnable=*/AutomaticLoginEnable=true/g' /mnt/etc/gdm/custom.conf");
utils::exec("sed -i 's/^TimedLoginEnable=*/TimedLoginEnable=true/g' /mnt/etc/gdm/custom.conf");
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^TimedLogin=*/TimedLoginEnable={}/g' /mnt/etc/gdm/custom.conf"), user));
utils::exec("sed -i 's/^TimedLoginDelay=*/TimedLoginDelay=0/g' /mnt/etc/gdm/custom.conf");
} else if (dm == "lightdm") {
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^#autologin-user=/autologin-user={}/' /mnt/etc/lightdm/lightdm.conf"), user));
utils::exec("sed -i 's/^#autologin-user-timeout=0/autologin-user-timeout=0/' /mnt/etc/lightdm/lightdm.conf");
utils::arch_chroot("groupadd -r autologin");
utils::arch_chroot(fmt::format(FMT_COMPILE("gpasswd -a {} autologin"), user));
} else if (dm == "sddm") {
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^User=/User={}/g' /mnt/etc/sddm.conf"), user));
} else if (dm == "lxdm") {
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/^# autologin=dgod/autologin={}/g' /mnt/etc/lxdm/lxdm.conf"), user));
}
#endif
}
void parse_config() noexcept {
using namespace simdjson;

View File

@ -41,6 +41,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 parse_config() noexcept;
void setup_luks_keyfile() noexcept;
void final_check() noexcept;