diff --git a/src/scripts/install-chrome.sh b/src/scripts/install-chrome.sh index ac0f431..ea77f85 100644 --- a/src/scripts/install-chrome.sh +++ b/src/scripts/install-chrome.sh @@ -7,12 +7,20 @@ PROCESSED_CHROME_VERSION=$(circleci env subst "$ORB_PARAM_CHROME_VERSION") # installation check if uname -a | grep Darwin >/dev/null 2>&1; then if ls /Applications/*Google\ Chrome* >/dev/null 2>&1; then - if [ "$ORB_PARAM_REPLACE_EXISTING" == "1" ]; then - echo "$(/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version)is currently installed; replacing it" + LATEST_VERSION="$(curl -s 'https://chromiumdash.appspot.com/fetch_releases?channel=Stable&platform=Mac' | jq -r ' .[0] | .version ')" + if [[ "$PROCESSED_CHROME_VERSION" == "latest" ]]; then + target_version="$LATEST_VERSION" + else + target_version="$PROCESSED_CHROME_VERSION" + fi + installed_version="$(/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version)" + + if [ "$ORB_PARAM_REPLACE_EXISTING" == "1" ] && [ "$installed_version" != "$target_version" ]; then + echo "$installed_version is currently installed; replacing it" HOMEBREW_NO_AUTO_UPDATE=1 brew uninstall google-chrome >/dev/null 2>&1 || true $SUDO rm -rf /Applications/Google\ Chrome.app >/dev/null 2>&1 || true else - echo "$(/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version)is already installed" + echo "$installed_version is already installed" exit 0 fi else @@ -20,12 +28,20 @@ if uname -a | grep Darwin >/dev/null 2>&1; then fi elif grep Alpine /etc/issue >/dev/null 2>&1; then if command -v chromium-browser >/dev/null 2>&1; then - if [ "$ORB_PARAM_REPLACE_EXISTING" == "1" ]; then - echo "$(chromium-browser --version)is currently installed; replacing it" + LATEST_VERSION="$(curl -s 'https://chromiumdash.appspot.com/fetch_releases?channel=Stable&platform=Linux' | jq -r ' .[0] | .version ')" + if [[ "$PROCESSED_CHROME_VERSION" == "latest" ]]; then + target_version="$LATEST_VERSION" + else + target_version="$PROCESSED_CHROME_VERSION" + fi + installed_version="$(chromium-browser --version)" + + if [ "$ORB_PARAM_REPLACE_EXISTING" == "1" ] && [ "$installed_version" != "$target_version" ]; then + echo "$installed_version is currently installed; replacing it" $SUDO apk del --force-broken-world chromium >/dev/null 2>&1 || true $SUDO rm -f "$(command -v chromium-browser)" >/dev/null 2>&1 || true else - echo "$(chromium-browser --version)is already installed to $(command -v chromium-browser)" + echo "$installed_version is already installed to $(command -v chromium-browser)" exit 0 fi else @@ -33,12 +49,20 @@ elif grep Alpine /etc/issue >/dev/null 2>&1; then fi elif command -v yum >/dev/null 2>&1; then if command -v google-chrome >/dev/null 2>&1; then - if [ "$ORB_PARAM_REPLACE_EXISTING" == "1" ]; then - echo "$(google-chrome --version)is currently installed; replacing it" + LATEST_VERSION="$(curl -s 'https://chromiumdash.appspot.com/fetch_releases?channel=Stable&platform=Linux' | jq -r ' .[0] | .version ')" + if [[ "$PROCESSED_CHROME_VERSION" == "latest" ]]; then + target_version="$LATEST_VERSION" + else + target_version="$PROCESSED_CHROME_VERSION" + fi + installed_version="$(google-chrome --version)" + + if [ "$ORB_PARAM_REPLACE_EXISTING" == "1" ] && [ "$installed_version" != "$target_version" ]; then + echo "$installed_version is currently installed; replacing it" $SUDO yum remove -y google-chrome-stable >/dev/null 2>&1 || true $SUDO rm -f "$(command -v google-chrome)" >/dev/null 2>&1 || true else - echo "$(google-chrome --version)is already installed to $(command -v google-chrome)" + echo "$installed_version is already installed to $(command -v google-chrome)" exit 0 fi else