Skip to content

Commit

Permalink
Merge pull request #38 from seanhagen/fix-wrong-arch
Browse files Browse the repository at this point in the history
Fix arch when `uanme -m` reports "x86_64"
  • Loading branch information
spencergilbert authored Sep 13, 2024
2 parents 438aa77 + 540504b commit 808c05e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mkdir -p "$ASDF_DOWNLOAD_PATH"

platform=$(get_platform)

arch=$(get_arch)
arch=$(get_arch "$ASDF_INSTALL_VERSION")

release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"

Expand Down
35 changes: 31 additions & 4 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,40 @@ get_platform() {
fi
}

# from https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
vercomp() {
if [[ $1 == $2 ]]; then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i = ${#ver1[@]}; i < ${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i = 0; i < ${#ver1[@]}; i++)); do
if ((10#${ver1[i]:=0} > 10#${ver2[i]:=0})); then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]})); then
return 2
fi
done
return 0
}

get_arch() {
local version="$1"
if [[ $(uname -m) == "x86_64" ]]; then
_arch="$(uname -m)"
echo "$_arch"
vercomp $version "0.45.0"
case $? in
0) echo "x86_64" ;;
1) echo "amd64" ;;
2) echo "x86_64" ;;
*) echo "amd64" ;;
esac
elif [[ $(uname -m) == "arm64" ]]; then
_arch="$(uname -m)"
echo "$_arch"
echo "arm64"
else
echo >&2 'Architecture not supported' && exit 1
fi
Expand Down

0 comments on commit 808c05e

Please sign in to comment.