Add provision() to configure users for profiles (#4254)
This commit is contained in:
parent
a9c939cb86
commit
d86daa531a
|
|
@ -7,6 +7,7 @@ from archinstall.lib.translationhandler import tr
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from ..lib.installer import Installer
|
||||
from ..lib.models.users import User
|
||||
|
||||
|
||||
class ProfileType(Enum):
|
||||
|
|
@ -103,6 +104,13 @@ class Profile:
|
|||
are needed
|
||||
"""
|
||||
|
||||
def provision(self, install_session: Installer, users: list[User]) -> None:
|
||||
"""
|
||||
Hook that will be called when the installation process is
|
||||
finished and user configuration for specific default_profiles
|
||||
is needed
|
||||
"""
|
||||
|
||||
def json(self) -> dict[str, str]:
|
||||
"""
|
||||
Returns a json representation of the profile
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from archinstall.tui.ui.result import ResultType
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from archinstall.lib.installer import Installer
|
||||
from archinstall.lib.models.users import User
|
||||
|
||||
|
||||
class ServerProfile(Profile):
|
||||
|
|
@ -53,6 +54,11 @@ class ServerProfile(Profile):
|
|||
case ResultType.Reset:
|
||||
return SelectResult.ResetCurrent
|
||||
|
||||
@override
|
||||
def provision(self, install_session: Installer, users: list[User]) -> None:
|
||||
for profile in self.current_selection:
|
||||
profile.provision(install_session, users)
|
||||
|
||||
@override
|
||||
def post_install(self, install_session: Installer) -> None:
|
||||
for profile in self.current_selection:
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from archinstall.default_profiles.profile import Profile, ProfileType
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from archinstall.lib.installer import Installer
|
||||
from archinstall.lib.models.users import User
|
||||
|
||||
|
||||
class DockerProfile(Profile):
|
||||
|
|
@ -26,9 +27,6 @@ class DockerProfile(Profile):
|
|||
return ['docker']
|
||||
|
||||
@override
|
||||
def post_install(self, install_session: Installer) -> None:
|
||||
from archinstall.lib.args import arch_config_handler
|
||||
|
||||
if auth_config := arch_config_handler.config.auth_config:
|
||||
for user in auth_config.users:
|
||||
install_session.arch_chroot(f'usermod -a -G docker {user.username}')
|
||||
def provision(self, install_session: Installer, users: list[User]) -> None:
|
||||
for user in users:
|
||||
install_session.arch_chroot(f'usermod -a -G docker {user.username}')
|
||||
|
|
|
|||
|
|
@ -123,8 +123,10 @@ def perform_installation(
|
|||
config.profile_config,
|
||||
)
|
||||
|
||||
users = None
|
||||
if config.auth_config:
|
||||
if config.auth_config.users:
|
||||
users = config.auth_config.users
|
||||
installation.create_users(config.auth_config.users)
|
||||
auth_handler.setup_auth(installation, config.auth_config, config.hostname)
|
||||
|
||||
|
|
@ -153,6 +155,9 @@ def perform_installation(
|
|||
if (profile_config := config.profile_config) and profile_config.profile:
|
||||
profile_config.profile.post_install(installation)
|
||||
|
||||
if users:
|
||||
profile_config.profile.provision(installation, users)
|
||||
|
||||
# If the user provided a list of services to be enabled, pass the list to the enable_service function.
|
||||
# Note that while it's called enable_service, it can actually take a list of services and iterate it.
|
||||
if services := config.services:
|
||||
|
|
|
|||
Loading…
Reference in New Issue