chroot: run: multi-commands for user (MR 2252)

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-12 19:36:48 +02:00 committed by Oliver Smith
parent 0e3386e8f3
commit b0ded94ca9
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 8 additions and 3 deletions

View file

@ -95,7 +95,7 @@ def root(cmds: Sequence[PathString], chroot: Chroot=Chroot.native(), working_dir
disable_timeout, add_proxy_env_vars)
def user(cmd, chroot: Chroot=Chroot.native(), working_dir: Path = Path("/"), output="log",
def userm(cmds: Sequence[Sequence[PathString]], chroot: Chroot=Chroot.native(), working_dir: Path = Path("/"), output="log",
output_return=False, check=None, env={}):
"""
Run a command inside a chroot as "user". We always use the BusyBox
@ -114,13 +114,18 @@ def user(cmd, chroot: Chroot=Chroot.native(), working_dir: Path = Path("/"), out
if "HOME" not in env:
env["HOME"] = "/home/pmos"
flat_cmd = pmb.helpers.run_core.flat_cmd([cmd], env=env)
flat_cmd = pmb.helpers.run_core.flat_cmd(cmds, env=env)
cmd = ["busybox", "su", "pmos", "-c", flat_cmd]
return pmb.chroot.root(cmd, chroot, working_dir, output,
output_return, check, {},
add_proxy_env_vars=False)
def user(cmd: Sequence[PathString], chroot: Chroot=Chroot.native(), working_dir: Path = Path("/"), output="log",
output_return=False, check=None, env={}):
userm([cmd], chroot, working_dir, output, output_return, check, env)
def exists(username, chroot: Chroot=Chroot.native()):
"""
Checks if username exists in the system