mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 13:45:45 -05:00
wrapper_su_helper.py: use su -P
to allocate a pseudo-TTY
This commit is contained in:
parent
57be536781
commit
9f1281f1cb
1 changed files with 4 additions and 8 deletions
|
@ -1,12 +1,11 @@
|
||||||
#!/bin/python3
|
#!/bin/python3
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import os
|
|
||||||
import pwd
|
import pwd
|
||||||
|
|
||||||
from logger import logging, setup_logging
|
from logger import logging, setup_logging
|
||||||
|
|
||||||
from exec.cmd import run_cmd
|
from exec.cmd import run_cmd, flatten_shell_script
|
||||||
from exec.file import chown
|
from exec.file import chown
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,12 +21,9 @@ def kupferbootstrap_su(cmd: list[str], uid: int = 1000, username: str = 'kupfer'
|
||||||
if uid != user.pw_uid:
|
if uid != user.pw_uid:
|
||||||
run_cmd(['usermod', '-u', str(uid), username]).check_returncode() # type: ignore[union-attr]
|
run_cmd(['usermod', '-u', str(uid), username]).check_returncode() # type: ignore[union-attr]
|
||||||
chown(home, username, recursive=False)
|
chown(home, username, recursive=False)
|
||||||
env = os.environ | {
|
logging.debug(f'wrapper_su_helper: running {cmd} as {repr(username)}')
|
||||||
'HOME': home,
|
su_cmd = ['sudo', 'su', '-P', username, '-c', flatten_shell_script(cmd, wrap_in_shell_quote=True, shell_quote_items=True)]
|
||||||
'USER': username,
|
result = run_cmd(su_cmd, attach_tty=True)
|
||||||
}
|
|
||||||
logging.debug(f'wrapper: running {cmd} as {repr(username)}')
|
|
||||||
result = run_cmd(cmd, attach_tty=True, switch_user=username, env=env)
|
|
||||||
assert isinstance(result, int)
|
assert isinstance(result, int)
|
||||||
exit(result)
|
exit(result)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue