Skip to content

Commit a275efc

Browse files
committed
Add provision() to configure users for profiles
1 parent a9c939c commit a275efc

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

archinstall/default_profiles/profile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from enum import Enum, auto
44
from typing import TYPE_CHECKING, Self
55

6+
from archinstall.lib.models.users import User
67
from archinstall.lib.translationhandler import tr
78

89
if TYPE_CHECKING:
@@ -103,6 +104,13 @@ def post_install(self, install_session: Installer) -> None:
103104
are needed
104105
"""
105106

107+
def provision(self, install_session: Installer, users: list[User]) -> None:
108+
"""
109+
Hook that will be called when the installation process is
110+
finished and user configuration for specific default_profiles
111+
is needed
112+
"""
113+
106114
def json(self) -> dict[str, str]:
107115
"""
108116
Returns a json representation of the profile

archinstall/default_profiles/server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from archinstall.default_profiles.profile import Profile, ProfileType, SelectResult
66
from archinstall.lib.menu.helpers import Selection
7+
from archinstall.lib.models.users import User
78
from archinstall.lib.output import info
89
from archinstall.lib.profile.profiles_handler import profile_handler
910
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
@@ -53,6 +54,11 @@ def do_on_select(self) -> SelectResult:
5354
case ResultType.Reset:
5455
return SelectResult.ResetCurrent
5556

57+
@override
58+
def provision(self, install_session: Installer, users: list[User]) -> None:
59+
for profile in self.current_selection:
60+
profile.provision(install_session, users)
61+
5662
@override
5763
def post_install(self, install_session: Installer) -> None:
5864
for profile in self.current_selection:

archinstall/default_profiles/servers/docker.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import TYPE_CHECKING, override
44

55
from archinstall.default_profiles.profile import Profile, ProfileType
6+
from archinstall.lib.models.users import User
67

78
if TYPE_CHECKING:
89
from archinstall.lib.installer import Installer
@@ -26,9 +27,6 @@ def services(self) -> list[str]:
2627
return ['docker']
2728

2829
@override
29-
def post_install(self, install_session: Installer) -> None:
30-
from archinstall.lib.args import arch_config_handler
31-
32-
if auth_config := arch_config_handler.config.auth_config:
33-
for user in auth_config.users:
34-
install_session.arch_chroot(f'usermod -a -G docker {user.username}')
30+
def provision(self, install_session: Installer, users: list[User]) -> None:
31+
for user in users:
32+
install_session.arch_chroot(f'usermod -a -G docker {user.username}')

archinstall/scripts/guided.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ def perform_installation(
123123
config.profile_config,
124124
)
125125

126+
users = None
126127
if config.auth_config:
127128
if config.auth_config.users:
129+
users = config.auth_config.users
128130
installation.create_users(config.auth_config.users)
129131
auth_handler.setup_auth(installation, config.auth_config, config.hostname)
130132

@@ -153,6 +155,9 @@ def perform_installation(
153155
if (profile_config := config.profile_config) and profile_config.profile:
154156
profile_config.profile.post_install(installation)
155157

158+
if users:
159+
profile_config.profile.provision(installation, users)
160+
156161
# If the user provided a list of services to be enabled, pass the list to the enable_service function.
157162
# Note that while it's called enable_service, it can actually take a list of services and iterate it.
158163
if services := config.services:

0 commit comments

Comments
 (0)