Skip to content

Commit

Permalink
fix(download): fix download of artefacts for v2 and upwards
Browse files Browse the repository at this point in the history
  • Loading branch information
pdemagny committed May 24, 2024
1 parent 93f5ea4 commit 15c1944
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
22 changes: 17 additions & 5 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ source "${plugin_dir}/lib/utils.bash"

mkdir -p "$ASDF_DOWNLOAD_PATH"

release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"
if [[ $ASDF_INSTALL_VERSION =~ ^1 ]]; then
RELEASE_FILE_EXT=gz
EXTRACT_ARGUMENTS=-xzf
else
RELEASE_FILE_EXT=xz
EXTRACT_ARGUMENTS=-xf
fi

# Download tar.gz file to the download directory
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.$RELEASE_FILE_EXT"

# Download release 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" || fail "Could not extract $release_file"
# Extract contents of release file into the download directory
if [[ $ASDF_INSTALL_VERSION =~ ^1 ]]; then
tar "$EXTRACT_ARGUMENTS" "$release_file" -C "$ASDF_DOWNLOAD_PATH" || fail "Could not extract $release_file"
else
tar "$EXTRACT_ARGUMENTS" "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"
fi

# Remove the tar.gz file since we don't need to keep it
# Remove the release file since we don't need to keep it
rm "$release_file"
34 changes: 30 additions & 4 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,32 @@ fail() {
}

get_os() {
os=$(uname -s)
case $os in
Darwin) os="macos" ;;
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="x86_64" ;;
arm64) arch="aarch64" ;;
*) fail "The architecture (${arch}) is not supported by this installation script." ;;
esac
echo "$arch"
}

get_v1_os() {
os=$(uname -s)
if [[ ! "$os" =~ (Darwin|Linux) ]]; then fail "The os (${os}) is not supported by this installation script."; fi
echo "$os"
}

get_arch() {
get_v1_arch() {
arch=$(uname -m)
if [[ ! "$arch" =~ (x86_64|arm64) ]]; then fail "The architecture (${arch}) is not supported by this installation script."; fi
echo "$arch"
Expand Down Expand Up @@ -50,9 +70,15 @@ download_release() {
version="$1"
filename="$2"

arch=$(get_arch)
os=$(get_os)
url="$GH_REPO/releases/download/v${version}/teller_${version}_${os}_${arch}.tar.gz"
if [[ $version =~ ^1 ]]; then
arch=$(get_v1_arch)
os=$(get_v1_os)
url="$GH_REPO/releases/download/v${version}/teller_${version}_${os}_${arch}.tar.gz"
else
arch=$(get_arch)
os=$(get_os)
url="$GH_REPO/releases/download/v${version}/teller-${arch}-${os}.tar.xz"
fi

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

0 comments on commit 15c1944

Please sign in to comment.