Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import glob
import json
import os
import platform
import re
Expand Down Expand Up @@ -1943,6 +1944,20 @@ def _create_user(self, user: User) -> None:
if user.sudo:
self.enable_sudo(user)

if user.birth_date:
self._write_userdb_dropin(user)

def _write_userdb_dropin(self, user: User) -> None:
userdb_dir = self.target / 'etc' / 'userdb'
userdb_dir.mkdir(parents=True, exist_ok=True)

dropin = userdb_dir / f'{user.username}.user'
record = {'userName': user.username, 'birthDate': user.birth_date}
dropin.write_text(json.dumps(record))
dropin.chmod(0o644)

info(f'Wrote userdb drop-in for {user.username} with birth date')

def set_user_password(self, user: User) -> bool:
info(f'Setting password for {user.username}')

Expand Down
11 changes: 10 additions & 1 deletion archinstall/lib/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def _check_password_strength(
'sudo': bool,
'groups': list[str],
'enc_password': str | None,
'birth_date': NotRequired[str],
},
)

Expand Down Expand Up @@ -158,6 +159,7 @@ class User:
password: Password
sudo: bool
groups: list[str] = field(default_factory=list)
birth_date: str = ''

@override
def __str__(self) -> str:
Expand All @@ -170,16 +172,22 @@ def table_data(self) -> dict[str, str | bool | list[str]]:
'password': self.password.hidden(),
'sudo': self.sudo,
'groups': self.groups,
'birth_date': self.birth_date,
}

def json(self) -> UserSerialization:
return {
data: UserSerialization = {
'username': self.username,
'enc_password': self.password.enc_password,
'sudo': self.sudo,
'groups': self.groups,
}

if self.birth_date:
data['birth_date'] = self.birth_date

return data

@classmethod
def parse_arguments(
cls,
Expand Down Expand Up @@ -208,6 +216,7 @@ def parse_arguments(
password=password,
sudo=entry.get('sudo', False) is True,
groups=groups,
birth_date=entry.get('birth_date', ''),
)

users.append(user)
Expand Down
37 changes: 36 additions & 1 deletion archinstall/lib/user/user_menu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from datetime import UTC, date, datetime
from typing import override

from archinstall.lib.menu.helpers import Confirmation, Input
Expand Down Expand Up @@ -91,6 +92,12 @@ def _add_user(self) -> User | None:
return None

header += f'{tr("Password")}: {password.hidden()}\n'

birth_date = self._ask_birth_date(header)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating users is not mandatory, one can also only set a root password

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this, you know this, but the laws that just got adopted are written in a stupid way that possibly doesn't exempt TUI installers. I don't know if will be "safe" for the project to not ask for a birth date when adding a user when these laws take effect in 2027.


if birth_date:
header += f'{tr("Birth date")}: {birth_date}\n'

prompt = f'{header}\n' + tr('Should "{}" be a superuser (sudo)?\n').format(username)

result = Confirmation(
Expand All @@ -105,7 +112,35 @@ def _add_user(self) -> User | None:
case _:
raise ValueError('Unhandled result type')

return User(username, password, sudo)
return User(username, password, sudo, birth_date=birth_date)

def _validate_birth_date(self, value: str | None) -> str | None:
if not value:
return tr('Birth date is required')
try:
dt = date.fromisoformat(value)
except ValueError:
return tr('Invalid date format. Use YYYY-MM-DD')
if dt > datetime.now(tz=UTC).date():
return tr('Birth date cannot be in the future')
if dt.year < 1900:
return tr('Birth date year must be 1900 or later')
return None

def _ask_birth_date(self, header: str) -> str:
prompt = f'{header}\n' + tr('Enter birth date (YYYY-MM-DD, e.g. 2000-01-01)')

result = Input(
prompt,
allow_skip=False,
validator_callback=self._validate_birth_date,
).show()

match result.type_:
case ResultType.Selection:
return result.get_value() or ''
case _:
raise ValueError('Unhandled result type')


def select_users(prompt: str = '', preset: list[User] = []) -> list[User]:
Expand Down