Skip to content

Commit

Permalink
fix: download the right file
Browse files Browse the repository at this point in the history
  • Loading branch information
pdemagny committed Oct 25, 2023
1 parent 453e587 commit 53431a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -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"
37 changes: 28 additions & 9 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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
}

Expand All @@ -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"
Expand All @@ -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!"
Expand Down

0 comments on commit 53431a7

Please sign in to comment.