From 4f84f1dc77f7b0592873d45c42153815c32aab5d Mon Sep 17 00:00:00 2001 From: Giorgio Garasto Date: Wed, 4 Oct 2023 21:55:10 +0200 Subject: [PATCH] feat: adapt download and install steps --- bin/download | 5 ++--- contributing.md | 1 - lib/utils.bash | 34 ++++++++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/bin/download b/bin/download index c11ee53..7a95973 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" # Download tar.gz file to the download directory download_release "$ASDF_INSTALL_VERSION" "$release_file" -# Extract contents of tar.gz file into the download directory -tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file" +# Extract contents of tar.gz file into the download directory +tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" || fail "Could not extract $release_file" # Remove the tar.gz file since we don't need to keep it rm "$release_file" diff --git a/contributing.md b/contributing.md index 04b984a..1ffadec 100644 --- a/contributing.md +++ b/contributing.md @@ -5,7 +5,6 @@ Testing Locally: ```shell asdf plugin test [--asdf-tool-version ] [--asdf-plugin-gitref ] [test-command*] -# TODO: adapt this asdf plugin test traefik https://github.com/Dabolus/asdf-traefik.git "traefik --help" ``` diff --git a/lib/utils.bash b/lib/utils.bash index 107d02a..4bd2825 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -2,7 +2,6 @@ set -euo pipefail -# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for traefik. GH_REPO="https://github.com/traefik/traefik" TOOL_NAME="traefik" TOOL_TEST="traefik --help" @@ -27,22 +26,45 @@ sort_versions() { list_github_tags() { git ls-remote --tags --refs "$GH_REPO" | grep -o 'refs/tags/.*' | cut -d/ -f3- | - sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags + sed 's/^v//' } list_all_versions() { - # TODO: Adapt this. By default we simply list the tag names from GitHub releases. - # Change this function if traefik has other means of determining installable versions. list_github_tags } +get_platform() { + # Get uname and lowercase it with awk + local os=$(uname | awk '{print tolower($0)}') + # Make sure the platform is supported + if [[ "$os" == "darwin" || "$os" == "linux" || "$os" == "freebsd" ]]; then + echo "$os" + else + >&2 echo "unsupported os: ${os}" && exit 1 + fi +} + +get_arch() { + local arch=$(uname -m) + if [[ "$arch" == "x86_64" || "$arch" == "amd64" ]]; then + echo "amd64" + elif [[ "$arch" == "arm64" || "$arch" == "aarch64" || "$arch" == "aarch64_be" || "$arch" == "armv8b" || "$arch" == "armv8l" ]]; then + echo "arm64" + elif [[ "$arch" == "armv6" || "$arch" == "armv6l" ]]; then + echo "armv6" + elif [[ "$arch" == "i386" || "$arch" == "i686" ]]; then + echo "386" + else + >&2 echo "unsupported arch: ${arch}" && exit 1 + fi +} + download_release() { local version filename url version="$1" filename="$2" - # TODO: Adapt the release URL convention for traefik - url="$GH_REPO/archive/v${version}.tar.gz" + url="$GH_REPO/releases/download/v${version}/traefik_v${version}_$(get_platform)_$(get_arch).tar.gz" echo "* Downloading $TOOL_NAME release $version..." curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"