diff --git a/lib/utils.bash b/lib/utils.bash index 0d4a358..463f0d7 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -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" @@ -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 +}