pmb.sideload: Remove irrelevant output when querying architecture (MR 2286)

Previously, if this was the first time you were connecting to a device,
the output of the ssh command would contain a warning about that the
host was added to the list of trusted hosts. This causes problems as
this gets included in the output where the code previously expected the
string-representation of the architecture to be.

As such, remove the irrelevant output by splitting it into lines and
only using the last line as we assume ssh won't print anything after the
actual output of the invoked command.

Closes https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2335
[ci:skip-build]: already built successfully in CI
This commit is contained in:
Newbyte 2024-04-01 22:21:16 +02:00
parent 1d515f9389
commit c73e439d0a
No known key found for this signature in database
GPG Key ID: 8A700086A9FE41FD
1 changed files with 5 additions and 1 deletions

View File

@ -43,7 +43,11 @@ def ssh_find_arch(args: Namespace, user: str, host: str, port: str) -> str:
logging.info(f"Querying architecture of {user}@{host}")
command = ["ssh", "-p", port, f"{user}@{host}", "uname -m"]
output = pmb.helpers.run.user(args, command, output_return=True)
foreign_machine_type = output.strip() # Remove newline from output
# Split by newlines so we can pick out any irrelevant output, e.g. the "permanently
# added to list of known hosts" warnings.
output_lines = output.strip().splitlines()
# Pick out last line which should contain the foreign device's architecture
foreign_machine_type = output_lines[-1]
alpine_architecture = pmb.parse.arch.machine_type_to_alpine(foreign_machine_type)
return alpine_architecture