From a13a3329c597b783d6c7397e74d5d66f594abf8c Mon Sep 17 00:00:00 2001 From: Rob Zwissler Date: Thu, 14 Mar 2024 10:10:46 -0700 Subject: [PATCH 1/3] update to allow installing new versions --- bin/download | 18 ++++++++++-------- lib/utils.bash | 20 +++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/bin/download b/bin/download index 3ebe74e..c18fccf 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..7de8086 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -37,18 +37,24 @@ list_all_versions() { } download_release() { - local version filename url platform arch + local version filename found url 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" - - 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 + url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${platform}_${arch}.${extension}" + + echo "* Downloading $TOOL_NAME release $version (trying $extension)..." + if curl "${curl_opts[@]}" -o "${filename}.${extension}" -C - "$url" ; then + found=true + break + fi + done + $found || fail "Could not download $url" } install_version() { From 6a29822e813abc7ff21935f8c0497fd6fb244ead Mon Sep 17 00:00:00 2001 From: Rob Zwissler Date: Thu, 14 Mar 2024 10:17:45 -0700 Subject: [PATCH 2/3] improved output on fail --- lib/utils.bash | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index 7de8086..96bbeed 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -37,24 +37,25 @@ list_all_versions() { } download_release() { - local version filename found url platform arch + local version filename found url_prefix platform arch version="$1" filename="$2" # we will treat this like a prefix platform=$(getPlatform) arch=$(getArch) + url_prefix="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${platform}_${arch}" + found=false for extension in zip tar.gz ; do - url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${platform}_${arch}.${extension}" echo "* Downloading $TOOL_NAME release $version (trying $extension)..." - if curl "${curl_opts[@]}" -o "${filename}.${extension}" -C - "$url" ; then + if curl "${curl_opts[@]}" -o "${filename}.${extension}" -C - "${url_prefix}.${extension}" ; then found=true break fi done - $found || fail "Could not download $url" + $found || fail "Could not download $url_prefix(.tar.gz|.zip)" } install_version() { From 3ae380747db319fe990c6ca85c939363dceb134f Mon Sep 17 00:00:00 2001 From: Rob Zwissler Date: Thu, 14 Mar 2024 11:01:46 -0700 Subject: [PATCH 3/3] formatted --- bin/download | 2 +- lib/utils.bash | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/download b/bin/download index c18fccf..9af04f0 100755 --- a/bin/download +++ b/bin/download @@ -15,7 +15,7 @@ release_file_prefix="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION" download_release "$ASDF_INSTALL_VERSION" "$release_file_prefix" # Extract contents of archive file -if [ -f "${release_file_prefix}.zip" ] ; then +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" diff --git a/lib/utils.bash b/lib/utils.bash index 96bbeed..8bebcc3 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -47,10 +47,10 @@ download_release() { url_prefix="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${platform}_${arch}" found=false - for extension in zip tar.gz ; do + 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 + if curl "${curl_opts[@]}" -o "${filename}.${extension}" -C - "${url_prefix}.${extension}"; then found=true break fi