diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 19560d75a9..e596f7fead 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -739,6 +739,9 @@ def arch_chroot(self, cmd: str, run_as: str | None = None, peek_output: bool = F return self.run_command(cmd, peek_output=peek_output) + def _chroot_argv(self, *args: str) -> list[str]: + return ['arch-chroot', '-S', str(self.target), *args] + def drop_to_shell(self) -> None: subprocess.check_call(f'arch-chroot {self.target}', shell=True) @@ -987,17 +990,7 @@ def setup_btrfs_snapshot( } for config_name, mountpoint in snapper.items(): - command = [ - 'arch-chroot', - '-S', - str(self.target), - 'snapper', - '--no-dbus', - '-c', - config_name, - 'create-config', - mountpoint, - ] + command = self._chroot_argv('snapper', '--no-dbus', '-c', config_name, 'create-config', mountpoint) try: SysCommand(command, peek_output=True) @@ -1336,13 +1329,7 @@ def _add_grub_bootloader( boot_dir = Path('/boot') - command = [ - 'arch-chroot', - '-S', - str(self.target), - 'grub-install', - '--debug', - ] + command = self._chroot_argv('grub-install', '--debug') if SysInfo.has_uefi(): if not efi_partition: @@ -1922,16 +1909,17 @@ def _create_user(self, user: User) -> None: if not handled_by_plugin: info(f'Creating user {user.username}') - cmd = 'useradd -m' + cmd = self._chroot_argv('useradd', '-m') if user.sudo: - cmd += ' -G wheel' + cmd += ['-G', 'wheel'] - cmd += f' {user.username}' + cmd += ['--', user.username] try: - self.arch_chroot(cmd) - except SysCallError as err: + run(cmd) + except CalledProcessError as err: + debug(f'Error creating user {user.username}: {err}') raise SystemError(f'Could not create user inside installation: {err}') for plugin in plugins.values(): @@ -1942,7 +1930,11 @@ def _create_user(self, user: User) -> None: self.set_user_password(user) for group in user.groups: - self.arch_chroot(f'gpasswd -a {user.username} {group}') + cmd = self._chroot_argv('gpasswd', '-a', user.username, group) + try: + run(cmd) + except CalledProcessError as err: + warn(f'Failed to add {user.username} to group {group}: {err}') if user.sudo: self.enable_sudo(user) @@ -1957,7 +1949,7 @@ def set_user_password(self, user: User) -> bool: return False input_data = f'{user.username}:{enc_password}'.encode() - cmd = ['arch-chroot', '-S', str(self.target), 'chpasswd', '--encrypted'] + cmd = self._chroot_argv('chpasswd', '--encrypted') try: run(cmd, input_data=input_data) @@ -1969,7 +1961,7 @@ def set_user_password(self, user: User) -> bool: def user_set_shell(self, user: str, shell: str) -> bool: info(f'Setting shell for {user} to {shell}') - cmd = ['arch-chroot', '-S', str(self.target), 'chsh', '-s', shell, user] + cmd = self._chroot_argv('chsh', '-s', shell, user) try: run(cmd) return True @@ -1979,7 +1971,7 @@ def user_set_shell(self, user: str, shell: str) -> bool: def chown(self, owner: str, path: str, options: list[str] | None = None) -> bool: options = options or [] - cmd = ['arch-chroot', '-S', str(self.target), 'chown', *options, owner, path] + cmd = self._chroot_argv('chown', *options, '--', owner, path) try: run(cmd) return True