mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-22 21:25:43 -05:00
wrapper_su_helper.py: inject constants.WRAPPER_ENV_VAR into user env
This commit is contained in:
parent
96ead1ec21
commit
fccd58c533
1 changed files with 4 additions and 1 deletions
|
@ -2,9 +2,11 @@
|
|||
|
||||
import click
|
||||
import pwd
|
||||
import os
|
||||
|
||||
from logger import logging, setup_logging
|
||||
|
||||
from constants import WRAPPER_ENV_VAR
|
||||
from exec.cmd import run_cmd, flatten_shell_script
|
||||
from exec.file import chown
|
||||
|
||||
|
@ -22,7 +24,8 @@ def kupferbootstrap_su(cmd: list[str], uid: int = 1000, username: str = 'kupfer'
|
|||
run_cmd(['usermod', '-u', str(uid), username]).check_returncode() # type: ignore[union-attr]
|
||||
chown(home, username, recursive=False)
|
||||
logging.debug(f'wrapper_su_helper: running {cmd} as {repr(username)}')
|
||||
su_cmd = ['sudo', 'su', '-P', username, '-c', flatten_shell_script(cmd, wrap_in_shell_quote=True, shell_quote_items=True)]
|
||||
env_inject = ['env', f'{WRAPPER_ENV_VAR}={os.environ[WRAPPER_ENV_VAR]}'] if WRAPPER_ENV_VAR in os.environ else []
|
||||
su_cmd = ['sudo', *env_inject, 'su', '-P', username, '-c', flatten_shell_script(cmd, wrap_in_shell_quote=True, shell_quote_items=True)]
|
||||
result = run_cmd(su_cmd, attach_tty=True)
|
||||
assert isinstance(result, int)
|
||||
exit(result)
|
||||
|
|
Loading…
Add table
Reference in a new issue