Skip to content

Commit

Permalink
feat: implement download script
Browse files Browse the repository at this point in the history
  • Loading branch information
benberryallwood committed Jan 3, 2025
1 parent dadce40 commit 3d33944
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
9 changes: 4 additions & 5 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -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"
18 changes: 5 additions & 13 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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}'
Expand All @@ -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() {
Expand Down

0 comments on commit 3d33944

Please sign in to comment.