Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: debug #5

Merged
merged 11 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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