Last active
January 5, 2024 15:55
-
-
Save illmatix/f9daff73ee2e9de228f29347ac70c29f to your computer and use it in GitHub Desktop.
Chrome Browser and Chrome Driver setup for Latest Release Stable
This file contains hidden or 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 | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "This script must be run as root (or with sudo)" | |
| exit 1 | |
| fi | |
| function install_google_chrome() { | |
| echo "Checking googlechromelabs.github.io/chrome-for-testing latest release version" | |
| wget --no-verbose -O /tmp/chrome_latest_stable https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_STABLE | |
| echo "-----------------------" | |
| export CHROME_LATEST_STABLE_VERSION=$(cat /tmp/chrome_latest_stable | sed -E "s/.* ([0-9]+(\.[0-9]+){3}).*/\1/") | |
| echo -e "Google Chrome for Testing Version $CHROME_LATEST_STABLE_VERSION." | |
| rm /tmp/chrome_latest_stable | |
| if [[ $1 == "force" ]] || ! type /usr/local/bin/chrome >/dev/null 2>&1 || [[ $(/usr/local/bin/chrome --version | awk '{print $5}') != "${CHROME_LATEST_STABLE_VERSION}"* ]]; then | |
| export CHROME_LATEST_STABLE_DOWNLOAD="https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/${CHROME_LATEST_STABLE_VERSION}/linux64/chrome-linux64.zip" | |
| wget --no-verbose -O /tmp/google-chrome-stable.zip "$CHROME_LATEST_STABLE_DOWNLOAD" | |
| sudo unzip /tmp/google-chrome-stable.zip -d /tmp/ | |
| sudo cp -r /tmp/chrome-linux64/ /usr/src/chrome-linux64/ | |
| sudo ln -nsf /usr/src/chrome-linux64/chrome /usr/local/bin/chrome-for-testing | |
| sudo chmod +x /usr/local/bin/chrome-for-testing | |
| sudo chown $SUDO_USER:$SUDO_USER /usr/local/bin/chrome-for-testing | |
| sudo rm /tmp/google-chrome-stable.zip | |
| sudo rm -rf /tmp/chrome-linux64 | |
| echo -e "Google Chrome for Testing updated/installed." | |
| else | |
| echo -e "Google Chrome for Testing is already the latest version." | |
| fi | |
| } | |
| function install_chrome_driver() { | |
| if type chromedriver >/dev/null 2>&1; then | |
| CURRENT_CHROME_DRIVER_VERSION=$(chromedriver -v | cut -d " " -f2) | |
| echo -e "Current ChromeDriver version: $CURRENT_CHROME_DRIVER_VERSION" | |
| else | |
| CURRENT_CHROME_DRIVER_VERSION="" | |
| fi | |
| if [[ $1 == "force" ]] && [ "$CURRENT_CHROME_DRIVER_VERSION" != "$CHROME_LATEST_STABLE_VERSION" ]; then | |
| echo -e "Updating/Installing ChromeDriver..." | |
| export CHROME_DRIVER_URL="https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROME_LATEST_STABLE_VERSION/linux64/chromedriver-linux64.zip" | |
| wget --no-verbose -O /tmp/chromedriver_linux64.zip $CHROME_DRIVER_URL | |
| sudo rm -rf /usr/bin/chromedriver && sudo rm -rf /usr/local/bin/chromedriver | |
| unzip -p /tmp/chromedriver_linux64.zip chromedriver-linux64/chromedriver > /usr/bin/chromedriver | |
| rm /tmp/chromedriver_linux64.zip | |
| sudo chown root:root /usr/bin/chromedriver | |
| sudo chmod +x /usr/bin/chromedriver | |
| echo -e "ChromeDriver updated/installed." | |
| else | |
| echo -e "ChromeDriver version is up to date." | |
| fi | |
| check_chrome_driver_running | |
| start_chrome_driver | |
| } | |
| function check_chrome_driver_running() { | |
| if pgrep chromedriver >/dev/null; then | |
| CHROMEDRIVER_PID=$(pgrep chromedriver) | |
| echo -e "ChromeDriver is already running..." | |
| kill -9 $CHROMEDRIVER_PID | |
| echo -e "ChromeDriver has been terminated" | |
| fi | |
| } | |
| function start_chrome_driver() { | |
| echo -e "Starting Chromedriver now..." | |
| chromedriver --port=9515 & | |
| } | |
| if [[ $1 == "chrome" ]]; then | |
| install_google_chrome $2 | |
| elif [[ $1 == "driver" ]]; then | |
| install_chrome_driver $2 | |
| elif [[ $1 == "both" ]]; then | |
| install_google_chrome $2 | |
| echo "-----------------------" | |
| install_chrome_driver $2 | |
| else | |
| echo "Invalid argument. Please use either 'chrome' or 'driver' or 'both'." | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to your .env file
Make this file executable then run one of the following:
sudo ./chrome_browser_chromedriver_setup.sh bothsudo ./chrome_browser_chromedriver_setup.sh chromesudo ./chrome_browser_chromedriver_setup.sh driverAll three of these options also can be forced installed example:
both forceorchrome force.