Add script 'check_google_chrome_driver_version.sh'
This commit is contained in:
		
							
								
								
									
										355
									
								
								check_google_chrome_driver_version.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										355
									
								
								check_google_chrome_driver_version.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,355 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					script_name="$(basename $(realpath $0))"
 | 
				
			||||||
 | 
					working_dir="$(dirname $(realpath $0))"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					conf_file="${working_dir}/conf/${script_name%%.*}.conf"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					LOCK_DIR="/tmp/$(basename $0).$$.LOCK"
 | 
				
			||||||
 | 
					log_file="${LOCK_DIR}/${script_name%%.*}.log"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ALL_IS_FINE=true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ----------
 | 
				
			||||||
 | 
					# Base Function(s)
 | 
				
			||||||
 | 
					# ----------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					usage() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   [[ -n  "$1" ]] && error "$1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   [[ $terminal ]] && echo -e "
 | 
				
			||||||
 | 
					\033[1mUsage:\033[m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   $(basename $0) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\033[1mDescription\033[m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Script checks if version of google chrom driver matches version of google chrome
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\033[1mOptions\033[m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   No Options available
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\033[1mFiles\033[m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   $conf_file: No Configuration file needed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\033[1mExample:\033[m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Check if version of google chrom driver matches version of google chrome
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      $(basename $0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   clean_up 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					clean_up() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   # Perform program exit housekeeping
 | 
				
			||||||
 | 
					   rm -rf "$LOCK_DIR"
 | 
				
			||||||
 | 
					   blank_line
 | 
				
			||||||
 | 
					   exit $1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echononl(){
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo X\\c > /tmp/shprompt$$
 | 
				
			||||||
 | 
					      if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
 | 
				
			||||||
 | 
					         echo -e -n "   $*\\c" 1>&2
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					         echo -e -n "   $*" 1>&2
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					      rm /tmp/shprompt$$
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fatal(){
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -e "   [ \033[31m\033[1mFatal\033[m ] $*"
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo -e "   [ Fatal ] $*"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -e "             \033[1mScript terminated\033[m.."
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo -e "             Script terminated.."
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					   rm -rf $LOCK_DIR
 | 
				
			||||||
 | 
					   exit 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					error (){
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -e "   [ \033[31m\033[1mError\033[m ] $*"
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo "   [ Error ] $*"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					warn (){
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -e "   [ \033[33m\033[1mWarn\033[m ]  $*"
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo "   [ Warn ]  $*"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					info (){
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					      if $terminal ; then
 | 
				
			||||||
 | 
					         echo -e "   [ \033[32m\033[1mInfo\033[m ]  $*"
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					         echo "   [ Info ]  $*"
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ok (){
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					      if $terminal ; then
 | 
				
			||||||
 | 
					         echo -e "   [ \033[32m\033[1mOk\033[m ]    $*"
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					         echo "   [ Ok ]    $*"
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo_done() {
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -e "\033[75G[ \033[32mdone\033[m ]"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					echo_ok() {
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -e "\033[75G[ \033[32mok\033[m ]"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					echo_warn() {
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -e "\033[75G[ \033[33m\033[1mwarn\033[m ]"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					echo_failed(){
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					echo_skipped() {
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -e "\033[75G[ \033[90m\033[1mskipped\033[m ]"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					echo_wait(){
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo -en "\033[75G[ \033[5m\033[1m...\033[m ]"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					trim() {
 | 
				
			||||||
 | 
					    local var="$*"
 | 
				
			||||||
 | 
					    var="${var#"${var%%[![:space:]]*}"}"   # remove leading whitespace characters
 | 
				
			||||||
 | 
					    var="${var%"${var##*[![:space:]]}"}"   # remove trailing whitespace characters
 | 
				
			||||||
 | 
					    echo -n "$var"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					blank_line() {
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ----------
 | 
				
			||||||
 | 
					# - Jobhandling 
 | 
				
			||||||
 | 
					# ----------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM
 | 
				
			||||||
 | 
					# -
 | 
				
			||||||
 | 
					trap clean_up SIGHUP SIGINT SIGTERM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# - Create lock directory '$LOCK_DIR"
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					mkdir "$LOCK_DIR"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ----------
 | 
				
			||||||
 | 
					# - Some checks ..
 | 
				
			||||||
 | 
					# ----------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# - Running in a terminal?
 | 
				
			||||||
 | 
					# -
 | 
				
			||||||
 | 
					if [[ -t 1 ]] ; then
 | 
				
			||||||
 | 
					   terminal=true
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					   terminal=false
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ==========
 | 
				
			||||||
 | 
					# - Begin Main Script
 | 
				
			||||||
 | 
					# ==========
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ----------
 | 
				
			||||||
 | 
					# - Headline
 | 
				
			||||||
 | 
					# ----------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if $terminal ; then
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					   echo -e "\033[1m----------\033[m"
 | 
				
			||||||
 | 
					   echo -e "\033[32m\033[1mRunning script \033[m\033[1m$script_name\033[32m .. \033[m"
 | 
				
			||||||
 | 
					   echo -e "\033[1m----------\033[m"
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: > $log_file
 | 
				
			||||||
 | 
					echononl "Get Version of google chrome.."
 | 
				
			||||||
 | 
					GOOGLE_CHROME_VERSION="$(aptitude versions google-chrome-stable 2> $log_file | awk '{print$2}' 2> $log_file)"
 | 
				
			||||||
 | 
					if [[ -s "$log_file" ]]; then
 | 
				
			||||||
 | 
					   echo_failed
 | 
				
			||||||
 | 
					   fatal "$(cat "$log_file")"
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					   echo_ok
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					GOOGLE_CHROME_CHECK_VERSION="${GOOGLE_CHROME_VERSION%\.*}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: > $log_file
 | 
				
			||||||
 | 
					echononl "Get Version of google chrome driver .."
 | 
				
			||||||
 | 
					GOOGLE_DRIVER_VERSION="$(/usr/local/bin/chromedriver --version | awk '{print$2}')"
 | 
				
			||||||
 | 
					if [[ -s "$log_file" ]]; then
 | 
				
			||||||
 | 
					   echo_failed
 | 
				
			||||||
 | 
					   fatal "$(cat "$log_file")"
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					   echo_ok
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					GOOGLE_DRIVER_CHECK_VERSION="${GOOGLE_DRIVER_VERSION%\.*}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					blank_line
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echononl "Check Versions.."
 | 
				
			||||||
 | 
					if [[ "$GOOGLE_CHROME_CHECK_VERSION" = "$GOOGLE_DRIVER_CHECK_VERSION" ]] ; then
 | 
				
			||||||
 | 
					   echo_ok
 | 
				
			||||||
 | 
					   VERSIONS_OK=true
 | 
				
			||||||
 | 
					   info "Version of Goggle Chrome Driver matches version of Google Chrome"
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					   echo_warn
 | 
				
			||||||
 | 
					   VERSIONS_OK=false
 | 
				
			||||||
 | 
					   warn "Version of Google Chrome Driver DOES NOT MATCH version of Google Chrome"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if $VERSIONS_OK ; then
 | 
				
			||||||
 | 
					   echononl "Backup current chrome driver .."
 | 
				
			||||||
 | 
					   if [[ ! -f "/usr/local/bin/chromedriver.${GOOGLE_DRIVER_VERSION}" ]]; then
 | 
				
			||||||
 | 
					      cp -a "/usr/local/bin/chromedriver" "/usr/local/bin/chromedriver.${GOOGLE_DRIVER_VERSION}" > $log_file 2>&1
 | 
				
			||||||
 | 
					      if [[ "$?" -gt 0 ]]; then
 | 
				
			||||||
 | 
					         echo_failed
 | 
				
			||||||
 | 
					         error "$(cat "$log_file")"
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					         echo_done
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo_skipped
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					   echo "             Google Chrome Version: $GOOGLE_CHROME_VERSION"
 | 
				
			||||||
 | 
					   echo "             Google Driver Version: $GOOGLE_DRIVER_VERSION"
 | 
				
			||||||
 | 
					   echo ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   # ----------
 | 
				
			||||||
 | 
					   # - Try to update google chrome driver
 | 
				
			||||||
 | 
					   # ----------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   if $terminal ; then
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					      echo -e "   \033[1mTry to update google chrome driver..\033[m"
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					      echo "   Try to update google chrome driver.."
 | 
				
			||||||
 | 
					      echo ""
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   : > $log_file
 | 
				
			||||||
 | 
					   echononl "Get Driver Versiom .."
 | 
				
			||||||
 | 
					   NEW_GOOGLE_CHROME_VERSION="$(curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE 2> $log_file)"
 | 
				
			||||||
 | 
					   if [[ -s "$log_file" ]]; then
 | 
				
			||||||
 | 
					      echo_failed
 | 
				
			||||||
 | 
					      fatal "$(cat "$log_file")"
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo_ok
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   : > $log_file
 | 
				
			||||||
 | 
					   echononl "Download new Google Chrome Driver.."
 | 
				
			||||||
 | 
					   wget -N http://chromedriver.storage.googleapis.com/${NEW_GOOGLE_CHROME_VERSION}/chromedriver_linux64.zip \
 | 
				
			||||||
 | 
					      -P /tmp 2> $log_file
 | 
				
			||||||
 | 
					   if [[ "$?" -gt 0 ]]; then
 | 
				
			||||||
 | 
					      echo_failed
 | 
				
			||||||
 | 
					      fatal "$(cat "$log_file")"
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo_ok
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   : > $log_file
 | 
				
			||||||
 | 
					   echononl "Install (unzip) driver into directory '/usr/local/bin'.."
 | 
				
			||||||
 | 
					   unzip -o /tmp/chromedriver_linux64.zip -d /usr/local/bin > $log_file 2>&1
 | 
				
			||||||
 | 
					   if [[ "$?" -gt 0 ]]; then
 | 
				
			||||||
 | 
					      echo_failed
 | 
				
			||||||
 | 
					      fatal "$(cat "$log_file")"
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo_ok
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   : > $log_file
 | 
				
			||||||
 | 
					   echononl "Get Version of newly installed google chrome driver .."
 | 
				
			||||||
 | 
					   GOOGLE_DRIVER_VERSION="$(/usr/local/bin/chromedriver --version | awk '{print$2}')"
 | 
				
			||||||
 | 
					   if [[ -s "$log_file" ]]; then
 | 
				
			||||||
 | 
					      echo_failed
 | 
				
			||||||
 | 
					      fatal "$(cat "$log_file")"
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo_ok
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					   GOOGLE_DRIVER_CHECK_VERSION="${GOOGLE_DRIVER_VERSION%\.*}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   echononl "Check Versions once again.."
 | 
				
			||||||
 | 
					   if [[ "$GOOGLE_CHROME_CHECK_VERSION" = "$GOOGLE_DRIVER_CHECK_VERSION" ]] ; then
 | 
				
			||||||
 | 
					      echo_ok
 | 
				
			||||||
 | 
					      if $terminal ; then
 | 
				
			||||||
 | 
					         info "Version of Google Chrome Driver NOW matches version of Google Chrome."
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					         echo ""
 | 
				
			||||||
 | 
					         echo "   [ Info ]  Version of Google Chrome Driver NOW matches version of Google Chrome."
 | 
				
			||||||
 | 
					         echo ""
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					   else
 | 
				
			||||||
 | 
					      echo_warn
 | 
				
			||||||
 | 
					      error "Version of Google Chrome Driver DOES NOT MATCH version of Google Chrome."
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					clean_up 1
 | 
				
			||||||
		Reference in New Issue
	
	Block a user