Skip to content

Commit

Permalink
Merge pull request #5 from xanmanning/feat-initial-release
Browse files Browse the repository at this point in the history
feat: initial release
  • Loading branch information
xanmanning authored Mar 18, 2024
2 parents 03d3099 + 1cb4545 commit 7f58a92
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 21 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

**TODO: adapt this section**

- `bash`, `curl`, `tar`, and [POSIX utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.
- `bash`, `curl`, and [POSIX utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).

# Install

Expand Down
12 changes: 4 additions & 8 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ 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"
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION"

# 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"

# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
platform=$(get_platform)
arch=$(get_arch)
download_release "$ASDF_INSTALL_VERSION" "$release_file" "$platform" "$arch"
17 changes: 9 additions & 8 deletions bin/latest-stable
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ fi
# curl of REPO/releases/latest is expected to be a 302 to another URL
# when no releases redirect_url="REPO/releases"
# when there are releases redirect_url="REPO/releases/tag/v<VERSION>"
redirect_url=$(curl "${curl_opts[@]}" "$GH_REPO/releases/latest" | sed -n -e "s|^location: *||p" | sed -n -e "s|\r||p")
version=
printf "redirect url: %s\n" "$redirect_url" >&2
if [[ "$redirect_url" == "$GH_REPO/releases" ]]; then
version="$(list_all_versions | sort_versions | tail -n1 | xargs echo)"
else
version="$(printf "%s\n" "$redirect_url" | sed 's|.*/tag/v\{0,1\}||')"
fi
# redirect_url=$(curl "${curl_opts[@]}" "$GH_REPO/releases/latest" | sed -n -e "s|^location: *||p" | sed -n -e "s|\r||p")
# version=
# printf "redirect url: %s\n" "$redirect_url" >&2
# if [[ "$redirect_url" == "$GH_REPO/releases" ]]; then
# version="$(list_all_versions | sort_versions | tail -n1 | xargs echo)"
# else
# version="$(printf "%s\n" "$redirect_url" | sed 's|.*/tag/v\{0,1\}||')"
# fi
version="$(list_all_versions | sort_versions | tail -n1 | xargs echo)"

printf "%s\n" "$version"
47 changes: 44 additions & 3 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sort_versions() {

list_github_tags() {
git ls-remote --tags --refs "$GH_REPO" |
grep -vE "chart-|k3k-" |
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
}
Expand All @@ -36,13 +37,51 @@ list_all_versions() {
list_github_tags
}

get_platform() {
local platform
platform="$(uname | tr '[:upper:]' '[:lower:]')"
if [[ $(uname -s) == "Darwin" ]]; then
echo "$platform"
elif [[ $(uname -s) == "Linux" ]]; then
echo "$platform"
else
echo >&2 'Platform not supported' && exit 1
fi
}

get_arch() {
if [[ $(uname -m) == "x86_64" ]]; then
echo "amd64"
elif [[ $(uname -m) == "arm64" ]]; then
echo "arm64"
elif [[ $(uname -m) == "aarch64" ]]; then
echo "aarch64"
else
echo >&2 'Architecture not supported' && exit 1
fi
}

download_release() {
local version filename url
local suffix version filename url platform arch
version="$1"
filename="$2"
platform="$3"
arch="$4"
suffix=""

case $platform in
"darwin")
suffix="-${platform}-${arch}"
;;
*)
if [ "$arch" != "amd64" ]; then
suffix="-${arch}"
fi
;;
esac

# TODO: Adapt the release URL convention for k3kcli
url="$GH_REPO/archive/v${version}.tar.gz"
url="${GH_REPO}/releases/download/v${version}/${TOOL_NAME}${suffix}"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -59,7 +98,9 @@ install_version() {

(
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path/$TOOL_NAME"

chmod +x "$install_path/$TOOL_NAME"

# TODO: Assert k3kcli executable exists.
local tool_cmd
Expand Down
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0

0 comments on commit 7f58a92

Please sign in to comment.