|
34 | 34 | from .models.packages import Repository |
35 | 35 | from .models.profile import ProfileConfiguration |
36 | 36 | from .models.users import Password, User |
37 | | -from .models.profile_model import ProfileConfiguration |
38 | | -from .models.users import User |
39 | 37 | from .output import FormattedOutput |
40 | 38 | from .pacman.config import PacmanConfig |
41 | 39 | from .translationhandler import Language, tr, translation_handler |
| 40 | +from .utils.util import get_password |
42 | 41 |
|
43 | 42 |
|
44 | 43 | class GlobalMenu(AbstractMenu[None]): |
@@ -111,9 +110,16 @@ def _get_menu_options(self) -> list[MenuItem]: |
111 | 110 | preview_action=self._prev_hostname, |
112 | 111 | key='hostname', |
113 | 112 | ), |
| 113 | + MenuItem( |
| 114 | + text=tr('Root password'), |
| 115 | + action=self._set_root_password, |
| 116 | + preview_action=self._prev_root_pwd, |
| 117 | + key='root_enc_password', |
| 118 | + ), |
114 | 119 | MenuItem( |
115 | 120 | text=tr('Authentication'), |
116 | 121 | action=self._select_authentication, |
| 122 | + value=[], |
117 | 123 | preview_action=self._prev_authentication, |
118 | 124 | key='auth_config', |
119 | 125 | ), |
@@ -224,16 +230,13 @@ def has_superuser() -> bool: |
224 | 230 |
|
225 | 231 | missing = set() |
226 | 232 |
|
227 | | - item: MenuItem = self._item_group.find_by_key('auth_config') |
228 | | - auth_config: AuthenticationConfiguration | None = item.value |
229 | | - |
230 | | - if (auth_config is None or auth_config.root_enc_password is None) and not has_superuser(): |
231 | | - missing.add( |
232 | | - tr('Either root-password or at least 1 user with sudo privileges must be specified'), |
233 | | - ) |
234 | | - |
235 | 233 | for item in self._item_group.items: |
236 | | - if item.mandatory: |
| 234 | + if item.key in ['root_enc_password', 'users']: |
| 235 | + if not check('root_enc_password') and not has_superuser(): |
| 236 | + missing.add( |
| 237 | + tr('Either root-password or at least 1 user with sudo privileges must be specified'), |
| 238 | + ) |
| 239 | + elif item.mandatory: |
237 | 240 | assert item.key is not None |
238 | 241 | if not check(item.key): |
239 | 242 | missing.add(item.text) |
@@ -311,9 +314,6 @@ def _prev_authentication(self, item: MenuItem) -> str | None: |
311 | 314 | auth_config: AuthenticationConfiguration = item.value |
312 | 315 | output = '' |
313 | 316 |
|
314 | | - if auth_config.root_enc_password: |
315 | | - output += f'{tr("Root password")}: {auth_config.root_enc_password.hidden()}\n' |
316 | | - |
317 | 317 | if auth_config.u2f_config: |
318 | 318 | u2f_config = auth_config.u2f_config |
319 | 319 | login_method = u2f_config.u2f_login_method.display_value() |
@@ -400,6 +400,12 @@ def _prev_hostname(self, item: MenuItem) -> str | None: |
400 | 400 | return f'{tr("Hostname")}: {item.value}' |
401 | 401 | return None |
402 | 402 |
|
| 403 | + def _prev_root_pwd(self, item: MenuItem) -> str | None: |
| 404 | + if item.value is not None: |
| 405 | + password: Password = item.value |
| 406 | + return f'{tr("Root password")}: {password.hidden()}' |
| 407 | + return None |
| 408 | + |
403 | 409 | def _prev_parallel_dw(self, item: MenuItem) -> str | None: |
404 | 410 | if item.value is not None: |
405 | 411 | return f'{tr("Parallel Downloads")}: {item.value}' |
@@ -504,6 +510,10 @@ def _prev_profile(self, item: MenuItem) -> str | None: |
504 | 510 |
|
505 | 511 | return None |
506 | 512 |
|
| 513 | + def _set_root_password(self, preset: str | None = None) -> Password | None: |
| 514 | + password = get_password(text=tr('Root password'), allow_skip=True) |
| 515 | + return password |
| 516 | + |
507 | 517 | def _select_disk_config( |
508 | 518 | self, |
509 | 519 | preset: DiskLayoutConfiguration | None = None, |
|
0 commit comments