From d9dbef7e0cc0119789a8c7791f0d0389d48a8a03 Mon Sep 17 00:00:00 2001 From: John Amicangelo Date: Thu, 7 Dec 2023 18:10:19 -0500 Subject: [PATCH] copy snippet from https://github.com/asdf-vm/asdf-plugin-template/pull/46\#discussion_r1117770604 --- lib/utils.bash | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/utils.bash b/lib/utils.bash index e6b995c..8e0adb9 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -36,13 +36,42 @@ list_all_versions() { list_github_tags } +get_machine_os() { + local OS + OS=$(uname -s | tr '[:upper:]' '[:lower:]') + + case "${OS}" in + darwin*) echo "darwin" ;; + linux*) echo "linux" ;; + *) fail "OS not supported: ${OS}" ;; + esac +} + +get_machine_arch() { + local ARCH + ARCH=$(uname -m | tr '[:upper:]' '[:lower:]') + + case "${ARCH}" in + i?86) echo "386" ;; + x86_64) echo "amd64" ;; + aarch64) echo "arm64" ;; + armv8l) echo "arm64" ;; + arm64) echo "arm64" ;; + *) fail "Architecture not supported: $ARCH" ;; + esac +} + download_release() { local version filename url version="$1" filename="$2" + os=$(get_machine_os) + arch=$(get_machine_arch) + # TODO: Adapt the release URL convention for richgo - url="$GH_REPO/archive/v${version}.tar.gz" + # url="$GH_REPO/archive/v${version}.tar.gz" + url="${GH_REPO}/releases/download/v${version}/${TOOL_NAME}_${version}.tar.gz" echo "* Downloading $TOOL_NAME release $version..." curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"