diff --git a/bin/download b/bin/download index 3ebe74e..9af04f0 100755 --- a/bin/download +++ b/bin/download @@ -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" diff --git a/lib/utils.bash b/lib/utils.bash index 8f53005..8bebcc3 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -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() {