From 296ce3ad89ed5129f34dce5b314d37d9d128e402 Mon Sep 17 00:00:00 2001 From: aameen-tulip <98349328+aameen-tulip@users.noreply.github.com> Date: Tue, 26 Apr 2022 15:56:27 -0500 Subject: [PATCH] Permit users to set uname info This allows users on multi-arch systems to explicitly set their architecture in their environment. Overriding `ARCH` is necessary for systems which run without a `uname` binary which has been extended to "lie" about the system's architecture in different contexts. For example on a multi-arch build system `mongo` may be running in an execution mode which differs from the host execution mode; currently you either have to modify `mongo` or patch `uname` to "lie" in order to get the desired `ARCH`. This change doesn't require a patched `mongo` or `uname` binary. Ex: ``` PATH="/usr/local/opt/gnu-coreutils/bin${PATH+:$PATH}" ARCH=x86_64; export PATH ARCH; /usr/bin/arch -x86_64 ~/.meteor/packages/meteor-tool/2.5.6/mt-os.osx.x86_64/meteor ARGS...; ``` For context `gnu-coreutils`'s `uname` is agnostic to the effects of `arch -x86_64` and would output `arm64` in this case when we actually want `x86_64`. --- meteor | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/meteor b/meteor index 3ff57c86d6..6c71dff39f 100755 --- a/meteor +++ b/meteor @@ -4,7 +4,12 @@ BUNDLE_VERSION=14.19.1.0 # OS Check. Put here because here is where we download the precompiled # bundles that are arch specific. -UNAME=$(uname) +# Use of : "${ARCH:=$(uname)}" assignment permits users to set their +# architecture manually; this is useful for multi-arch systems whose +# uname executables may sometimes return different architectures in +# different contexts. +# Ex: ARCH=arm64 meteor ARGS...; +UNAME="$(uname)" if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then echo "Sorry, this OS is not supported." exit 1 @@ -12,7 +17,7 @@ fi if [ "$UNAME" = "Darwin" ] ; then if [ "arm64" == "$(uname -m)" ]; then - ARCH="arm64" + : "${ARCH:=arm64}" else if [ "i386" != "$(uname -p)" -o "1" != "$(sysctl -n hw.cpu64bit_capable 2>/dev/null || echo 0)" ] ; then @@ -21,10 +26,10 @@ if [ "$UNAME" = "Darwin" ] ; then echo "Only 64-bit and arm64 processors are supported at this time." exit 1 fi - ARCH="x86_64" + : "${ARCH:=x86_64}" fi elif [ "$UNAME" = "Linux" ] ; then - ARCH="$(uname -m)" + : "${ARCH:=$(uname -m)}" if [ "$ARCH" != "x86_64" ] ; then echo "Unsupported architecture: $ARCH" echo "Meteor only supports x86_64"