1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-24 21:15:10 +03:00

remove sudo wrapper

we are already root now thanks to user namespaces 😎

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
This commit is contained in:
Casey Connolly 2025-04-23 18:41:52 +02:00
parent 7c6df10861
commit 4ca57db3f0
No known key found for this signature in database
GPG key ID: 0583312B195F64B6
4 changed files with 2 additions and 62 deletions

View file

@ -78,26 +78,16 @@ def rootm(
# Build the command in steps and run it, e.g.:
# cmd: ["echo", "test"]
# cmd_chroot: ["/sbin/chroot", "/..._native", "/bin/sh", "-c", "echo test"]
# cmd_sudo: ["sudo", "env", "-i", "sh", "-c", "PATH=... /sbin/chroot ..."]
executables = pmb.config.required_programs
cmd_chroot: list[PathString] = [
executables["chroot"],
chroot.path,
"/bin/sh",
"-c",
pmb.helpers.run_core.flat_cmd(cmd_strs, Path(working_dir)),
pmb.helpers.run_core.flat_cmd(cmd_strs, Path(working_dir), env=env_all),
]
cmd_sudo = pmb.config.sudo(
[
"env",
"-i",
executables["sh"],
"-c",
pmb.helpers.run_core.flat_cmd([cmd_chroot], env=env_all),
]
)
return pmb.helpers.run_core.core(
msg, cmd_sudo, None, output, output_return, check, True, disable_timeout
msg, cmd_chroot, None, output, output_return, check, True, disable_timeout
)

View file

@ -12,7 +12,6 @@ from collections.abc import Sequence
# FIXME (#2324): this sucks, we should re-organise this and not rely on "lifting"
# this functions this way
from pmb.config.file import load as load, save as save, serialize as serialize
from pmb.config.sudo import which_sudo
from pmb.config.other import is_systemd_selected as is_systemd_selected
from .init import require_programs as require_programs
from . import workdir as workdir
@ -72,16 +71,6 @@ required_programs: dict[str, str] = {
"sh": "",
}
def sudo(cmd: Sequence[PathString]) -> Sequence[PathString]:
"""Adapt a command to run as root."""
sudo = which_sudo()
if sudo:
return [sudo, *cmd]
else:
return cmd
defaults: dict[str, PathString] = {
"cipher": "aes-xts-plain64",
"config": Path(

View file

@ -1,38 +0,0 @@
# Copyright 2023 Anjandev Momi
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import shutil
from functools import lru_cache
@lru_cache
def which_sudo() -> str | None:
"""Return a command required to run commands as root, if any.
Find whether sudo or doas is installed for commands that require root.
Allows user to override preferred sudo with PMB_SUDO env variable.
"""
if os.getuid() == 0:
return None
supported_sudos = ["doas", "sudo"]
user_set_sudo = os.getenv("PMB_SUDO")
if user_set_sudo is not None:
if shutil.which(user_set_sudo) is None:
raise RuntimeError(
"PMB_SUDO environmental variable is set to"
f" {user_set_sudo} but pmbootstrap cannot find"
" this command on your system."
)
return user_set_sudo
for sudo in supported_sudos:
if shutil.which(sudo) is not None:
return sudo
raise RuntimeError(
"Can't find sudo or doas required to run pmbootstrap."
" Please install sudo, doas, or specify your own sudo"
" with the PMB_SUDO environmental variable."
)

View file

@ -124,6 +124,5 @@ def root(
if env:
cmd = ["sh", "-c", pmb.helpers.run_core.flat_cmd([cmd], env=env)]
cmd = pmb.config.sudo(cmd)
return user(cmd, working_dir, output, output_return, check, env, True)