#!/bin/bash # # # #Script to install Ruby on Rails on a cPanel server # # #This script is ©2006 Defender Technologies Group LLC., #and may not be reproduced in part or full without permission # #Tony Dodd # # if [ x`which GET` == "x" ] then echo "Sorry, GET is required for this script to run" exit 2 fi if [ `id | awk '{print $1}' | sed -e 's/(.*)$//g' | cut -d"=" -f2` -ne "0" ] then echo "Sorry, root is required for this script to run" exit 2 fi function rubyver { #function will grab the download url for latest ruby ruby_url=`GET http://ruby-lang.org/en/20020102.html | grep "stable release" -m1 | cut -d"<" -f4 | cut -d"\"" -f2` ruby_version=`echo $ruby_url | cut -d"/" -f6 | sed -e 's/\.tar\.gz//g'` ruby_file=`echo $ruby_url | cut -d"/" -f6` } function doruby { if [ -e /usr/src/rubyfiles/ruby/$ruby_version ] then echo "$ruby_version already installed, skipping" else mkdir -p /usr/src/rubyfiles/ruby cd /usr/src/rubyfiles/ruby wget $ruby_url tar -zxvf $ruby_file cd $ruby_version ./configure && make && make install fi } function gemsver { gems_url=http\:\/\/rubyforge.org`GET http://rubyforge.org/frs/?group_id=126 | grep rubygems\- -m1 | cut -d"\"" -f2` gems_version=`echo $gems_url | cut -d"/" -f7 | sed -e 's/\.tgz//g'` gems_file=`echo $gems_url | cut -d"/" -f7` } function dogems { if [ -e /usr/src/rubyfiles/gems/$gems_version ] then echo "$gems_version already installed, skipping" else mkdir /usr/src/rubyfiles/gems # if rubyfiles hasn't been created yet, there is a problem. cd /usr/src/rubyfiles/gems wget $gems_url tar -zxvf $gems_file cd $gems_version ruby setup.rb fi } function dorails { gem install rails -y #more of a placeholder than a real function, in case this method ever needs to be revised. } function fcgiver { #again, another semi place-holder in case this changes in future. fcgi_url="http://fastcgi.com/dist/fcgi-2.4.0.tar.gz" fcgi_version="fcgi-2.4.0" fcgi_file="fcgi-2.4.0.tar.gz" } function dofcgi { if [ -e /usr/src/rubyfiles/fcgi/$fcgi_version ] then echo "$fcgi_version already installed, skipping" else mkdir /usr/src/rubyfiles/fcgi cd /usr/src/rubyfiles/fcgi wget $fcgi_url tar -zxvf $fcgi_file cd $fcgi_version ./configure && make && make install fi } function modfcgiver { #another place-holder modfcgi_url="http://fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz" modfcgi_version="mod_fastcgi-2.4.2" modfcgi_file="mod_fastcgi-2.4.2.tar.gz" } function domodfcgi { if [ -e /usr/src/rubyfiles/mod_fcgi/$modfcgi_version ] then echo "$modfcgi_version already installed, skipping" else mkdir /usr/src/rubyfiles/mod_fcgi cd /usr/src/rubyfiles/mod_fcgi wget $modfcgi_url tar -zxvf $modfcgi_file cd $modfcgi_version $apxs -o mod_fastcgi.so -c *.c $apxs -i -a -n fastcgi mod_fastcgi.so fi } function findapxs { if [ -e /usr/local/apache/bin/apxs ] then apxs="/usr/local/apache/bin/apxs" echo "found apxs at $apxs" elif [ -n `whereis apxs | awk '{print $2}'` ] then apxs="`whereis apxs | awk '{print $2}'`" echo "found apxs at $apxs" else echo "I cannot find apxs, please add a symlink to it in /usr/sbin/ then run me again" exit 2 fi } function dogemfcgi { #placeholder gem install fcgi -y } function httpdconf { if [ -e /etc/httpd/conf/httpd.conf ] then httpd_conf="/etc/httpd/conf/httpd.conf" else httpd_conf="/usr/local/apache/conf/httpd.conf" fi fcgi_if_line=`cat $httpd_conf -n | grep AccessFile -m1 -B1 | head -1 | awk '{print $1}'` fcgi_load_line=$(( `cat -n $httpd_conf | head -300 | grep LoadModule | tail -1 | awk '{print $1}'` + 1 )) cd /usr/src/rubyfiles/scripts/ chmod +x insertext.sh /usr/src/rubyfiles/scripts/insertext.sh $fcgi_if_line fcgi_if $httpd_conf /usr/src/rubyfiles/scripts/insertext.sh $fcgi_load_line fcgi_load $httpd_conf /etc/init.d/httpd restart } function getsupport { #grab support scripts that we need mkdir -p /usr/src/rubyfiles/scripts/ cd /usr/src/rubyfiles/scripts if [ -e insertext.sh ] then echo "insertext.sh already exists, overwriting" wget -O insertext.sh http://download.powervps.com/scriptsupport/insertext.sh else wget -O insertext.sh http://download.powervps.com/scriptsupport/insertext.sh fi if [ -e fcgi_load ] then echo "fcgi_load already exists, overwriting" wget -O fcgi_load http://download.powervps.com/scriptsupport/fcgi_load else wget -O fcgi_load http://download.powervps.com/scriptsupport/fcgi_load fi if [ -e fcgi_if ] then echo "fcgi_if already exists, overwriting" wget -O fcgi_if http://download.powervps.com/scriptsupport/fcgi_if else wget -O fcgi_if http://download.powervps.com/scriptsupport/fcgi_if fi } function folders { mkdir -p /fcgi_ipc chown nobody.nobody /fcgi_ipc -R chmod 755 /fcgi_ipc -R } function cleaning_up { echo "cleaning up files we do not need" rm -rf /usr/src/rubyfiles } function finished { echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! !! !! INSTALLATION COMPLETE !! !! !! !! The following will get a test app set up to make sure RoR is working. !! !! !! !! cd /home/USER !! !! rails /home/USER/testapp !! !! cd /home/USER/testapp/ !! !! ruby script/generate controller test !! !! cd /home/USER/public_html !! !! ln -s ../testapp/public rails !! !! !! !! Then visit http://www.yourtestdomain.com/rails/ !! !! and you should see a congratulations page. !! !! !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" } getsupport findapxs rubyver gemsver fcgiver modfcgiver doruby dogems dorails dofcgi domodfcgi dogemfcgi httpdconf folders cleaning_up finished