From 53431a7b1148b804e4de313d57b8b2a4c48956fc Mon Sep 17 00:00:00 2001 From: Pierre Demagny Date: Wed, 25 Oct 2023 10:19:25 +0200 Subject: [PATCH] fix: download the right file --- README.md | 3 --- bin/download | 3 +-- lib/utils.bash | 37 ++++++++++++++++++++++++++++--------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 357a1d2..520b172 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,7 @@ # Dependencies -**TODO: adapt this section** - - `bash`, `curl`, `tar`: generic POSIX utilities. -- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x. # Install diff --git a/bin/download b/bin/download index c11ee53..d4edcd3 100755 --- a/bin/download +++ b/bin/download @@ -10,14 +10,13 @@ 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" # 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" +tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" || fail "Could not extract $release_file" # Remove the tar.gz file since we don't need to keep it rm "$release_file" diff --git a/lib/utils.bash b/lib/utils.bash index f23f37d..c43ca75 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -2,7 +2,6 @@ set -euo pipefail -# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for changie. GH_REPO="https://github.com/miniscruff/changie" TOOL_NAME="changie" TOOL_TEST="changie --version" @@ -12,6 +11,26 @@ fail() { exit 1 } +get_os() { + os=$(uname -s) + case $os in + Darwin) os="darwin" ;; + Linux) os="linux" ;; + *) fail "The os (${os}) is not supported by this installation script." ;; + esac + echo "$os" +} + +get_arch() { + arch=$(uname -m) + case $arch in + x86_64) arch="amd64" ;; + arm64) arch="arm64" ;; + *) fail "The architecture (${arch}) is not supported by this installation script." ;; + esac + echo "$arch" +} + curl_opts=(-fsSL) # NOTE: You might want to remove this if changie is not hosted on GitHub releases. @@ -31,8 +50,6 @@ list_github_tags() { } list_all_versions() { - # TODO: Adapt this. By default we simply list the tag names from GitHub releases. - # Change this function if changie has other means of determining installable versions. list_github_tags } @@ -41,8 +58,9 @@ download_release() { version="$1" filename="$2" - # TODO: Adapt the release URL convention for changie - url="$GH_REPO/archive/v${version}.tar.gz" + arch=$(get_arch) + os=$(get_os) + url="$GH_REPO/releases/download/v${version}/changie_${version}_${os}_${arch}.tar.gz" echo "* Downloading $TOOL_NAME release $version..." curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url" @@ -58,12 +76,13 @@ install_version() { fi ( - mkdir -p "$install_path" - cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path" - - # TODO: Assert changie executable exists. local tool_cmd tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)" + + mkdir -p "$install_path" + cp -r "$ASDF_DOWNLOAD_PATH/${tool_cmd}" "$install_path/$tool_cmd" + chmod +x "$install_path/$tool_cmd" + test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable." echo "$TOOL_NAME $version installation was successful!"