2020-10-07 13:49:40 +05:00
#!/bin/bash -e
2019-12-13 09:48:00 -05:00
################################################################################
## File: google-chrome.sh
2021-04-02 19:21:33 +03:00
## Desc: Installs google-chrome, chromedriver and chromium
2019-12-13 09:48:00 -05:00
################################################################################
2021-03-30 10:17:56 +03:00
# Source the helpers for use with the script
source $HELPER_SCRIPTS /install.sh
2021-04-02 19:21:33 +03:00
function GetChromiumRevision {
CHROME_VERSION = $1
# Get the required Chromium revision corresponding to the Chrome version
URL = " https://omahaproxy.appspot.com/deps.json?version= ${ CHROME_VERSION } "
REVISION = $( curl -s $URL | jq -r '.chromium_base_position' )
2023-07-21 13:54:40 +02:00
# Temporarily hardcode revision as both requests
# for 115.0.5790.102 and 115.0.5790.98 return old incorrect revision
if [ $REVISION -eq "1583" ] ; then
REVISION = "1134878"
fi
2022-04-19 09:04:36 +02:00
# Some Google Chrome versions are based on Chromium revisions for which a (usually very old) Chromium release with the same number exist. So far this has heppened with 4 digits long Chromium revisions (1060, 1086).
# Use the previous Chromium release when this happens to avoid downloading and installing very old Chromium releases that would break image build because of incompatibilities.
2022-08-10 13:55:34 +01:00
# First reported with: https://github.com/actions/runner-images/issues/5256
2022-09-05 12:54:06 +02:00
if [ ${# REVISION } -le 4 ] ; then
2022-04-19 09:04:36 +02:00
CURRENT_REVISIONS = $( curl -s "https://omahaproxy.appspot.com/all.json?os=linux&channel=stable" )
PREVIOUS_VERSION = $( echo " $CURRENT_REVISIONS " | jq -r '.[].versions[].previous_version' )
URL = " https://omahaproxy.appspot.com/deps.json?version= ${ PREVIOUS_VERSION } "
REVISION = $( curl -s $URL | jq -r '.chromium_base_position' )
2022-03-24 12:44:59 +04:00
fi
2021-04-02 19:21:33 +03:00
# Take the first part of the revision variable to search not only for a specific version,
# but also for similar ones, so that we can get a previous one if the required revision is not found
FIRST_PART_OF_REVISION = ${ REVISION : 0 : ${# REVISION } /2 }
2021-10-20 06:06:42 -07:00
FIRST_PART_OF_PREVIOUS_REVISION = $( expr $FIRST_PART_OF_REVISION - 1)
URL = "https://www.googleapis.com/storage/v1/b/chromium-browser-snapshots/o?delimiter=/&prefix=Linux_x64"
2022-08-10 13:55:34 +01:00
# Revision can include a hash instead of a number. Need to filter it out https://github.com/actions/runner-images/issues/5256
2022-03-24 12:44:59 +04:00
VERSIONS = $(( curl - s $URL / ${ FIRST_PART_OF_REVISION } | jq - r '.prefixes[]' & & curl - s $URL / ${ FIRST_PART_OF_PREVIOUS_REVISION } | jq - r '.prefixes[]' ) | grep - E "Linux_x64\/[0-9]+\/" | cut - d "/" - f 2 | sort - - version-sort)
2021-04-02 19:21:33 +03:00
# If required Chromium revision is not found in the list
# we should have to decrement the revision number until we find one.
# This is mentioned in the documentation we use for this installation:
# https://www.chromium.org/getting-involved/download-chromium
RIGHT_REVISION = $( echo $VERSIONS | cut -f 1 -d " " )
for version in $VERSIONS ; do
2022-03-24 12:44:59 +04:00
if [ $REVISION - lt $version ] ; then
2021-04-02 19:21:33 +03:00
echo $RIGHT_REVISION
return
fi
RIGHT_REVISION = $version
done
echo $RIGHT_REVISION
}
2021-03-30 10:17:56 +03:00
# Download and install Google Chrome
CHROME_DEB_URL = "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
CHROME_DEB_NAME = "google-chrome-stable_current_amd64.deb"
download_with_retries $CHROME_DEB_URL "/tmp" " ${ CHROME_DEB_NAME } "
apt install " /tmp/ ${ CHROME_DEB_NAME } " - f
2019-12-13 09:48:00 -05:00
echo "CHROME_BIN=/usr/bin/google-chrome" | tee - a / etc/environment
2021-04-15 12:04:19 +03:00
# Remove Google Chrome repo
rm - f / etc/cron.daily/google-chrome / etc/apt/sources.list.d/google-chrome.list / etc/apt/sources.list.d/google-chrome.list.save
2021-03-30 10:17:56 +03:00
# Parse Google Chrome version
2021-04-02 19:21:33 +03:00
FULL_CHROME_VERSION = $( google-chrome --product-version)
2023-07-21 16:03:18 +02:00
CHROME_VERSION = ${ FULL_CHROME_VERSION %.* }
echo " Chrome version is $FULL_CHROME_VERSION "
2019-12-18 17:16:23 +03:00
2023-07-20 16:15:00 +02:00
# Determine the download url for chromedriver
2023-07-21 16:03:18 +02:00
CHROME_VERSIONS_JSON = $( curl -fsSL https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build-with-downloads.json)
CHROMEDRIVER_VERSION = $( echo $CHROME_VERSIONS_JSON | jq -r '.builds["' " $CHROME_VERSION " '"].version' )
CHROMEDRIVER_URL = $( echo $CHROME_VERSIONS_JSON | jq -r '.builds["' " $CHROME_VERSION " '"].downloads.chromedriver[] | select(.platform=="linux64").url' )
2019-12-18 17:16:23 +03:00
2021-03-30 10:17:56 +03:00
# Download and unpack the latest release of chromedriver
2023-07-21 16:03:18 +02:00
echo " Installing chromedriver version $CHROMEDRIVER_VERSION "
2021-03-30 10:17:56 +03:00
download_with_retries $CHROMEDRIVER_URL "/tmp" "chromedriver_linux64.zip"
2023-07-20 16:15:00 +02:00
unzip - qq / tmp/chromedriver_linux64.zip - d / usr/local/share
2020-02-04 13:58:37 +03:00
2023-07-20 16:15:00 +02:00
CHROMEDRIVER_DIR = "/usr/local/share/chromedriver-linux64"
CHROMEDRIVER_BIN = " $CHROMEDRIVER_DIR /chromedriver "
2020-02-04 14:08:26 +03:00
chmod + x $CHROMEDRIVER_BIN
2020-02-04 13:58:37 +03:00
ln - s " $CHROMEDRIVER_BIN " / usr/bin/
2020-02-04 15:39:21 +03:00
echo " CHROMEWEBDRIVER= $CHROMEDRIVER_DIR " | tee - a / etc/environment
2019-12-18 17:16:23 +03:00
2021-04-02 19:21:33 +03:00
# Download and unpack Chromium
# Get Chromium version corresponding to the Google Chrome version
REVISION = $( GetChromiumRevision $FULL_CHROME_VERSION )
ZIP_URL = " https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F ${ REVISION } %2Fchrome-linux.zip?alt=media "
ZIP_FILE = " ${ REVISION } -chromium-linux.zip "
CHROMIUM_DIR = "/usr/local/share/chromium"
CHROMIUM_BIN = " $CHROMIUM_DIR /chrome-linux/chrome "
# Download and unzip Chromium archive
download_with_retries $ZIP_URL "/tmp" $ZIP_FILE
mkdir $CHROMIUM_DIR
unzip - qq / tmp/${ ZIP_FILE } - d $CHROMIUM_DIR
ln - s $CHROMIUM_BIN / usr/bin/chromium
2021-04-09 14:50:48 +03:00
ln - s $CHROMIUM_BIN / usr/bin/chromium-browser
2021-04-02 19:21:33 +03:00
2021-03-30 10:17:56 +03:00
invoke_tests "Browsers" "Chrome"
2021-04-02 19:21:33 +03:00
invoke_tests "Browsers" "Chromium"