diff --git a/pmb/chroot/root.py b/pmb/chroot/root.py index dae392f1..d4037f0b 100644 --- a/pmb/chroot/root.py +++ b/pmb/chroot/root.py @@ -71,8 +71,15 @@ def root(args, cmd, suffix="native", working_dir="/", output="log", executables = executables_absolute_path() cmd_chroot = [executables["chroot"], chroot, "/bin/sh", "-c", pmb.helpers.run.flat_cmd(cmd, working_dir)] - cmd_sudo = ["sudo", "env", "-i", executables["sh"], "-c", - pmb.helpers.run.flat_cmd(cmd_chroot, env=env_all)] + + if "sudo_askpass_program" in args: + cmd_sudo = ["env", f"SUDO_ASKPASS={args.sudo_askpass_program}", + "sudo", "--askpass", "env", "-i", executables["sh"], "-c", + pmb.helpers.run.flat_cmd(cmd_chroot, env=env_all)] + else: + cmd_sudo = ["sudo", "env", "-i", executables["sh"], "-c", + pmb.helpers.run.flat_cmd(cmd_chroot, env=env_all)] + return pmb.helpers.run_core.core(args, msg, cmd_sudo, None, output, output_return, check, True, disable_timeout) diff --git a/pmb/helpers/run.py b/pmb/helpers/run.py index 0d6a7bd3..32e5d59f 100644 --- a/pmb/helpers/run.py +++ b/pmb/helpers/run.py @@ -72,7 +72,18 @@ def root(args, cmd, working_dir=None, output="log", output_return=False, """ if env: cmd = ["sh", "-c", flat_cmd(cmd, env=env)] - cmd = ["sudo"] + cmd + + # fom `man sudo`: + # If the -A (askpass) option + # is specified, a (possibly graphical) helper program is executed to + # read the user's password and output the password to the standard output. + # If the SUDO_ASKPASS environment variable is set, it specifies the path + # to the helper program. + if "sudo_askpass_program" in args: + cmd = ["env", f"SUDO_ASKPASS={args.sudo_askpass_program}", + "sudo", "--askpass"] + cmd + else: + cmd = ["sudo"] + cmd return user(args, cmd, working_dir, output, output_return, check, env, True)