Skip to content

Commit

Permalink
feat: setup download for ls-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ameausoone authored Dec 21, 2023
1 parent ca55200 commit 73d478a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
11 changes: 3 additions & 8 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ plugin_dir=$(dirname "$(dirname "$current_script_path")")
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"
set -x
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME"

# 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"
set +x
2 changes: 2 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ plugin_dir=$(dirname "$(dirname "$current_script_path")")
# shellcheck source=./lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

set -x
install_version "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
set +x
22 changes: 14 additions & 8 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail

GH_REPO="https://github.com/loeffel-io/ls-lint"
TOOL_NAME="ls-lint"
TOOL_TEST="ls-lint -h"
TOOL_TEST="ls-lint"

fail() {
echo -e "asdf-$TOOL_NAME: $*"
Expand Down Expand Up @@ -35,18 +35,26 @@ list_all_versions() {
}

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

# TODO: Adapt the release URL convention for ls-lint
url="$GH_REPO/archive/v${version}.tar.gz"
arch=$(uname -m)
case $arch in
arm64) arch="arm64" ;; # m1 macs
aarch64) arch="arm64" ;;
*) arch="amd64" ;;
esac
platform="$(uname | tr '[:upper:]' '[:lower:]')-${arch}"
# Adapt the release URL convention for ls-lint
url="$GH_REPO/releases/download/v${version}/ls-lint-${platform}"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
}

install_version() {
# debug
local install_type="$1"
local version="$2"
local install_path="${3%/bin}/bin"
Expand All @@ -58,12 +66,10 @@ install_version() {
(
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
chmod +x "$install_path"/*
chmod +x "$install_path/$TOOL_NAME"

# TODO: Assert ls-lint executable exists.
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."
test -x "$install_path/$TOOL_NAME" || fail "Expected $install_path/$TOOL_NAME to be executable."

echo "$TOOL_NAME $version installation was successful!"
) || (
Expand Down

0 comments on commit 73d478a

Please sign in to comment.