Skip to content
Merged
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
4 changes: 3 additions & 1 deletion archinstall/lib/authentication/authentication_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def _configure_u2f_mapping(
Tui.print(tr('Setting up U2F device for user: {}').format(user.username))
Tui.print(tr('You may need to enter the PIN and then touch your U2F device to register it'))

cmd = ' '.join(['arch-chroot', str(install_session.target), 'pamu2fcfg', '-u', user.username, '-o', f'pam://{hostname}', '-i', f'pam://{hostname}'])
cmd = ' '.join(
['arch-chroot', '-S', str(install_session.target), 'pamu2fcfg', '-u', user.username, '-o', f'pam://{hostname}', '-i', f'pam://{hostname}']
)

debug(f'Enrolling U2F device: {cmd}')

Expand Down
46 changes: 24 additions & 22 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def set_locale(self, locale_config: LocaleConfiguration) -> bool:
return False

try:
SysCommand(f'arch-chroot {self.target} locale-gen')
self.arch_chroot('locale-gen')
except SysCallError as e:
error(f'Failed to run locale-gen on target: {e}')
return False
Expand All @@ -638,7 +638,7 @@ def set_timezone(self, zone: str) -> bool:

if (Path('/usr') / 'share' / 'zoneinfo' / zone).exists():
(Path(self.target) / 'etc' / 'localtime').unlink(missing_ok=True)
SysCommand(f'arch-chroot {self.target} ln -s /usr/share/zoneinfo/{zone} /etc/localtime')
self.arch_chroot(f'ln -s /usr/share/zoneinfo/{zone} /etc/localtime')
return True

else:
Expand Down Expand Up @@ -675,14 +675,14 @@ def enable_service(self, services: str | list[str]) -> None:
if hasattr(plugin, 'on_service'):
plugin.on_service(service)

def run_command(self, cmd: str, *args: str, **kwargs: str) -> SysCommand:
return SysCommand(f'arch-chroot {self.target} {cmd}')
def run_command(self, cmd: str, peek_output: bool = False) -> SysCommand:
return SysCommand(f'arch-chroot -S {self.target} {cmd}', peek_output=peek_output)

def arch_chroot(self, cmd: str, run_as: str | None = None) -> SysCommand:
def arch_chroot(self, cmd: str, run_as: str | None = None, peek_output: bool = False) -> SysCommand:
if run_as:
cmd = f'su - {run_as} -c {shlex.quote(cmd)}'

return self.run_command(cmd)
return self.run_command(cmd, peek_output=peek_output)

def drop_to_shell(self) -> None:
subprocess.check_call(f'arch-chroot {self.target}', shell=True)
Expand Down Expand Up @@ -782,7 +782,7 @@ def mkinitcpio(self, flags: list[str]) -> bool:
mkinit.write(content)

try:
SysCommand(f'arch-chroot {self.target} mkinitcpio {" ".join(flags)}', peek_output=True)
self.arch_chroot(f'mkinitcpio {" ".join(flags)}', peek_output=True)
return True
except SysCallError as e:
if e.worker_log:
Expand Down Expand Up @@ -894,7 +894,7 @@ def minimal_installation(
self.set_keyboard_language(locale_config.kb_layout)

# TODO: Use python functions for this
SysCommand(f'arch-chroot {self.target} chmod 700 /root')
self.arch_chroot('chmod 700 /root')

if mkinitcpio and not self.mkinitcpio(['-P']):
error('Error generating initramfs (continuing anyway)')
Expand Down Expand Up @@ -927,6 +927,7 @@ def setup_btrfs_snapshot(
for config_name, mountpoint in snapper.items():
command = [
'arch-chroot',
'-S',
str(self.target),
'snapper',
'--no-dbus',
Expand Down Expand Up @@ -1207,15 +1208,15 @@ def _add_systemd_bootloader(
# as a container environemnt since v257 and skips them silently.
# https://github.com/systemd/systemd/issues/36174
if systemd_version >= '258':
SysCommand(f'arch-chroot {self.target} bootctl --variables=yes {" ".join(bootctl_options)} install')
self.arch_chroot(f'bootctl --variables=yes {" ".join(bootctl_options)} install')
else:
SysCommand(f'arch-chroot {self.target} bootctl {" ".join(bootctl_options)} install')
self.arch_chroot(f'bootctl {" ".join(bootctl_options)} install')
except SysCallError:
if systemd_version >= '258':
# Fallback, try creating the boot loader without touching the EFI variables
SysCommand(f'arch-chroot {self.target} bootctl --variables=no {" ".join(bootctl_options)} install')
self.arch_chroot(f'bootctl --variables=no {" ".join(bootctl_options)} install')
else:
SysCommand(f'arch-chroot {self.target} bootctl --no-variables {" ".join(bootctl_options)} install')
self.arch_chroot(f'bootctl --no-variables {" ".join(bootctl_options)} install')

# Loader configuration is stored in ESP/loader:
# https://man.archlinux.org/man/loader.conf.5
Expand Down Expand Up @@ -1277,6 +1278,7 @@ def _add_grub_bootloader(

command = [
'arch-chroot',
'-S',
str(self.target),
'grub-install',
'--debug',
Expand Down Expand Up @@ -1329,8 +1331,8 @@ def _add_grub_bootloader(
raise DiskError(f'Failed to install GRUB boot on {boot_partition.dev_path}: {err}')

try:
SysCommand(
f'arch-chroot {self.target} grub-mkconfig -o {boot_dir}/grub/grub.cfg',
self.arch_chroot(
f'grub-mkconfig -o {boot_dir}/grub/grub.cfg',
)
except SysCallError as err:
raise DiskError(f'Could not configure GRUB: {err}')
Expand Down Expand Up @@ -1439,7 +1441,7 @@ def _add_limine_bootloader(
shutil.copy(limine_path / 'limine-bios.sys', boot_limine_path)

# `limine bios-install` deploys the stage 1 and 2 to the
SysCommand(f'arch-chroot {self.target} limine bios-install {parent_dev_path}', peek_output=True)
self.arch_chroot(f'limine bios-install {parent_dev_path}', peek_output=True)
except Exception as err:
raise DiskError(f'Failed to install Limine on {parent_dev_path}: {err}')

Expand Down Expand Up @@ -1697,15 +1699,15 @@ def _create_user(self, user: User) -> None:
if not handled_by_plugin:
info(f'Creating user {user.username}')

cmd = f'arch-chroot {self.target} useradd -m'
cmd = 'useradd -m'

if user.sudo:
cmd += ' -G wheel'

cmd += f' {user.username}'

try:
SysCommand(cmd)
self.arch_chroot(cmd)
except SysCallError as err:
raise SystemError(f'Could not create user inside installation: {err}')

Expand All @@ -1717,7 +1719,7 @@ def _create_user(self, user: User) -> None:
self.set_user_password(user)

for group in user.groups:
SysCommand(f'arch-chroot {self.target} gpasswd -a {user.username} {group}')
self.arch_chroot(f'gpasswd -a {user.username} {group}')

if user.sudo:
self.enable_sudo(user)
Expand All @@ -1732,7 +1734,7 @@ def set_user_password(self, user: User) -> bool:
return False

input_data = f'{user.username}:{enc_password}'.encode()
cmd = ['arch-chroot', str(self.target), 'chpasswd', '--encrypted']
cmd = ['arch-chroot', '-S', str(self.target), 'chpasswd', '--encrypted']

try:
run(cmd, input_data=input_data)
Expand All @@ -1745,15 +1747,15 @@ def user_set_shell(self, user: str, shell: str) -> bool:
info(f'Setting shell for {user} to {shell}')

try:
SysCommand(f'arch-chroot {self.target} sh -c "chsh -s {shell} {user}"')
self.arch_chroot(f'sh -c "chsh -s {shell} {user}"')
return True
except SysCallError:
return False

def chown(self, owner: str, path: str, options: list[str] = []) -> bool:
cleaned_path = path.replace("'", "\\'")
try:
SysCommand(f"arch-chroot {self.target} sh -c 'chown {' '.join(options)} {owner} {cleaned_path}'")
self.arch_chroot(f"sh -c 'chown {' '.join(options)} {owner} {cleaned_path}'")
return True
except SysCallError:
return False
Expand Down Expand Up @@ -1851,6 +1853,6 @@ def run_custom_user_commands(commands: list[str], installation: Installer) -> No
with open(chroot_path, 'w') as user_script:
user_script.write(command)

SysCommand(f'arch-chroot {installation.target} bash {script_path}')
SysCommand(f'arch-chroot -S {installation.target} bash {script_path}')

os.unlink(chroot_path)