gitlab-build-images/scripts/install-chrome
2022-11-08 12:49:31 +00:00

73 lines
2.1 KiB
Bash
Executable file

#!/bin/bash
set -xeuo pipefail
IFS=$'\n\t'
function download_deb() {
component=$1
if [ "${component}" == "browser" ]; then
local DEB="${PKG}_${CHROME_VERSION}_${ARCH}.deb"
else
local DEB="${PKG}-${component}_${CHROME_VERSION}_${ARCH}.deb"
fi
curl --silent --show-error --fail -O "${DOWNLOAD_URL_BASE}/${CHROME_VERSION}/$DEB"
echo "${DEB}"
}
function build_debian() {
echo "Installing browser"
BROWSER_DEB="$(download_deb browser)"
if [ "${ARCH}" == "arm64" ]; then
COMMON_DEB=$(download_deb common)
apt install -y "$PWD/${COMMON_DEB}" "$PWD/${BROWSER_DEB}"
rm -rf "$COMMON_DEB"
else
apt install -y "$PWD/${BROWSER_DEB}"
fi
rm -f "$BROWSER_DEB"
echo "Installing webdriver"
if [ "${ARCH}" == "amd64" ]; then
CHROME_VERSION_BASE=$(echo $CHROME_VERSION | awk -F "." '{print $1 "." $2 "." $3}')
CHROME_DRIVER_VERSION=$(curl -q https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION_BASE)
wget -q https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d /usr/local/bin
rm -f chromedriver_linux64.zip
else
DRIVER_DEB=$(download_deb driver)
apt install -y "$PWD/$DRIVER_DEB"
rm -f "$DRIVER_DEB"
fi
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/google*.list
}
function build_ubi() {
echo "This OS is not supported for chrome install!"
exit 1
}
BUILD_OS=${BUILD_OS:-debian}
OS_VERSION=${OS_VERSION:-bullseye}
CHROME_VERSION=${1:-107.0.5304.87-1}
ARCH=${TARGETARCH:-amd64}
PKG=$([ "${ARCH}" == "amd64" ] && echo "google-chrome-stable" || echo "chromium")
DOWNLOAD_URL_BASE="https://gitlab.com/api/v4/projects/1075790/packages/generic/${BUILD_OS}-${OS_VERSION}-${PKG}"
if [[ $BUILD_OS =~ debian ]]; then
build_debian "$@"
elif [[ $BUILD_OS =~ ubi ]]; then
build_ubi "$@"
fi
if [ "${ARCH}" == "amd64" ]; then
google-chrome --version
else
chromium --version
fi