Skip to content

Instantly share code, notes, and snippets.

@hemanth
Created June 3, 2013 04:08
Show Gist options
  • Select an option

  • Save hemanth/5696075 to your computer and use it in GitHub Desktop.

Select an option

Save hemanth/5696075 to your computer and use it in GitHub Desktop.
watir-webdriver-setup script for GNU/Linux.
# works for all linux flavours [tested on Ubuntu, Fedora, CentOS]
# Author : Hemanth.HM
#!/bin/bash
shopt -s nocaseglob
set -e
ruby_version="1.9.3"
ruby_version_string="1.9.3-p0"
ruby_source_url="http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz"
ruby_source_tar_name="ruby-1.9.3-p0.tar.gz"
ruby_source_dir_name="ruby-1.9.3-p0"
script_runner=$(whoami)
sonicready_path=$(cd && pwd)/sonicready
log_file="$sonicready_path/install.log"
control_c()
{
echo -en "\n\n*** Exiting ***\n\n"
exit 1
}
# trap keyboard interrupt (control-c)
trap control_c SIGINT
echo -e "\n\n"
echo "#################################"
echo "########## Sonic Ready ##########"
echo "#################################"
#determine the distro
if [[ $MACHTYPE = *linux* ]] ; then
distro_sig=$(cat /etc/issue)
[[ $distro_sig =~ ubuntu ]] && distro="ubuntu"
[[ $distro_sig =~ centos ]] && distro="centos"
[[ $distro_sig =~ fedora ]] && distro="fedora"
else
echo -e "\nSonic Ready currently only supports Ubuntu, Feodra, CentOS\n"
exit 1
fi
#now check if user is root
if [ $script_runner == "root" ] ; then
echo -e "\nThis script must be run as a normal user with sudo privileges\n"
exit 1
fi
echo -e "\n\n"
echo -en "This script will update your system! Run on a fresh install only !!!"
echo "run tail -f $log_file in a new terminal to watch the install"
echo -e "\n"
echo "What this script gets you:"
echo " * An updated system"
echo " * Ruby $ruby_version_string"
# Check if the user has sudo privileges.
sudo -v >/dev/null 2>&1 || { echo $script_runner has no sudo privileges ; exit 1; }
echo -en "\n\n!!! Set to build Ruby from source and install system wide !!! \n"
echo -e "\n=> Creating install dir..."
cd && mkdir -p sonicready/src && cd sonicready && touch install.log
echo "==> done..."
echo -e "\n=> Running recipe for $distro...\n"
if [[ $MACHTYPE = *linux* ]] ; then
if [[ $distro = *ubuntu* ]]; then
#test if aptitude exists and default to using that if possible
if command -v aptitude >/dev/null 2>&1 ; then
pm="aptitude"
else
pm="apt-get"
fi
echo -e "\nUsing $pm for package installation\n"
# Update the system before going any further
echo -e "\n=> Updating system (this may take a while)..."
sudo $pm update >> $log_file 2>&1 \
&& sudo $pm -y upgrade >> $log_file 2>&1
echo "==> done..."
# Install build tools
echo -e "\n=> Installing build tools..."
sudo $pm -y install \
wget curl build-essential clang \
bison openssl zlib1g \
libxslt1.1 libssl-dev libxslt1-dev \
libxml2 libffi-dev libyaml-dev \
libxslt-dev autoconf libc6-dev \
libreadline6-dev zlib1g-dev libcurl4-openssl-dev >> $log_file 2>&1
echo "==> done..."
fi
if [[ $distro = centos ]];then
epel_repo_url="http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm"
# Add the EPEL repo if centos
echo -e "\n=> Adding EPEL repo..."
sudo rpm -Uvh $epel_repo_url
echo "==> done..."
fi
if [[ $distro = fedora || $distro = centos ]]; then
# Update the system before going any further
echo -e "\n=> Updating system (this may take a while)..."
sudo yum update -y >> $log_file 2>&1
echo "==> done..."
# Install build tools
echo -e "\n=> Installing build tools..."
sudo yum install -y gcc-c++ patch \
readline readline-devel zlib zlib-devel \
libyaml-devel libffi-devel openssl-devel \
make automake bash curl sqlite-devel mysql-devel >> $log_file 2>&1
echo "==> done..."
fi
echo -e "\n==> done running $distro specific commands..."
# Install Ruby
echo -e "\n=> Downloading Ruby $ruby_version_string \n"
cd $sonicready_path/src && wget $ruby_source_url
echo -e "\n==> done..."
echo -e "\n=> Extracting Ruby $ruby_version_string"
tar -xzf $ruby_source_tar_name >> $log_file 2>&1
echo "==> done..."
echo -e "\n=> Building Ruby $ruby_version_string (this will take a while)..."
cd $ruby_source_dir_name && ./configure --prefix=/usr/local >> $log_file 2>&1 \
&& make >> $log_file 2>&1 \
&& sudo make install >> $log_file 2>&1
echo "==> done..."
# Reload bash
echo -e "\n=> Reloading shell so ruby and rubygems are available..."
if [ -f ~/.bashrc ] ; then
source ~/.bashrc
fi
if [ -f ~/.bash_profile ] ; then
source ~/.bash_profile
fi
echo "==> done..."
echo -e "\n=> Updating Rubygems..."
[[ $distro = fedora || $distro = centos ]] && su && gem update --system --no-ri --no-rdoc >> $log_file 2>&1 || sudo gem update --system --no-ri --no-rdoc
echo "==> done..."
echo -e "\n=> Installing required gems..."
echo -e "Installing watir-webdriver.."
[[ $distro = fedora || $distro = centos ]] && su && gem install watir-webdriver >> $log_file 2>&1 || sudo gem install watir-webdriver >> $log_file 2>&1
echo -e "Done installig watir-webdriver gem."
echo -e "\nInstalling xdo gme"
[[ $distro = fedora || $distro = centos ]] && su && gem install xdo >> $log_file 2 >& || sudo gem install xdo
echo -e "Done installing xdo gem."
echo "### Setup is complete! ###"
echo -e "#################################\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment