From 816ae5ac6c6a45de687a11a8d30dc2069dd8b119 Mon Sep 17 00:00:00 2001
From: Newbyte <newbyte@postmarketos.org>
Date: Sun, 11 Aug 2024 17:10:27 +0200
Subject: [PATCH] pmb.sideload: Run $ uname -m in subshell (MR 2390)

Some shells, in particular Nushell, replace the built-in
POSIX-compatible uname with a custom one that does not support common
flags. I opened an issue in the Nushell repository about this, but it
was rejected on the grounds that POSIX compatibility is not a goal. As
such, run this in a subshell to ensure that we get the expected uname
interface.

Nushell issue: https://github.com/nushell/nushell/issues/12570
---
 pmb/sideload/__init__.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/pmb/sideload/__init__.py b/pmb/sideload/__init__.py
index 1b5ada938..1f246e6f2 100644
--- a/pmb/sideload/__init__.py
+++ b/pmb/sideload/__init__.py
@@ -50,7 +50,10 @@ def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str) -> None:
 def ssh_find_arch(args: PmbArgs, user: str, host: str, port: str) -> Arch:
     """Connect to a device via ssh and query the architecture."""
     logging.info(f"Querying architecture of {user}@{host}")
-    command = ["ssh", "-p", port, f"{user}@{host}", "uname -m"]
+    # Run command in a subshell in case the foreign device has a weird uname
+    # implementation, e.g. Nushell.
+    architecture_cmd = shlex.quote("uname -m")
+    command = ["ssh", "-p", port, f"{user}@{host}", f"sh -c {architecture_cmd}"]
     output = pmb.helpers.run.user_output(command)
     # Split by newlines so we can pick out any irrelevant output, e.g. the "permanently
     # added to list of known hosts" warnings.
-- 
GitLab