Skip to content

Commit

Permalink
fix: skip installation if installed version is newer (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricRibeiro committed Jul 27, 2023
1 parent 047b84b commit 637a5b8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,21 @@ if command -v gcloud > /dev/null 2>&1; then
installed_version="$(gcloud version | head -n 1 | sed 's/Google Cloud SDK \([0-9]*.[0-9]*.[0-9]*\)/\1/')"

if [ "$installed_version" != "$version" ]; then
printf '%s\n' "The version installed ($installed_version) differs from the version requested ($version)."
printf '%s\n' "Uninstalling v${installed_version}..."
if ! uninstall; then printf '%s\n' "Failed to uninstall the current version."; exit 1; fi
# Figure out which version is older between the installed version and the requested version.
older_version="$(printf '%s\n%s\n' "$installed_version" "$version" | sort -V | head -n 1)"

# If the version requested is "latest" and the installed version is newer than the latest version available, skip installation.
if [ "$ORB_VAL_VERSION" = "latest" ] && [ "$older_version" = "$version" ]; then
printf '%s\n' "The version installed ($installed_version) is newer than the latest version listed in the release notes ($version)."
printf '%s\n' "Skipping installation."
else
printf '%s\n' "The version installed ($installed_version) differs from the version requested ($version)."
printf '%s\n' "Uninstalling v${installed_version}..."
if ! uninstall; then printf '%s\n' "Failed to uninstall the current version."; exit 1; fi

printf '%s\n' "Installing v${version}..."
if ! install "$version"; then printf '%s\n' "Failed to install the requested version."; exit 1; fi
printf '%s\n' "Installing v${version}..."
if ! install "$version"; then printf '%s\n' "Failed to install the requested version."; exit 1; fi
fi
else
printf '%s\n' "The version installed ($installed_version) matches the version requested ($version)."
printf '%s\n' "Skipping installation."
Expand Down

0 comments on commit 637a5b8

Please sign in to comment.