Skip to content

Instantly share code, notes, and snippets.

@ea2809
Created August 2, 2022 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ea2809/7696ca7022b4dfc9caab1a8758d18418 to your computer and use it in GitHub Desktop.
Save ea2809/7696ca7022b4dfc9caab1a8758d18418 to your computer and use it in GitHub Desktop.
Update ChromeDriver based on the chrome version for Mac
#!/bin/bash
####
# Author: ea2809 (Enrique García Galán)
# Description: Download the Mac chromedriver and move it to the expected site
# The user should have permissions to change the actual chromedriver
####
function updateChrome() {
chromedriver="chromedriver"
# Chromedriver donwload name
arch=$(uname -p)
file_name="chromedriver_mac64.zip"
if [[ "${arch}" == "arm" ]]; then
file_name="chromedriver_mac64_m1.zip"
fi
# Paths
file_dir="/tmp"
file_path="$file_dir/$file_name"
chromedriver_path="$file_dir/$chromedriver"
# Get local chrome version
chrome_version=$(/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version | cut -d" " -f3 | cut -d"." -f-3)
# Get the actual chromedriver version
download_url="https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chrome_version"
echo "Getting latest release for $chrome_version at $download_url"
download_location=$(curl "$download_url")
# Actual chromedriver location
chromedriver_location="https://chromedriver.storage.googleapis.com/$download_location/$file_name"
rm $file_path || true
echo "Downloading $chromedriver_location to $file_path"
curl -o $file_path $chromedriver_location
pushd $file_dir
unzip $file_path $chromedriver
popd
# Unzip the chromedriver or show how to fix it
actual_driver=$(which $chromedriver)
if [[ -f $actual_driver ]]; then
mv $actual_driver $actual_driver.back
mv $chromedriver_path $actual_driver
# Clean
rm $file_path
else
echo "I don't know where you should have your chormedriver"
echo "Downloaded $file_name is at $file_path"
fi
}
updateChrome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment