mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 13:45:45 -05:00
Chroot.run_cmd(): add user
parameter
This commit is contained in:
parent
064f265247
commit
d277d926fd
1 changed files with 5 additions and 1 deletions
|
@ -214,6 +214,7 @@ class Chroot(AbstractChroot):
|
||||||
def run_cmd(
|
def run_cmd(
|
||||||
self,
|
self,
|
||||||
script: Union[str, list[str]],
|
script: Union[str, list[str]],
|
||||||
|
user: str = 'root',
|
||||||
inner_env: dict[str, str] = {},
|
inner_env: dict[str, str] = {},
|
||||||
outer_env: dict[str, str] = os.environ.copy() | {'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'},
|
outer_env: dict[str, str] = os.environ.copy() | {'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'},
|
||||||
attach_tty: bool = False,
|
attach_tty: bool = False,
|
||||||
|
@ -227,6 +228,7 @@ class Chroot(AbstractChroot):
|
||||||
if outer_env is None:
|
if outer_env is None:
|
||||||
outer_env = os.environ.copy()
|
outer_env = os.environ.copy()
|
||||||
env_cmd = ['/usr/bin/env'] + [f'{shell_quote(key)}={shell_quote(value)}' for key, value in inner_env.items()]
|
env_cmd = ['/usr/bin/env'] + [f'{shell_quote(key)}={shell_quote(value)}' for key, value in inner_env.items()]
|
||||||
|
su_cmd = []
|
||||||
kwargs: dict = {
|
kwargs: dict = {
|
||||||
'env': outer_env,
|
'env': outer_env,
|
||||||
}
|
}
|
||||||
|
@ -237,7 +239,9 @@ class Chroot(AbstractChroot):
|
||||||
script = ' '.join(script)
|
script = ' '.join(script)
|
||||||
if cwd:
|
if cwd:
|
||||||
script = f"cd {shell_quote(cwd)} && ( {script} )"
|
script = f"cd {shell_quote(cwd)} && ( {script} )"
|
||||||
cmd = ['chroot', self.path] + env_cmd + [
|
if user != 'root':
|
||||||
|
su_cmd = ['su', user, '--']
|
||||||
|
cmd = ['chroot', self.path] + su_cmd + env_cmd + [
|
||||||
'/bin/bash',
|
'/bin/bash',
|
||||||
'-c',
|
'-c',
|
||||||
script,
|
script,
|
||||||
|
|
Loading…
Add table
Reference in a new issue