From 3d33944e29ee78baa6a4400abf82a6752196a177 Mon Sep 17 00:00:00 2001 From: Ben Berry-Allwood Date: Fri, 3 Jan 2025 17:52:24 +0000 Subject: [PATCH] feat: implement download script --- bin/download | 9 ++++----- lib/utils.bash | 18 +++++------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/bin/download b/bin/download index c11ee53..af8d699 100755 --- a/bin/download +++ b/bin/download @@ -10,14 +10,13 @@ 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" +release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tgz" -# Download tar.gz file to the download directory +# Download tgz file to the download directory download_release "$ASDF_INSTALL_VERSION" "$release_file" -# Extract contents of tar.gz file into the download directory +# Extract contents of tgz file into the download directory tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file" -# Remove the tar.gz file since we don't need to keep it +# Remove the tgz file since we don't need to keep it rm "$release_file" diff --git a/lib/utils.bash b/lib/utils.bash index 6a479fb..efc677a 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -2,8 +2,6 @@ set -euo pipefail -# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for spark. -GH_REPO="https://github.com/apache/spark" TOOL_NAME="spark" TOOL_TEST="spark-shell --version" @@ -12,13 +10,6 @@ fail() { exit 1 } -curl_opts=(-fsSL) - -# NOTE: You might want to remove this if spark is not hosted on GitHub releases. -if [ -n "${GITHUB_API_TOKEN:-}" ]; then - curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN") -fi - sort_versions() { sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' @@ -35,15 +26,16 @@ list_all_versions() { } download_release() { - local version filename url + local version filename base_version url version="$1" filename="$2" - # TODO: Adapt the release URL convention for spark - url="$GH_REPO/archive/v${version}.tar.gz" + base_version=$(echo "$version" | cut -d'-' -f1) + + url="https://archive.apache.org/dist/spark/spark-${base_version}/spark-${version}.tgz" echo "* Downloading $TOOL_NAME release $version..." - curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url" + curl -fsSL -o "$filename" -C - "$url" || fail "Could not download $url" } install_version() {