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: minor improvements for osx compat #69

Closed
Closed
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
12 changes: 8 additions & 4 deletions template/bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ set -euo pipefail
current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/utils.bash
# shellcheck source=./lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

mkdir -p "$ASDF_DOWNLOAD_PATH"
download_base_path="$(sanitize_path "$ASDF_DOWNLOAD_PATH")"
mkdir -p "$download_base_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="$download_base_path"/"$TOOL_NAME".zip

# Download tar.gz file to the download directory
download_release "$ASDF_INSTALL_VERSION" "$release_file"

install_base_path="$(sanitize_path "$ASDF_DOWNLOAD_PATH")"
mkdir -p "$install_base_path"

# 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 "$install_base_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"
2 changes: 1 addition & 1 deletion template/bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/utils.bash
# shellcheck source=./lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

install_version "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
4 changes: 3 additions & 1 deletion template/bin/latest-stable
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/utils.bash
# shellcheck source=./lib/utils.bash
. "${plugin_dir}/lib/utils.bash"

curl_opts=(-sI)
Expand All @@ -26,4 +26,6 @@ else
version="$(printf "%s\n" "$redirect_url" | sed 's|.*/tag/v\{0,1\}||')"
fi

version=$(get_version "${version}")

printf "%s\n" "$version"
2 changes: 1 addition & 1 deletion template/bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/utils.bash
# shellcheck source=./lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

list_all_versions | sort_versions | xargs echo
38 changes: 35 additions & 3 deletions template/lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,44 @@ list_all_versions() {
list_github_tags
}

get_download_link() {
local version
version="$1"

# seems like version can come as full download url or just the version
if [[ ${version} = https* ]]; then
(echo "${version}/" | sed 's|/tag/|/download/|')
else
(echo "${GH_REPO}/releases/download/v${version}/")
fi
}

get_version() {
local version
version="$1"

# seems like version can come as full download url or just the version
if [[ ${version} = https* ]]; then
(echo "${version//${GH_REPO}\/releases\/tag\/v/}")
else
(echo "${version}")
fi
}

sanitize_path() {
local path
path="$1"

echo "${path//${GH_REPO}\/releases\/tag\/v/}"
}

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

# TODO: Adapt the release URL convention for <YOUR TOOL>
url="$GH_REPO/archive/v${version}.tar.gz"
url="$(get_download_link "${version}")"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -51,15 +82,16 @@ download_release() {
install_version() {
local install_type="$1"
local version="$2"
local install_path="${3%/bin}/bin"
local install_path="$3"
install_path="$(sanitize_path "$install_path")"

if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
fi

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

# TODO: Assert <YOUR TOOL> executable exists.
local tool_cmd
Expand Down