Skip to content

Commit

Permalink
feat: Resolve Chrome download issues in MacOS and Linux (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleTryon authored Apr 26, 2022
1 parent a15ea92 commit 2d14282
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ workflows:
[orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check]
# Use a context to hold your publishing token.
context: orb-publisher
github-token: GHI_TOKEN
filters: *filters
# Triggers the next workflow in the Orb Development Kit.
- orb-tools/continue:
Expand Down
1 change: 1 addition & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ workflows:
orb-name: circleci/browser-tools
vcs-type: << pipeline.project.type >>
pub-type: production
github-token: GHI_TOKEN
requires:
- orb-tools/pack
- test-cimg-base-all
Expand Down
50 changes: 29 additions & 21 deletions src/scripts/install-chrome.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ fi

# install chrome
if uname -a | grep Darwin >/dev/null 2>&1; then
brew update >/dev/null 2>&1 &&
HOMEBREW_NO_AUTO_UPDATE=1 brew install google-chrome >/dev/null 2>&1
echo -e "#\!/bin/bash\n" >google-chrome
perl -i -pe "s|#\\\|#|g" google-chrome
echo -e "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \"\$@\"" >>google-chrome
$SUDO mv google-chrome /usr/local/bin
$SUDO chmod +x /usr/local/bin/google-chrome
echo "Preparing Chrome installation for MacOS-based systems"
# Universal MacOS .pkg with license pre-accepted: https://support.google.com/chrome/a/answer/9915669?hl=en
CHROME_MAC_URL="https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg"
CHROME_TEMP_DIR="$(mktemp -d)"
curl -L -o "$CHROME_TEMP_DIR/googlechrome.pkg" "$CHROME_MAC_URL"
sudo /usr/sbin/installer -pkg "$CHROME_TEMP_DIR/googlechrome.pkg" -target /
sudo rm -rf "$CHROME_TEMP_DIR"
xattr -rc "/Applications/Google Chrome.app"
echo '#!/usr/bin/env bash' >> google-chrome
echo '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome "$@"' >> google-chrome
sudo mv google-chrome /usr/local/bin/
sudo chmod +x /usr/local/bin/google-chrome
# test/verify installation
if google-chrome --version >/dev/null 2>&1; then
echo "$(google-chrome --version)has been installed in the /Applications directory"
Expand All @@ -74,6 +79,7 @@ if uname -a | grep Darwin >/dev/null 2>&1; then
exit 1
fi
elif command -v yum >/dev/null 2>&1; then
echo "Preparing Chrome installation for RedHat-based systems"
# download chrome
if [[ "$ORB_PARAM_CHROME_VERSION" == "latest" ]]; then
CHROME_URL="https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm"
Expand All @@ -93,23 +99,25 @@ elif command -v yum >/dev/null 2>&1; then
rm -rf google-chrome.rpm liberation-fonts.rpm
else
# download chrome
echo "Preparing Chrome installation for Debian-based systems"
if [[ "$ORB_PARAM_CHROME_VERSION" == "latest" ]]; then
CHROME_URL="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
ENV_IS_ARM=$(! dpkg --print-architecture | grep -q arm; echo $?)
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | $SUDO apt-key add -
if [ "$ENV_IS_ARM" == "arm" ]; then
echo "Installing Chrome for ARM64"
$SUDO sh -c 'echo "deb [arch=arm64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
else
echo "Installing Chrome for AMD64"
$SUDO sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
fi
$SUDO apt-get update
$SUDO apt-get install -y google-chrome-stable
else
CHROME_URL="https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${ORB_PARAM_CHROME_VERSION}-1_amd64.deb"
fi
curl --silent --show-error --location --fail --compressed \
--retry 3 --retry-delay 5 --keepalive-time 2 \
--output google-chrome.deb "$CHROME_URL"
# Debian 10 fix
if grep -i buster /etc/os-release; then
$SUDO apt-get --allow-releaseinfo-change-suite update
# Google does not keep older releases in their PPA, but they can be installed manually. HTTPS should be enough to secure the download.
wget --no-verbose -O /tmp/chrome.deb "https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${ORB_PARAM_CHROME_VERSION}-1_amd64.deb" \
&& $SUDO apt-get install -y /tmp/chrome.deb \
&& rm /tmp/chrome.deb
fi
# Ensure that Chrome apt dependencies are installed.
#$SUDO apt-get update
# The pipe will install any dependencies missing
$SUDO dpkg -i google-chrome.deb || $SUDO apt-get update && $SUDO apt-get -fy install
rm -rf google-chrome.deb
$SUDO sed -i 's|HERE/chrome"|HERE/chrome" --disable-setuid-sandbox --no-sandbox|g' "/opt/google/chrome/google-chrome"
fi

Expand Down

0 comments on commit 2d14282

Please sign in to comment.