Skip to content

Commit

Permalink
Finish download and install portions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Diamond committed Nov 23, 2023
1 parent 829e77e commit 832024e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# Dependencies

- `bash`, `curl`, `tar`, and [POSIX utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).
- `bash`, `curl`, and [POSIX utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).

# Install

Expand Down
12 changes: 3 additions & 9 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ source "${plugin_dir}/lib/utils.bash"
mkdir -p "$ASDF_DOWNLOAD_PATH"

#https://github.com/moonrepo/moon/releases/download/v${version}/${target}
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION"

# 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"
#Download file to the download directory
download_release "$ASDF_INSTALL_VERSION" "$release_file"
39 changes: 36 additions & 3 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,49 @@ list_all_versions() {
}

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

url="$GH_REPO/archive/v${version}.tar.gz"
#Ex: https://github.com/moonrepo/moon/releases/download/v1.17.3/moon-aarch64-apple-darwin
url="$GH_REPO/releases/download/v${version}/${target}"

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

get_target() {
arch=$(uname -sm)

if [[ "${OS-}" == "Windows_NT" ]]; then
target="moon-x86_64-pc-windows-msvc.exe"
else
case "$arch" in
"Darwin x86_64") target="moon-x86_64-apple-darwin" ;;
"Darwin arm64") target="moon-aarch64-apple-darwin" ;;
"Linux aarch64") target="moon-aarch64-unknown-linux" ;;
"Linux x86_64") target="moon-x86_64-unknown-linux" ;;
*)
echo "Unsupported system or architecture \"$arch\". Unable to install moon!"
exit 1
;;
esac
fi

if [[ "$arch" == "Linux"* ]]; then
deps=$(ldd --version 2>&1 || true)

if [[ $deps == *"musl"* ]]; then
target="$target-musl"
else
target="$target-gnu"
fi
fi

echo $target
}

install_version() {
local install_type="$1"
local version="$2"
Expand Down

0 comments on commit 832024e

Please sign in to comment.