Created
August 2, 2022 18:19
-
-
Save ea2809/7696ca7022b4dfc9caab1a8758d18418 to your computer and use it in GitHub Desktop.
Update ChromeDriver based on the chrome version for Mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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