From b0ded94ca9950397eb8d7737632d820f509fd742 Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Wed, 12 Jun 2024 19:36:48 +0200 Subject: [PATCH] chroot: run: multi-commands for user (MR 2252) Signed-off-by: Caleb Connolly --- pmb/chroot/__init__.py | 2 +- pmb/chroot/run.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pmb/chroot/__init__.py b/pmb/chroot/__init__.py index 306685e0..83c061bd 100644 --- a/pmb/chroot/__init__.py +++ b/pmb/chroot/__init__.py @@ -2,6 +2,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later from pmb.chroot.init import init, init_keys, UsrMerge from pmb.chroot.mount import mount, mount_native_into_foreign, remove_mnt_pmbootstrap -from pmb.chroot.run import root, rootm, user, exists as user_exists +from pmb.chroot.run import root, rootm, user, userm, exists as user_exists from pmb.chroot.shutdown import shutdown from pmb.chroot.zap import zap diff --git a/pmb/chroot/run.py b/pmb/chroot/run.py index 38668fc7..604990e5 100644 --- a/pmb/chroot/run.py +++ b/pmb/chroot/run.py @@ -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