Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to allow installing new versions #6

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ 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.zip"
release_file_prefix="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION"

# Download tar.gz file to the download directory
download_release "$ASDF_INSTALL_VERSION" "$release_file"
download_release "$ASDF_INSTALL_VERSION" "$release_file_prefix"

# Extract contents of zip file into the download directory
unzip -q "$release_file" -d "$ASDF_DOWNLOAD_PATH" || fail "Could not extract $release_file"
# Extract contents of archive file
if [ -f "${release_file_prefix}.zip" ] ; then
unzip -q "${release_file_prefix}.zip" -d "$ASDF_DOWNLOAD_PATH" || fail "Could not extract ${release_file_prefix}.zip"
else
tar -xzf "${release_file_prefix}.tar.gz" -C "$ASDF_DOWNLOAD_PATH" || fail "Could not extract ${release_file_prefix}.tar.gz"
fi

# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
# Remove the archive file since we don't need to keep it
rm -f "${release_file_prefix}.tar.gz" "${release_file_prefix}.zip"
19 changes: 13 additions & 6 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,25 @@ list_all_versions() {
}

download_release() {
local version filename url platform arch
local version filename found url_prefix platform arch
version="$1"
filename="$2"
filename="$2" # we will treat this like a prefix

platform=$(getPlatform)
arch=$(getArch)

# TODO: Adapt the release URL convention for tf-summarize
url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${platform}_${arch}.zip"
url_prefix="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${platform}_${arch}"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
found=false
for extension in zip tar.gz ; do

echo "* Downloading $TOOL_NAME release $version (trying $extension)..."
if curl "${curl_opts[@]}" -o "${filename}.${extension}" -C - "${url_prefix}.${extension}" ; then
found=true
break
fi
done
$found || fail "Could not download $url_prefix(.tar.gz|.zip)"
}

install_version() {
Expand Down
Loading