Skip to content

Commit

Permalink
Start on making vyxasd3f work
Browse files Browse the repository at this point in the history
  • Loading branch information
lyxal committed Jan 12, 2025
1 parent 9aaca16 commit 22334f9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 33 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) lyxal 2025

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
11 changes: 2 additions & 9 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ 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.jar"

# Download tar.gz file to the download directory
# Download the jar 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"
16 changes: 4 additions & 12 deletions bin/latest-stable
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@ if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
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
# Have to manually make sure the latest 2.x.x version is selected
# because the default asdf script gets the latest 3.x.x version
version="$(list_all_versions | sort_versions | tail -n1 | xargs echo)"

printf "%s\n" "$version"
printf "%s\n" "$version"
7 changes: 6 additions & 1 deletion bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ plugin_dir=$(dirname "$(dirname "$current_script_path")")
# shellcheck source=./lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

list_all_versions | sort_versions | xargs echo
# list_all_versions | sort_versions | xargs echo
git ls-remote --tags --refs "https://github.com/Vyxal/Vyxal" |
grep -o 'refs/tags/.*' | cut -d/ -f3- | sed 's/^v//' | grep '^2\.' |
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n |
awk '{print $2}' | xargs echo
16 changes: 8 additions & 8 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ fail() {

curl_opts=(-fsSL)

# NOTE: You might want to remove this if vyxal3 is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi


sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
Expand All @@ -27,22 +27,20 @@ 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//' |
grep '^3\.' # Only list v3.x.x releases
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if vyxal3 has other means of determining installable versions.
list_github_tags
}


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

# TODO: Adapt the release URL convention for vyxal3
url="$GH_REPO/archive/v${version}.tar.gz"
url="$GH_REPO/releases/download/v${version}/vyxal-${version}.jar"

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

# TODO: Assert vyxal3 executable exists.
echo '#!/bin/bash
java -jar "$(dirname "$0")/vyxal3.jar" "$@"' > vyxal && chmod +x vyxal

local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."
Expand Down

0 comments on commit 22334f9

Please sign in to comment.