install_chrome_driver.sh
#!/bin/bashBASEDIR=`dirname $0`BASEDIR=`(cd "$BASEDIR"; pwd)`# centos安装chromecentosInstall(){echo "开始安装google-chrome"cat>/etc/yum.repos.d/google-chrome.repo<<EOF[google-chrome]name=google-chromebaseurl=http://dl.google.com/linux/chrome/rpm/stable/basearchenabled=1gpgcheck=1gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pubEOFsed -i 's/basearch/$basearch/g' /etc/yum.repos.d/google-chrome.repoyum -y install google-chrome-stable --nogpgcheck;}# debian或ubuntu安装chromedebianInstall(){echo "开始安装google-chrome"curl -sSL https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o google-chrome-stable_current_amd64.debdpkg -i google-chrome-stable_current_amd64.debapt --fix-broken install -yrm -f google-chrome-stable_current_amd64.deb}install(){# 判断linux操作系统os=$(cat /etc/issue|awk 'NR==1 {print $1}')if [ "$os" = "\S" ];thenecho "CentOS"yum install -y curl unzipcentosInstallelseecho $osapt updateapt install -y curl unzipdebianInstallfi}# 判断是否安装了google-chromeif command -v google-chrome &> /dev/nullthenecho "google-chrome exist"elseinstallfi# 查看chrome浏览器版本google-chrome --version# 安装 chromedriverif command -v chromedriver &> /dev/nullthenecho "chromedriver exist"elsever=$(google-chrome --version|awk 'NR==1 {print $3}'| awk -F "." '{print $1"."$2"."$3}')latest_release=$(curl -sSL "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$ver")downurl="https://chromedriver.storage.googleapis.com/$latest_release/chromedriver_linux64.zip"curl -sSL $downurl -o chromedriver_linux64.zipunzip chromedriver_linux64.zip -d /usr/bin/rm -f chromedriver_linux64.zipfi# 查看chromedriver浏览器版本chromedriver --versionecho "安装完成"
执行
bash install_chrome_driver.sh
