base+gui: Move autologin configuration to /etc/loginui.conf
All checks were successful
Build and test / build (push) Successful in 1m45s

This commit is contained in:
apio 2024-09-14 15:05:05 +02:00
parent bbe1eca711
commit 4cf39c14a1
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 18 additions and 15 deletions

View File

@ -44,7 +44,7 @@ If you have no toolchain set up, `run.sh` will build it automatically, which mea
For development convenience, the system automatically starts a GUI session as the default user, without prompting for a password.
Despite this, Luna does have a login window built-in. If you'd like to try this feature out or start a GUI session as a different user, you'll need to edit [base/etc/init/99-login](base/etc/init/99-login) and change the line that says `Command=/usr/bin/loginui --autologin=selene` to `Command=/usr/bin/loginui`.
Despite this, Luna does have a login window built-in. If you'd like to try this feature out or start a GUI session as a different user, you'll need to edit [base/etc/loginui.conf](base/etc/loginui.conf) and change the line that says `Autologin=true` to `Autologin=false`.
## Prebuilt images

View File

@ -1,6 +1,6 @@
Name=login
Description=Start a graphical user session.
Command=/usr/bin/loginui --autologin=selene
Command=/usr/bin/loginui
StandardOutput=/dev/uart0
StandardError=/dev/uart0
Restart=true

2
base/etc/loginui.conf Normal file
View File

@ -0,0 +1,2 @@
Autologin=true
AutologinUser=selene

View File

@ -9,6 +9,7 @@
#include <luna/String.h>
#include <os/ArgumentParser.h>
#include <os/Config.h>
#include <os/File.h>
#include <os/FileSystem.h>
#include <os/IPC.h>
@ -33,16 +34,9 @@ static constexpr ui::Color BACKGROUND_COLOR = ui::Color::from_rgb(89, 89, 89);
Result<int> luna_main(int argc, char** argv)
{
StringView username;
os::ArgumentParser parser;
parser.add_description("Login prompt for a graphical UI session.");
parser.add_system_program_info("loginui"_sv);
// FIXME: Make this a config option instead of a switch.
// Also, calling "loginui --autologin=user" is functionally identical to calling "startui --user=user", the only
// difference is that it makes the init config easier to change (only adding or removing the autologin flag, instead
// of changing the program to use)
parser.add_value_argument(username, ' ', "autologin", "login as a specific user without prompting");
parser.parse(argc, argv);
if (geteuid() != 0)
@ -66,6 +60,12 @@ Result<int> luna_main(int argc, char** argv)
return 1;
}
auto config = TRY(os::ConfigFile::open("/etc/loginui.conf"));
if (config->read_boolean_or("Autologin", false))
{
StringView username = config->read_string_or("AutologinUser", "");
if (!username.is_empty())
{
auto flag = String::format("--user=%s"_sv, username.chars()).release_value();
@ -74,6 +74,7 @@ Result<int> luna_main(int argc, char** argv)
os::Process::exec(startui_command[0], Slice<StringView>(startui_command, 2));
unreachable();
}
}
ui::App app;
TRY(app.init());