@@ -617,7 +617,7 @@ def set_locale(self, locale_config: LocaleConfiguration) -> bool:
617617 return False
618618
619619 try :
620- SysCommand ( f'arch-chroot { self .target } locale-gen' )
620+ self .arch_chroot ( ' locale-gen' )
621621 except SysCallError as e :
622622 error (f'Failed to run locale-gen on target: { e } ' )
623623 return False
@@ -638,7 +638,7 @@ def set_timezone(self, zone: str) -> bool:
638638
639639 if (Path ('/usr' ) / 'share' / 'zoneinfo' / zone ).exists ():
640640 (Path (self .target ) / 'etc' / 'localtime' ).unlink (missing_ok = True )
641- SysCommand (f'arch-chroot { self . target } ln -s /usr/share/zoneinfo/{ zone } /etc/localtime' )
641+ self . arch_chroot (f'ln -s /usr/share/zoneinfo/{ zone } /etc/localtime' )
642642 return True
643643
644644 else :
@@ -675,14 +675,14 @@ def enable_service(self, services: str | list[str]) -> None:
675675 if hasattr (plugin , 'on_service' ):
676676 plugin .on_service (service )
677677
678- def run_command (self , cmd : str , * args : str , ** kwargs : str ) -> SysCommand :
679- return SysCommand (f'arch-chroot { self .target } { cmd } ' )
678+ def run_command (self , cmd : str , peek_output : bool = False ) -> SysCommand :
679+ return SysCommand (f'arch-chroot -S { self .target } { cmd } ' , peek_output = peek_output )
680680
681- def arch_chroot (self , cmd : str , run_as : str | None = None ) -> SysCommand :
681+ def arch_chroot (self , cmd : str , run_as : str | None = None , peek_output : bool = False ) -> SysCommand :
682682 if run_as :
683683 cmd = f'su - { run_as } -c { shlex .quote (cmd )} '
684684
685- return self .run_command (cmd )
685+ return self .run_command (cmd , peek_output = peek_output )
686686
687687 def drop_to_shell (self ) -> None :
688688 subprocess .check_call (f'arch-chroot { self .target } ' , shell = True )
@@ -782,7 +782,7 @@ def mkinitcpio(self, flags: list[str]) -> bool:
782782 mkinit .write (content )
783783
784784 try :
785- SysCommand (f'arch-chroot { self . target } mkinitcpio { " " .join (flags )} ' , peek_output = True )
785+ self . arch_chroot (f'mkinitcpio { " " .join (flags )} ' , peek_output = True )
786786 return True
787787 except SysCallError as e :
788788 if e .worker_log :
@@ -894,7 +894,7 @@ def minimal_installation(
894894 self .set_keyboard_language (locale_config .kb_layout )
895895
896896 # TODO: Use python functions for this
897- SysCommand ( f'arch-chroot { self .target } chmod 700 /root' )
897+ self .arch_chroot ( ' chmod 700 /root' )
898898
899899 if mkinitcpio and not self .mkinitcpio (['-P' ]):
900900 error ('Error generating initramfs (continuing anyway)' )
@@ -927,6 +927,7 @@ def setup_btrfs_snapshot(
927927 for config_name , mountpoint in snapper .items ():
928928 command = [
929929 'arch-chroot' ,
930+ '-S' ,
930931 str (self .target ),
931932 'snapper' ,
932933 '--no-dbus' ,
@@ -1207,15 +1208,15 @@ def _add_systemd_bootloader(
12071208 # as a container environemnt since v257 and skips them silently.
12081209 # https://github.com/systemd/systemd/issues/36174
12091210 if systemd_version >= '258' :
1210- SysCommand (f'arch-chroot { self . target } bootctl --variables=yes { " " .join (bootctl_options )} install' )
1211+ self . arch_chroot (f'bootctl --variables=yes { " " .join (bootctl_options )} install' )
12111212 else :
1212- SysCommand (f'arch-chroot { self . target } bootctl { " " .join (bootctl_options )} install' )
1213+ self . arch_chroot (f'bootctl { " " .join (bootctl_options )} install' )
12131214 except SysCallError :
12141215 if systemd_version >= '258' :
12151216 # Fallback, try creating the boot loader without touching the EFI variables
1216- SysCommand (f'arch-chroot { self . target } bootctl --variables=no { " " .join (bootctl_options )} install' )
1217+ self . arch_chroot (f'bootctl --variables=no { " " .join (bootctl_options )} install' )
12171218 else :
1218- SysCommand (f'arch-chroot { self . target } bootctl --no-variables { " " .join (bootctl_options )} install' )
1219+ self . arch_chroot (f'bootctl --no-variables { " " .join (bootctl_options )} install' )
12191220
12201221 # Loader configuration is stored in ESP/loader:
12211222 # https://man.archlinux.org/man/loader.conf.5
@@ -1277,6 +1278,7 @@ def _add_grub_bootloader(
12771278
12781279 command = [
12791280 'arch-chroot' ,
1281+ '-S' ,
12801282 str (self .target ),
12811283 'grub-install' ,
12821284 '--debug' ,
@@ -1329,8 +1331,8 @@ def _add_grub_bootloader(
13291331 raise DiskError (f'Failed to install GRUB boot on { boot_partition .dev_path } : { err } ' )
13301332
13311333 try :
1332- SysCommand (
1333- f'arch-chroot { self . target } grub-mkconfig -o { boot_dir } /grub/grub.cfg' ,
1334+ self . arch_chroot (
1335+ f'grub-mkconfig -o { boot_dir } /grub/grub.cfg' ,
13341336 )
13351337 except SysCallError as err :
13361338 raise DiskError (f'Could not configure GRUB: { err } ' )
@@ -1439,7 +1441,7 @@ def _add_limine_bootloader(
14391441 shutil .copy (limine_path / 'limine-bios.sys' , boot_limine_path )
14401442
14411443 # `limine bios-install` deploys the stage 1 and 2 to the
1442- SysCommand (f'arch-chroot { self . target } limine bios-install { parent_dev_path } ' , peek_output = True )
1444+ self . arch_chroot (f'limine bios-install { parent_dev_path } ' , peek_output = True )
14431445 except Exception as err :
14441446 raise DiskError (f'Failed to install Limine on { parent_dev_path } : { err } ' )
14451447
@@ -1697,15 +1699,15 @@ def _create_user(self, user: User) -> None:
16971699 if not handled_by_plugin :
16981700 info (f'Creating user { user .username } ' )
16991701
1700- cmd = f'arch-chroot { self . target } useradd -m'
1702+ cmd = ' useradd -m'
17011703
17021704 if user .sudo :
17031705 cmd += ' -G wheel'
17041706
17051707 cmd += f' { user .username } '
17061708
17071709 try :
1708- SysCommand (cmd )
1710+ self . arch_chroot (cmd )
17091711 except SysCallError as err :
17101712 raise SystemError (f'Could not create user inside installation: { err } ' )
17111713
@@ -1717,7 +1719,7 @@ def _create_user(self, user: User) -> None:
17171719 self .set_user_password (user )
17181720
17191721 for group in user .groups :
1720- SysCommand (f'arch-chroot { self . target } gpasswd -a { user .username } { group } ' )
1722+ self . arch_chroot (f'gpasswd -a { user .username } { group } ' )
17211723
17221724 if user .sudo :
17231725 self .enable_sudo (user )
@@ -1732,7 +1734,7 @@ def set_user_password(self, user: User) -> bool:
17321734 return False
17331735
17341736 input_data = f'{ user .username } :{ enc_password } ' .encode ()
1735- cmd = ['arch-chroot' , str (self .target ), 'chpasswd' , '--encrypted' ]
1737+ cmd = ['arch-chroot' , '-S' , str (self .target ), 'chpasswd' , '--encrypted' ]
17361738
17371739 try :
17381740 run (cmd , input_data = input_data )
@@ -1745,15 +1747,15 @@ def user_set_shell(self, user: str, shell: str) -> bool:
17451747 info (f'Setting shell for { user } to { shell } ' )
17461748
17471749 try :
1748- SysCommand (f'arch-chroot { self . target } sh -c "chsh -s { shell } { user } "' )
1750+ self . arch_chroot (f'sh -c "chsh -s { shell } { user } "' )
17491751 return True
17501752 except SysCallError :
17511753 return False
17521754
17531755 def chown (self , owner : str , path : str , options : list [str ] = []) -> bool :
17541756 cleaned_path = path .replace ("'" , "\\ '" )
17551757 try :
1756- SysCommand (f"arch-chroot { self . target } sh -c 'chown { ' ' .join (options )} { owner } { cleaned_path } '" )
1758+ self . arch_chroot (f"sh -c 'chown { ' ' .join (options )} { owner } { cleaned_path } '" )
17571759 return True
17581760 except SysCallError :
17591761 return False
@@ -1851,6 +1853,6 @@ def run_custom_user_commands(commands: list[str], installation: Installer) -> No
18511853 with open (chroot_path , 'w' ) as user_script :
18521854 user_script .write (command )
18531855
1854- SysCommand (f'arch-chroot { installation .target } bash { script_path } ' )
1856+ SysCommand (f'arch-chroot -S { installation .target } bash { script_path } ' )
18551857
18561858 os .unlink (chroot_path )
0 commit comments