#!/bin/bash # DO FIRST # make sure only run as root if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" exit 1 fi # Check if web server is running on port 80 if [[ `echo "close" | telnet localhost 80 2>&1 | grep "Connected"` ]]; then echo "Web server on port 80 is running." echo "Please stop it and then re-run the installation script." exit 1 fi timeInitial=`date +%H%M%S` installTime=$timeInitial # CONSTANTS DEPS=(gcc tar make wget) # FUNCTIONS # showHelp # Prints options to the screen showHelp () { cat << _USAGE_ Usage: install.sh [options] --no-redis Skip the installation of the redis server. --offline Check that all necessary files are installed in /opt/rhoconnect if no prefix is specified. -p, --prefix PREFIX Specify PREFIX as the installation directory. Default is /opt/rhoconnect. -r, --ruby-version VERSION Specify version of ruby to install. Default is Ruby Enterprise. -s, --silent Perform installation with minimal output. --skip-ruby Use system ruby instead of ruby installed through this installer. -w, --web-server SERVER Specify that you are using web server SERVER. Default is Nginx. -h, --help Display this screen. _USAGE_ exit } # checkDeps # Checks that all common dependencies are present, exits if not checkDeps () { missingDeps="" for ((i=0; i<${#DEPS[@]}; i++)) do dep=`which ${DEPS[$i]} 2> /dev/null` if [[ $dep == "" ]]; then missingDeps="${missingDeps}${DEPS[$i]}\n" fi done if [[ $missingDeps != "" ]]; then echo "Dependencies Missing: " | tee -a $log echo "${missingDeps}" | tee -a $log echo "These must be installed before setup can continue..." | tee -a $log exit fi } #end checkDeps # determinePkgMgr # Determines if the system is currently using rpm or # debian based pckage management determinePkgMgr () { if [[ `which apt-get 2> /dev/null` != "" ]]; then pkgMgr="apt-get -y" dist='debian' elif [[ `which yum 2> /dev/null` != "" ]]; then pkgMgr="yum -y" dist='yum' else echo "No supported package manager." | tee -a $log echo "Please install apt-get or yum to continue..." | tee -a $log exit fi } #end determinePkgMgr # parseOpts # Parses options passed to the install script parseOpts () { for i in "$*"; do i=$(echo $i | tr '[:upper:]' '[:lower:]') opts="${opts}${i} " # looking for getVal flag to grab next value. case $getVal in "p" ) prefix=$i ;; "w" ) webServer=$i ;; "r" ) rubyVersion=$i ;; * ) ;; esac # Check options passed in and assign flags where applicable case $i in --web-server | -w ) getVal="w" ;; --prefix | -p ) getVal="p" ;; --ruby-version ) getVal="r" ;; --offline ) ;; --silent | -s ) ;; --skip-redis ) redis=false ;; --skip-ruby ) ruby=false ;; --help | -h ) showHelp ;; * ) #if [ "${i}" ]; then # echo "${i} is not a valid option" | tee -a $log # exit #fi ;; esac done } #end parseOpts cleanPrefix () { # make sure there are no double /'s in the prefix path prefix=${prefix/\/\/+/"/"} # make sure path is absolute for ruby EE installation if [[ $prefix == *\.* ]]; then prefix=${prefix/\./`pwd`} fi # make sure prefix exists, create if not if ! [ -d $prefix ]; then mkdir -p $prefix fi } #end cleanPrefix setPrefixDependantPaths () { # if rubyBinDir not specified if [$rubyBinDir == ""]; then rubyBinDir="${prefix}/ruby/bin" fi # If logs directory does not exist, create it if ! [[ -d "${prefix}/logs/" ]]; then mkdir "${prefix}/logs/" fi # Make path to log file absolute and create directory if not already existent log="${prefix}/logs/${log}" touch $log > /dev/null # Add the log file path to the info file `echo $log >> info.dat` #cat info.dat # Move info.dat into installation directory if not already there if ! [ -e "${prefix}/info.dat" ]; then mv info.dat "${prefix}/info.dat" fi } #end setPrefixDependantPaths setDefaults () { # if $prefix not specified set to /opt/rhoconnect if [$prefix == ""]; then prefix="/opt/rhoconnect" fi # if $webServer not specified set to nginx if [$webServer == ""]; then webServer="nginx" fi } #end setDefaults logAndPrint () { $1 > $log 2>&1 exitStatus=$? } #end logAndPrint setRubyVars () { if [[ $rubyVersion == "" || $rubyVersion =~ ruby'ee'|'enterprise' ]]; then rubyVersion="rubyee" rubyDir="ruby-enterprise-1.8.7-2011.03" rubyTar="${rubyDir}.tar.gz" rubyURL="http://rubyenterpriseedition.googlecode.com/files/${rubyTar}" elif [$rubyVersion == "ruby187"]; then rubyDir="ruby-1.8.7" rubyTar="${rubyDir}.tar.gz" rubyURL="ftp://ftp.ruby-lang.org/pub/ruby/1.8/${rubyTar}" elif [$rubyVersion == "ruby192"]; then rubyDir="ruby-1.9.2-p180" rubyTar="${rubyDir}.tar.gz" rubyURL="http://ftp.ruby-lang.org/pub/ruby/1.9/${rubyTar}" else echo "${rubyVersion} is not a valid ruby version" | tee -a $log exit fi } installRuby () { if [[ ! -d "${prefix}${rubyDir}" ]]; then echo "Downloading ${rubyURL} ..." | tee -a $log echo "wget -P ${prefix} ${rubyURL}" >> $log wget -P ${prefix} ${rubyURL} > $log 2>&1 echo "tar -xzf ${prefix}/${rubyTar} -C ${prefix}" >> $log tar -xzf ${prefix}/${rubyTar} -C ${prefix} > $log 2>&1 fi echo "Installing ruby. This may take some time..." | tee -a $log case $rubyVersion in rubyee) logAndPrint "${prefix}/${rubyDir}/installer --dont-install-useful-gems --no-dev-docs --auto ${prefix}" ;; ruby187) logAndPrint "${prefix}/${rubyDir}/configure --prefix=\"${prefix}\"" logAndPrint "make && make install" ;; ruby192) logAndPrint "${prefix}/${rubyDir}/configure --prefix=\"${prefix}\"" logAndPrint "make && make install" ;; *) logAndPrint "echo \"${rubyVersion} is not a supported ruby version\"" exit ;; esac if [[ $exitStatus != 0 ]]; then echo "Some dependencies not installed..." | tee -a $log echo "Please install them and then re-run the installation script." | tee -a $log echo "For troubleshooting see file $log ..." | tee -a $log exit fi echo "Ruby $rubyDir is successfully installed." | tee -a $log } #end installRuby getTime () { timeDiff=$(( $1 - $timeInitial )) timeSec=$(( $timeDiff % 100 )) timeDiff=$(( $timeDiff / 100 )) if [ $timeSec -gt 1 ]; then timeSec=$timeSec" seconds" else timeSec=$timeSec" second" fi if [ $timeDiff -gt 0 ]; then timeMin=$(( $timeDiff % 100 )) timeDiff=$(( $timeDiff / 100 )) if [ $timeMin -gt 1 ]; then timeMin=$timeMin" minutes and " else timeMin=$timeMin" minute and " fi fi if [ $timeDiff -gt 0 ]; then timeHour=$(( $timeDiff % 100 )) timeDiff=$(( $timeDiff / 100 )) if [ $timeHour -gt 1 ]; then timeHour=$timeHour" hours, " else timeHour=$timeHour" hour, " fi fi echo "\nInstallation completed in ${timeHour}${timeMin}${timeSec}." } #end getTime # SCRIPT # Get starting directory startDir=`pwd` if [[ $startDir = "/opt/rhoconnect/installer" ]]; then #FIXME: INSTALL_DIR="/opt/rhoconnect/installer" else INSTALL_DIR="./installer" fi # define log file name DATEFILE=`date +%Y%m%d%H%M%S` log=rhoconnect_$(date +$DATEFILE).log # Make sure basic system dependencies are installed checkDeps # Determine which package management the system uses (Debian short-circuted) determinePkgMgr # define option variables opts="" prefix="" getVal="" webServer="" rubyVersion="" rubyBinDir="" # parse command-line options parseOpts "$*" # Set default Values setDefaults # Reformat ruby version to fit this scripts format # Tolower rubyVersion rubyVersion=$(echo $rubyVersion | tr '[:upper:]' '[:lower:]') # Remove all white space rubyVersion=${rubyVersion//[[:space:]]} # Remove periods and hyphens such as those present in version numbers rubyVersion=${rubyVersion//[-.]/} # Set ruby insatallation variables setRubyVars # Clean up the formatting of prefix cleanPrefix # Once the prefix path is cleaned up... setPrefixDependantPaths # Install ruby if not already installed if ! [ -e "${prefix}/bin/ruby" ]; then installRuby else echo "Ruby already installed" | tee -a $log fi # Construct the string with which to call the ruby installation script. callruby="sudo ${prefix}/bin/ruby ${INSTALL_DIR}/unix-like/rhoinstaller.rb ${opts}" # Call the ruby script $callruby rho_status=$? if [[ $installedSoftware -eq ${#INSTALL_ARRAY[@]} ]]; then rm "${prefix}/info.dat" if [ -e $prefix$rubyTar ]; then mv $prefix/$rubyTar $prefix"/downloads/"$rubyTar fi if [ -e $prefix$rubyDir ]; then mv $prefix$rubyDir $prefix"/downloads/"$rubyDir fi if [ ! -e $prefix"/post-install" ]; then mkdir $prefix"/post-install" fi if (( $rho_status )) ; then echo "Installation failed. For troubleshooting see file $log ..." | tee -a $log else opts=" -d $dist" sudo ${prefix}/bin/ruby ${INSTALL_DIR}/unix-like/create_texts.rb ${opts} fi # timeFinal=`date +%H%M%S` # getTime $timeFinal fi