Skip to content

Commit

Permalink
Merge pull request #1 from kaanbiryol/version-check
Browse files Browse the repository at this point in the history
Update repo url as of 2.1.1
  • Loading branch information
MontakOleg authored Apr 24, 2024
2 parents c5a3505 + 2d580aa commit 4eecb61
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ download_release() {
local version filename url platform
version="$1"
filename="$2"
platform="$(get_platform)"

# TODO: Adapt the release URL convention for mockolo
url="$GH_REPO/releases/download/${version}/mockolo.${platform}.tar.gz"
url=$(release_url)

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand Down Expand Up @@ -83,3 +82,30 @@ get_platform() {
echo "macos"
fi
}

get_arch() {
local -r arch="$(uname -m)"
platform="$(get_platform)"
if [[ $platform == "ubuntu" ]]; then
echo "$arch"
else
echo "universal"
fi
}

version_compare() {
if [[ "$1" == "$(echo -e "$1\n$2" | sort -V | head -n1)" ]] && [[ "$1" != "$2" ]]; then
return 0 # $1 is less than $2
else
return 1
fi
}

release_url() {
platform="$(get_platform)"
if version_compare "$version" "2.1.1"; then
echo "$GH_REPO/releases/download/${version}/mockolo.${platform}.tar.gz"
else
echo "$GH_REPO/releases/download/${version}/mockolo.${platform}-$(get_arch).tar.gz"
fi
}

0 comments on commit 4eecb61

Please sign in to comment.