sideload: support doas (MR 2403)

Fall back to doas if sudo is not available.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-09-18 14:01:21 +02:00
parent 431f6ea14f
commit a79e52feeb
No known key found for this signature in database
GPG key ID: 7930459FB9303217

View file

@ -14,6 +14,8 @@ import pmb.config.pmaports
import pmb.build
from pmb.core.context import get_context
su_cmd = "_su=$(command -v sudo >/dev/null && echo sudo || echo doas); $_su"
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,
@ -33,17 +35,14 @@ def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str) -> None:
logging.info(f"Installing signing key at {user}@{host}")
keyname = os.path.join("/tmp", os.path.basename(key))
remote_cmd_l: list[PathString] = [
"sudo",
"-p",
pmb.config.sideload_sudo_prompt,
"-S",
"mv",
"-n",
keyname,
"/etc/apk/keys/",
]
remote_cmd = pmb.helpers.run_core.flat_cmd([remote_cmd_l])
command = ["ssh", "-t", "-p", port, f"{user}@{host}", remote_cmd]
full_cmd = shlex.quote(f"{su_cmd} {remote_cmd}")
command = ["ssh", "-t", "-p", port, f"{user}@{host}", f"sh -c {full_cmd}"]
pmb.helpers.run.user(command, output="tui")
@ -82,10 +81,6 @@ def ssh_install_apks(args: PmbArgs, user, host, port, paths: list) -> None:
logging.info(f"Installing packages at {user}@{host}")
add_cmd = [
"sudo",
"-p",
pmb.config.sideload_sudo_prompt,
"-S",
"apk",
"--wait",
"30",
@ -93,7 +88,7 @@ def ssh_install_apks(args: PmbArgs, user, host, port, paths: list) -> None:
] + remote_paths
add_cmd = pmb.helpers.run_core.flat_cmd([add_cmd])
clean_cmd = pmb.helpers.run_core.flat_cmd([["rm"] + remote_paths])
add_cmd_complete = shlex.quote(f"{add_cmd} rc=$?; {clean_cmd} exit $rc")
add_cmd_complete = shlex.quote(f"{su_cmd} {add_cmd} rc=$?; {clean_cmd} exit $rc")
# Run apk command in a subshell in case the foreign device has a non-POSIX shell.
command = ["ssh", "-t", "-p", port, f"{user}@{host}", f"sh -c {add_cmd_complete}"]
pmb.helpers.run.user(command, output="tui")