Use doas instead of sudo if installed (MR 2091)

Prefer using doas over sudo if both are installed. Let the user override
the sudo tool with PMB_SUDO.
This commit is contained in:
Anjandev Momi 2021-08-08 23:14:39 -04:00 committed by Oliver Smith
parent 2801b5d687
commit c1407f921b
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
8 changed files with 60 additions and 8 deletions

View file

@ -62,7 +62,7 @@ def user(args, cmd, working_dir=None, output="log", output_return=False,
def root(args, cmd, working_dir=None, output="log", output_return=False,
check=None, env={}):
"""
Run a command on the host system as root, with sudo.
Run a command on the host system as root, with sudo or doas.
:param env: dict of environment variables to be passed to the command, e.g.
{"JOBS": "5"}
@ -72,7 +72,7 @@ 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
cmd = [pmb.config.sudo] + cmd
return user(args, cmd, working_dir, output, output_return, check, env,
True)