#!/bin/bash

# version variable
# Can be found here : https://hub.docker.com/r/selenium/standalone-chrome/tags
# Will need to change it in seleniumChromedriverDockerfile and probably download
# it and change it in patchChromedriver.py
VERSION="latest"

# From undetected chromedriver docker
#sudo docker run --rm -it -p 3389:3389 -v ./undetectedChromedriver:/root/.local/share/undetected_chromedriver/ ultrafunk/undetected-chromedriver:latest

sudo docker pull selenium/standalone-chrome:$VERSION

# With undetected chromedriver patcher
# Run the selenium/standalone-chrome:latest with a specific container name in the background
#sudo docker run -d --name standalone-chrome -v /home/ninluc/Documents/codage/DatBrowser/undetectedChromedriver/chrome/:/opt/google/chrome/ selenium/standalone-chrome:$VERSION
sudo docker run -d --name standalone-chrome selenium/standalone-chrome:$VERSION

sleep 7

# Copy the chromedriver binary from the container to the host
sudo docker cp -L standalone-chrome:/bin/chromedriver ./chromedriver

sudo chmod 777 ./chromedriver

# Patch the chromedriver binary
source venv/bin/activate
python3 ./patchChromedriver.py

# Stop the container
sudo docker stop standalone-chrome
sudo docker rm standalone-chrome
