#!/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 timeInitial=`date +%H%M%S` installTime=$timeInitial # CONSTANTS RHOCONNECT_VERSION="3.0.0.beta3" DEPS=(gcc tar make wget) # FUNCTIONS echoLog () { timeStamp="[`date`]: " echo -e $1 #end echoLog } showHelp () { echoLog " Usage: install.sh [options]\n --no-redis Skip the installation of the redis server.\n --offline Check that all necessary files are installed in /opt/rhoconnect if no prefix is specified.\n -p, --prefix PREFIX Specify PREFIX as the installation directory. Default is /opt/rhoconnect.\n -r, --ruby-version VERSION Specify version of ruby to install. Default is Ruby Enterprise.\n -s, --silent Perform installation with minimal output.\n --skip-ruby Use system ruby instead of ruby installed through this installer.\n -w, --web-server SERVER Specify that you are using web server SERVER. Default is Nginx.\n -h, --help Display this screen.\n " # End script after printing help message exit } #end showHelp 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 echoLog "Dependencies Missing: " | tee -a $log echoLog "${missingDeps}" | tee -a $log echoLog "These must be installed before setup can continue..." | tee -a $log exit fi } #end checkDeps 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 echoLog "No supported package manager." | tee -a $log echoLog "Please install apt-get or yum to continue..." | tee -a $log exit fi } #end determinePkgMgr 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 ;; "v" ) rhoconnectVersion=$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 ;; -v ) getVal="v" ;; --help | -h ) showHelp ;; * ) #if [ "${i}" ]; then # echoLog "${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 # 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 > tempout 2>&1 exitStatus=$? cat tempout | tee -a $log } #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 echoLog "${rubyVersion} is not a valid ruby version" | tee -a $log exit fi } #end setRubyVars installRuby () { if [[ ! -d "${prefix}${rubyDir}" ]]; then echoLog "Loading ruby tarball ..." | tee -a $log echoLog "wget -P ${prefix} ${rubyURL}" | tee -a $log wget -P ${prefix} ${rubyURL} echoLog "tar -xzf ${prefix}/${rubyTar} -C ${prefix}" | tee -a $log tar -xzf ${prefix}/${rubyTar} -C ${prefix} fi echoLog "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 "echoLog \"${rubyVersion} is not a supported ruby version\"" exit ;; esac if [[ $exitStatus != 0 ]]; then echoLog "Some dependencies not installed..." | tee -a $log echoLog "Please install them and then re-run the installation script." | tee -a $log exit fi rm tempout } #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 echoLog "\nInstallation completed in ${timeHour}${timeMin}${timeSec}." } #end getTime # SCRIPT # Get starting directory startDir=`pwd` if [[ $startDir =~ "rhoconnect-${RHOCONNECT_VERSION}" ]]; then INSTALL_DIR="/tmp/installdir/rhoconnect-${RHOCONNECT_VERSION}" 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=$(echoLog $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 echoLog "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 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 opts=" -d $dist" sudo ${prefix}/bin/ruby ${INSTALL_DIR}/utils/create_texts.rb ${opts} # timeFinal=`date +%H%M%S` # getTime $timeFinal fi