mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 09:35:54 +02:00
jw.pkg.cmds.distro.backend.BackendCmd: Add sudo(opts)
Prepending --login to the argument list of BackendCmd.sudo() fails if run as root, because BackendCmd.sudo() detects that and leaves the /usr/bin/sudo out from the exec call. Fix that by adding an opts: list[str] parameter to sudo, defaulting to an empty list, with options that should be passed to /usr/bin/sudo. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
cc8dd012b7
commit
0bc06b7c41
2 changed files with 5 additions and 4 deletions
|
|
@ -10,7 +10,7 @@ class BackendCmd:
|
|||
def __init__(self, parent: Cmd):
|
||||
self.__parent = parent
|
||||
|
||||
async def _sudo(self, cmd: list[str], mod_env: dict[str, str] = {}):
|
||||
async def _sudo(self, cmd: list[str], mod_env: dict[str, str] = {}, opts: list[str]=[]):
|
||||
env: dict[str, str]|None = None
|
||||
cmd_input: str|None = None
|
||||
if mod_env:
|
||||
|
|
@ -21,6 +21,7 @@ class BackendCmd:
|
|||
cmdline.append('/usr/bin/sudo')
|
||||
if env is not None:
|
||||
cmdline.append('--preserve-env=' + ','.join(mod_env.keys()))
|
||||
cmdline.extend(opts)
|
||||
cmdline.extend(cmd)
|
||||
if self.interactive:
|
||||
cmd_input = "mode:interactive"
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ class Base(BackendCmd):
|
|||
super().__init__(parent)
|
||||
|
||||
async def zypper(self, *args):
|
||||
# Run sudo --login, because /etc/profile may modify ZYPP_CONF
|
||||
cmd = ['--login', '/usr/bin/zypper']
|
||||
cmd = ['/usr/bin/zypper']
|
||||
if not self.interactive:
|
||||
cmd.extend(['--non-interactive', '--gpg-auto-import-keys', '--no-gpg-checks'])
|
||||
cmd.extend(args)
|
||||
return await self._sudo(cmd)
|
||||
# Run sudo --login in case /etc/profile modifies ZYPP_CONF
|
||||
return await self._sudo(cmd, opts=['--login'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue