Skip to content

Commit

Permalink
dynamic file name
Browse files Browse the repository at this point in the history
  • Loading branch information
fxsalazar committed Sep 10, 2024
1 parent 9cebbf4 commit a33dca3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
9 changes: 6 additions & 3 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ source "${plugin_dir}/lib/utils.bash"

mkdir -p "$ASDF_DOWNLOAD_PATH"

# TODO: Adapt this to proper extension and adapt extracting strategy.
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"
platform=$(get_platform)
arch=$(get_architecture)

release_basename="${TOOL_NAME}-v${ASDF_INSTALL_VERSION}-${platform}-${arch}.tar.gz"
release_file="${ASDF_DOWNLOAD_PATH}/${release_basename}"

# Download tar.gz file to the download directory
download_release "$ASDF_INSTALL_VERSION" "$release_file"
download_release "${ASDF_INSTALL_VERSION}" "${release_basename}" "${release_file}"

# Extract contents of tar.gz file into the download directory
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"
Expand Down
46 changes: 41 additions & 5 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ list_all_versions() {
download_release() {
local version filename url
version="$1"
filename="$2"
file_basename="$2"
filename="$3"

# https://github.com/pulumi/esc/releases/download/v0.9.1/esc-v0.9.1-darwin-x64.tar.gz

# TODO: Adapt the release URL convention for esc
url="$GH_REPO/releases/download/v${version}/esc-v${version}-linux-x64.tar.gz"
url="$GH_REPO/releases/download/v${version}/${file_basename}"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand Down Expand Up @@ -74,3 +72,41 @@ install_version() {
fail "An error occurred while installing $TOOL_NAME $version."
)
}

get_platform() {
local uname_platform="$(uname)"

case "${uname_platform}" in
"Darwin")
echo "darwin"
;;

"Linux")
echo "linux"
;;

*)
echo "Platform ${uname_platform} is not supported."
exit 1
;;
esac
}

get_architecture() {
local uname_arch="$(uname -m)"

case "${uname_arch}" in
"arm64" | "aarch64") # Mac M1 and Linux ARM
echo "arm64"
;;

"x86_64")
echo "x64"
;;

*)
echo "Architecture ${uname_arch} is not supported."
exit 1
;;
esac
}

0 comments on commit a33dca3

Please sign in to comment.