Revert "pmb.sideload: adapt sideload to support both doas and sudo (MR 2400)" (MR 2403)

This reverts commit 099a774190.
This commit is contained in:
Caleb Connolly 2024-09-18 13:49:46 +02:00
parent 0478c30e5c
commit 431f6ea14f
No known key found for this signature in database
GPG key ID: 7930459FB9303217

View file

@ -15,13 +15,12 @@ import pmb.build
from pmb.core.context import get_context from pmb.core.context import get_context
def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str, su: str) -> None: def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str) -> None:
"""Copy the building key of the local installation to the target device, """Copy the building key of the local installation to the target device,
so it trusts the apks that were signed here. so it trusts the apks that were signed here.
:param user: target device ssh username :param user: target device ssh username
:param host: target device ssh hostname :param host: target device ssh hostname
:param port: target device ssh port :param port: target device ssh port"""
:param su: target device su binary"""
keys = list((get_context().config.work / "config_abuild").glob("*.pub")) keys = list((get_context().config.work / "config_abuild").glob("*.pub"))
key = keys[0] key = keys[0]
@ -34,7 +33,10 @@ def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str, su: str) -> N
logging.info(f"Installing signing key at {user}@{host}") logging.info(f"Installing signing key at {user}@{host}")
keyname = os.path.join("/tmp", os.path.basename(key)) keyname = os.path.join("/tmp", os.path.basename(key))
remote_cmd_l: list[PathString] = [ remote_cmd_l: list[PathString] = [
su, "sudo",
"-p",
pmb.config.sideload_sudo_prompt,
"-S",
"mv", "mv",
"-n", "-n",
keyname, keyname,
@ -45,24 +47,6 @@ def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str, su: str) -> N
pmb.helpers.run.user(command, output="tui") pmb.helpers.run.user(command, output="tui")
def ssh_find_su(args: PmbArgs, user: str, host: str, port: str) -> str:
"""Connect to a device via ssh and query the su binary."""
logging.info(f"Querying su binary of {user}@{host}")
query_doas = shlex.quote("which doas || true")
query_sudo = shlex.quote("which sudo || true")
command_doas = ["ssh", "-p", port, f"{user}@{host}", f"sh -c {query_doas}"]
command_sudo = ["ssh", "-p", port, f"{user}@{host}", f"sh -c {query_sudo}"]
output_doas = pmb.helpers.run.user_output(command_doas)
output_sudo = pmb.helpers.run.user_output(command_sudo)
if output_doas != "":
return "doas"
elif output_sudo != "":
return "sudo"
else:
logging.error('ERROR: Failed to find supported su binary (tried "doas" and "sudo")')
return "error"
def ssh_find_arch(args: PmbArgs, user: str, host: str, port: str) -> Arch: def ssh_find_arch(args: PmbArgs, user: str, host: str, port: str) -> Arch:
"""Connect to a device via ssh and query the architecture.""" """Connect to a device via ssh and query the architecture."""
logging.info(f"Querying architecture of {user}@{host}") logging.info(f"Querying architecture of {user}@{host}")
@ -80,12 +64,11 @@ def ssh_find_arch(args: PmbArgs, user: str, host: str, port: str) -> Arch:
return alpine_architecture return alpine_architecture
def ssh_install_apks(args: PmbArgs, user, host, port, su: str, paths: list) -> None: def ssh_install_apks(args: PmbArgs, user, host, port, paths: list) -> None:
"""Copy binary packages via SCP and install them via SSH. """Copy binary packages via SCP and install them via SSH.
:param user: target device ssh username :param user: target device ssh username
:param host: target device ssh hostname :param host: target device ssh hostname
:param port: target device ssh port :param port: target device ssh port
:param su: target device su binary
:param paths: list of absolute paths to locally stored apks :param paths: list of absolute paths to locally stored apks
""" """
@ -99,7 +82,10 @@ def ssh_install_apks(args: PmbArgs, user, host, port, su: str, paths: list) -> N
logging.info(f"Installing packages at {user}@{host}") logging.info(f"Installing packages at {user}@{host}")
add_cmd = [ add_cmd = [
su, "sudo",
"-p",
pmb.config.sideload_sudo_prompt,
"-S",
"apk", "apk",
"--wait", "--wait",
"30", "30",
@ -131,8 +117,6 @@ def sideload(
if arch is None: if arch is None:
arch = ssh_find_arch(args, user, host, port) arch = ssh_find_arch(args, user, host, port)
su = ssh_find_su(args, user, host, port)
context = get_context() context = get_context()
to_build = [] to_build = []
for pkgname in pkgnames: for pkgname in pkgnames:
@ -152,6 +136,6 @@ def sideload(
raise RuntimeError(f"The package '{pkgname}' could not be built") raise RuntimeError(f"The package '{pkgname}' could not be built")
if copy_key: if copy_key:
scp_abuild_key(args, user, host, port, su) scp_abuild_key(args, user, host, port)
ssh_install_apks(args, user, host, port, su, paths) ssh_install_apks(args, user, host, port, paths)