Skip to content

Commit

Permalink
Merge pull request tfutils#351 from denizgenc/fix_mac_arch_selection
Browse files Browse the repository at this point in the history
Improve `TFENV_ARCH` initialisation for Apple Silicon Macs
  • Loading branch information
Zordrak authored Oct 1, 2022
2 parents 978ef3a + 94f0d2c commit 34c744b
Showing 1 changed file with 45 additions and 30 deletions.
75 changes: 45 additions & 30 deletions libexec/tfenv-install
Original file line number Diff line number Diff line change
Expand Up @@ -82,49 +82,64 @@ if [ -f "${dst_path}/terraform" ]; then
exit 0;
fi;

# Add support of ARM64 for Linux & Apple Silicon
case "$(uname -m)" in
aarch64* | arm64*)
# There is no arm64 support for versions:
# < 0.11.15
# >= 0.12.0, < 0.12.30
# >= 0.13.0, < 0.13.5
if [[ "${version}" =~ 0\.(([0-9]|10))\.\d* ||
"${version}" =~ 0\.11\.(([0-9]|1[0-4]))$ ||
"${version}" =~ 0\.12\.(([0-9]|[1-2][0-9]))$ ||
"${version}" =~ 0\.13\.[0-4]$
]]; then
TFENV_ARCH="${TFENV_ARCH:-amd64}";
else
TFENV_ARCH="${TFENV_ARCH:-arm64}";
fi;
;;
*)
TFENV_ARCH="${TFENV_ARCH:-amd64}";
;;
esac;

case "$(uname -s)" in
Darwin*)
os="darwin_${TFENV_ARCH}";
kernel="darwin";
;;
MINGW64*)
os="windows_${TFENV_ARCH}";
kernel="windows";
;;
MSYS_NT*)
os="windows_${TFENV_ARCH}";
MSYSNT*)
kernel="windows";
;;
CYGWIN_NT*)
os="windows_${TFENV_ARCH}";
CYGWINNT*)
kernel="windows";
;;
FreeBSD*)
os="freebsd_${TFENV_ARCH}";
kernel="freebsd";
;;
*)
os="linux_${TFENV_ARCH}";
kernel="linux";
;;
esac;

# Add support of ARM64 for Linux & Apple Silicon
case "$(uname -m)" in
aarch64* | arm64*)
case "${kernel}" in
"linux")
# There is no arm64 support for versions:
# < 0.11.15
# >= 0.12.0, < 0.12.30
# >= 0.13.0, < 0.13.5
if [[ "${version}" =~ 0\.(([0-9]|10))\.\d* ||
"${version}" =~ 0\.11\.(([0-9]|1[0-4]))$ ||
"${version}" =~ 0\.12\.(([0-9]|[1-2][0-9]))$ ||
"${version}" =~ 0\.13\.[0-4]$
]]; then
TFENV_ARCH="${TFENV_ARCH:-amd64}";
else
TFENV_ARCH="${TFENV_ARCH:-arm64}";
fi;
;;
"darwin")
# No Apple Silicon builds before 1.0.2
if [[ "${version}" =~ 0\..+$ || "${version}" =~ 1\.0\.0|1$
]]; then
TFENV_ARCH="${TFENV_ARCH:-amd64}";
else
TFENV_ARCH="${TFENV_ARCH:-arm64}";
fi;
;;
esac;
;;
*)
TFENV_ARCH="${TFENV_ARCH:-amd64}";
;;
esac;

os="${kernel}_${TFENV_ARCH}"

keybase_bin="$(command -v keybase 2>/dev/null)";
shasum_bin="$(command -v shasum 2>/dev/null)";
sha256sum_bin="$(command -v sha256sum 2>/dev/null)";
Expand Down

0 comments on commit 34c744b

Please sign in to comment.