Skip to content

Commit

Permalink
feat: adapt download and install steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabolus committed Oct 4, 2023
1 parent 7b4d4da commit 4f84f1d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
5 changes: 2 additions & 3 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"

# 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"
1 change: 0 additions & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Testing Locally:
```shell
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]

# TODO: adapt this
asdf plugin test traefik https://github.com/Dabolus/asdf-traefik.git "traefik --help"
```

Expand Down
34 changes: 28 additions & 6 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 4f84f1d

Please sign in to comment.