=== INSTALL UNDER UBUNTU 8.10 ===

== 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

== OS COMPONENTS ==

1.1 Install Required Packages

apt-get update
apt-get install -y build-essential apache2 mysql-server mysql-client git git-svn apg geoip-bin libgeoip1 libgeoip-dev sqlite3 libsqlite3-dev imagemagick libpcre3 libpcre3-dev zlib1g zlib1g-dev libyaml-dev libmysqlclient15-dev apache2-dev sendmail

1.2 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 ..

1.2.3 Set up ActiveMQ

apt-get install uuid uuid-dev openjdk-6-jre
wget http://www.powertech.no/apache/dist/activemq/apache-activemq/5.2.0/apache-activemq-5.2.0-bin.tar.gz
tar xzvf apache-activemq-5.2.0-bin.tar.gz  -C /usr/local/
echo "export ACTIVEMQ_HOME=/usr/local/apache-activemq-5.2.0" >> /etc/activemq.conf
echo "export JAVA_HOME=/usr/" >> /etc/activemq.conf
adduser --system --no-create-home  activemq
chown -R activemq /usr/local/apache-activemq-5.2.0/data

# turn off the default multicasting activemq does, or other brokers on the
# same network will receive your queue items
vim /usr/local/apache-activemq-5.2.0/conf/activemq.xml
# edit the networkConnectors conf to something like this:
<networkConnectors>
    <!-- by default just auto discover the other brokers -->
    <!-- <networkConnector name="default-nc" uri="multicast://default"/> -->
    <!-- Example of a static configuration: -->
    <networkConnector name="localhost" uri="static://(tcp://127.0.0.1:61616)"/>
</networkConnectors>
wget http://launchpadlibrarian.net/15645459/activemq
mv activemq /etc/init.d/activemq
chmod +x /etc/init.d/activemq

2.1 Install Ruby Enterprise Edition

wget http://rubyforge.org/frs/download.php/48625/ruby-enterprise_1.8.6-20081215-i386.deb
dpkg -i ruby-enterprise_1.8.6-20081215-i386.deb

2.2 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.3 Prepend to /etc/ld.so.conf

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

2.4 Update changed configuration

source /etc/profile
ldconfig

2.5 Set up Ruby Enterprise Edition and Passenger

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

3.1 Create /etc/apache2/mods-available/passenger.load with:

  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
  
3.2 Symlink Passenger into Apache

  ln -s /etc/apache2/mods-available/passenger.load /etc/apache2/mods-enabled/passenger.load 

3.3 Create /etc/apache2/sites-available/gitorious with:

  <VirtualHost *:80>
    ServerName your_server.com.br
    DocumentRoot /var/www/gitorious/public
  </VirtualHost>
  
3.4 Symlink the Site

  ln -s /etc/apache2/sites-available/gitorious /etc/apache2/sites-enabled/000-gitorious
  rm /etc/apache2/sites-enabled/000-default

4.1 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/ubuntu/git-ultrasphinx

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

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

6.3 Set up the services

chmod +x /etc/init.d/git-ultrasphinx
chmod +x /etc/init.d/git-daemon
update-rc.d -f git-daemon start 99 2 3 4 5 .
update-rc.d -f git-ultrasphinx start 99 2 3 4 5 .

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 the one that was asked to you during
  the apt packages installation in step 1.1

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
- replace the result (big string, take off the line breaks to have just one 
  continuous line) with value of the the current 'cookie_secret'
- 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 [UNKNOWN] 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

/etc/init.d/git-daemon start
/etc/init.d/git-ultrasphinx start

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

- copy content from doc/templates/ubuntu/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.