=== INSTALL UNDER CENT OS 5.2 ===

== TODO ==

- Gruff configuration still problematic
- Make more tests (those were done in a bare-bone VPS machine)
- Improve the service scripts

== WARNINGS ==

- Assumes running everything as ROOT, unless specified
- Some commands react like 'Wizard' screens, just follow the default choices
- Steps marked with [*] are unknown yet if really necessary

== OS COMPONENTS ==

1.1 Add Yum Repository

wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

1.2 Install Required Packages

yum -y upgrade
yum -y install git apg geoip httpd  mysql mysql-server mysql-devel sqlite sqlite-devel httpd-devel libjpeg libjpeg-devel readline-devel curl-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel libyaml libyaml-devel gcc gcc-c++ autoconf automake 

1.3 Configure MySQL

service mysqld start
/usr/bin/mysqladmin -u root password '[MYSQL_PASSWD]'

2.1 Append to /etc/profile

export PATH=/opt/ruby-enterprise/bin:$PATH
export LD_LIBRARY_PATH="/usr/local/lib"
export LDFLAGS="-L/usr/local/lib -Wl,-rpath,/usr/local/lib"

2.2 Prepend to /etc/ld.so.conf [*]

/usr/local/lib
include ld.so.conf.d/*.conf

2.3 Update changed configuration

source /etc/profile
ldconfig

3.1 Install some components from source

wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.1.tar.gz
tar xvfz onig-5.9.1.tar.gz 
cd onig-5.9.1
./configure && make && make install
cd ..

wget http://www.sphinxsearch.com/downloads/sphinx-0.9.8.tar.gz
tar xvfz sphinx-0.9.8.tar.gz
cd sphinx-0.9.8
./configure && make && make install
cd ..

wget ftp://ftp.imagemagick.net/pub/ImageMagick/ImageMagick-6.4.6-9.tar.gz
tar xvfz ImageMagick-6.4.6-9.tar.gz 
cd ImageMagick-6.4.6-9
./configure && make && make install
cd ..

wget http://rubyforge.org/frs/download.php/48623/ruby-enterprise-1.8.6-20081215.tar.gz
tar xvfz ruby-enterprise-1.8.6-20081215.tar.gz
cd ruby-enterprise-1.8.6-20081215
./installer

4.1 Set up Ruby Enterprise Edition and Passenger

ln -s /opt/ruby-enterprise-1.8.6-20081215 /opt/ruby-enterprise 
mv /usr/bin/ruby /usr/bin/ruby.old
ln -s /opt/ruby-enterprise/bin/ruby /usr/bin/ruby

gem install passenger --no-rdoc --no-ri
passenger-install-apache2-module

4.2 Append to /etc/httpd/conf/httpd.conf

  LoadModule passenger_module /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
  PassengerRoot /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.0.6
  PassengerRuby /opt/ruby-enterprise/bin/ruby
   
  <VirtualHost *:80>
    ServerName your_server.com.br
    DocumentRoot /var/www/gitorious/public
  </VirtualHost>
  
4.3 Install require Ruby Gems

gem install mime-types oniguruma textpow chronic BlueCloth ruby-yadis ruby-openid rmagick geoip ultrasphinx rspec rspec-rails RedCloth echoe daemons geoip --no-rdoc --no-ri

5.1 Download Gitorious

cd /var/www
git clone git://gitorious.org/gitorious/mainline.git gitorious
ln -s /var/www/gitorious/script/gitorious /usr/local/bin/gitorious
rm gitorious/public/.htaccess
mkdir gitorious/log
mkdir gitorious/tmp

6.1 Create /etc/init.d/git-ultrasphinx 

- copy from doc/templates/centos/git-ultrasphinx

6.2 Create /etc/init.d/git-daemon

- copy from doc/templates/centos/git-daemon

6.3 Set up the services

chmod 755 /etc/init.d/git-ultrasphinx
chmod 755 /etc/init.d/git-daemon
chkconfig --add git-ultrasphinx
chkconfig --add git-daemon
chkconfig git-ultrasphinx on
chkconfig git-daemon on
chkconfig sendmail on
chkconfig mysqld on
chkconfig httpd on
service sendmail start
service mysqld start

7.1 Create the 'git' user (can be another name instead of 'git')

adduser git
chown -R git:git /var/www/gitorious

su - git            <================= ATTENTION: LOGGED AS GIT FROM NOW ON (!)
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
cd /var/www/gitorious
cp config/database.sample.yml config/database.yml
cp config/gitorious.sample.yml config/gitorious.yml

7.2 Edit config/database.yml

- Probably need to chanage password to [MYSQL_PASSWD] as set up above

7.3 Edit config/gitorious.yml

  # The session secret key (`apg -m 64` is always useful for this kinda stuff)
  cookie_secret: frie...kceft
   
  # The path where git repositories are stored. The actual (bare) repositories resides
  # in repository_base_path/#{project.slug}/#{repository.name}.git/:
  repository_base_path: "/home/git"
   
  # Stuff that's in the html <head>. custom stats javascript code etc
  extra_html_head_data:
    
  # System message that will appear on all pages if present
  system_message:
    
  # Port the ./script/gitorious script should use:
  gitorious_client_port: 80
   
  # Host the ./script/gitorious script should use:
  gitorious_client_host: localhost
   
  # Host which is serving the gitorious app, eg "gitorious.org"
  gitorious_host: servidor.local
   
  # User which is running git daemon
  gitorious_user: git
  
  # Email spam on server errors to:
  exception_notification_emails:  
  
  # Mangle visible e-mail addresses (spam protection)
  mangle_email_addresses: true

  # Enable or Disable Public Mode (true) or Private Mode (false)
  public_mode: false

  # Define your locale
  locale: en

7.3.1 Remarks on gitorious.yml

- run apg -m 64
- copy the result (big string, take off the line breaks to have just one 
  continuous line)
- configure 'gitorious_host' to your registered domain, if you have one
- configure 'gitorious_user' if you created the 'git' user above

7.4 Final Website Setup

cd /var/www/gitorious
rake db:create RAILS_ENV=production
rake db:migrate RAILS_ENV=production
rake ultrasphinx:bootstrap RAILS_ENV=production

7.5 Setup CronJobs

- type in 'crontab -e'
- it will open an editor (probably nano)
- copy and paste the following 2 lines:

*/2 * * * * /opt/ruby-enterprise/bin/ruby /var/www/gitorious/script/task_performer
* */1 * * * cd /var/www/gitorious && /opt/ruby-enterprise/bin/rake ultrasphinx:index RAILS_ENV=production

8.1 Append to /home/git/.bash_profile [*]

# User specific aliases and functions
export RUBY_HOME=/opt/ruby-enterprise
export GEM_HOME=$RUBY_HOME/lib/ruby/gems/1.8/gems
export PATH=$RUBY_HOME/bin:$PATH

9.1 Start services

- if you're still as ser 'git', type 'exit' to go back to Root

exit
service httpd start
service git-daemon start

9.2 Create /etc/logrotate.d/gitorious, add this content:

- copy content from doc/templates/centos/gitorious-logrotate

9.3 Set permission for /etc/logrotate.d/gitorious

chmod 644 /etc/logrotate.d/gitorious


10 DONE

Open your browser, go to your main website, it should take a minute to cold start
Phusion Passenger. Then you should already be able to start operating on the system.