Skip to content

Commit

Permalink
Generate asdf-oras plugin from template.
Browse files Browse the repository at this point in the history
  • Loading branch information
bodgit committed Aug 16, 2023
1 parent 0326357 commit 8b19f5a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
4 changes: 1 addition & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
TODO: INSERT YOUR NAME COPYRIGHT YEAR (if applicable to your license)

MIT License

Copyright (c) [year] [fullname]
Copyright (c) 2023 Matt Dainty

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 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"
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 oras https://github.com/bodgit/asdf-oras.git "oras version"
```

Expand Down
31 changes: 29 additions & 2 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 oras.
GH_REPO="https://github.com/oras-project/oras"
TOOL_NAME="oras"
TOOL_TEST="oras version"
Expand Down Expand Up @@ -36,13 +35,41 @@ list_all_versions() {
list_github_tags
}

get_machine_os() {
local OS
OS=$(uname -s | tr '[:upper:]' '[:lower:]')

case "${OS}" in
darwin*) echo "darwin" ;;
linux*) echo "linux" ;;
*) fail "OS not supported: ${OS}" ;;
esac
}

get_machine_arch() {
local ARCH
ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')

case "${ARCH}" in
i?86) echo "386" ;;
x86_64) echo "amd64" ;;
aarch64) echo "arm64" ;;
armv81) echo "arm64" ;;
arm64) echo "arm64" ;;
*) fail "Architecture not supported: ${ARCH}" ;;
esac
}

download_release() {
local version filename url
version="$1"
filename="$2"

os=$(get_machine_os)
arch=$(get_machine_arch)

# TODO: Adapt the release URL convention for oras
url="$GH_REPO/archive/v${version}.tar.gz"
url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${version}_${os}_${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 8b19f5a

Please sign in to comment.