#! /bin/bash

# setup our install dir
#

mkdir -p /opt/local/oracle

cd /opt/local/oracle

# step one is to download the dsk from oracle :
#
# http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
#
# grab the sdk - note that you actually have to sign up and click yes to an
# agreement to do this
#

wget\
  http://download.oracle.com/otn/mac/instantclient/10204/instantclient-sdk-macosx-10.2.0.4.0.zip

# unpack
#

unzip instantclient-sdk-macosx-10.2.0.4.0.zip

# setup your environment to point to the install
#

cat >> ~/.bash_profile <<'bash_profile'
  # oracle crap
  export ORACLE_HOME=/opt/local/oracle/instantclient_10_2/
  export TNS_ADMIN=$ORACLE_HOME
  export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$ORACLE_HOME
bash_profile

. ~/.bash_profile

# and now you should be to install the ruby bindings - note that i've had poor
# luck with the gem install and so compile manually
#

wget http://rubyforge.org/frs/download.php/39145/ruby-oci8-1.0.2.tar.gz
tar xvfz ruby-oci8-1.0.2.tar.gz
cd ruby-oci8-1.0.2
ruby setup.rb config && ruby setup.rb setup && sudo ruby setup.rb install

# finally, grab the oracle adapter for active record
#

sudo gem install activerecord-oracle-adapter --source http://gems.rubyonrails.org

# icing on the cake for me is setting up a local tnsnames file, i have
# something like this
#

mkdir -p /opt/local/oracle/instantclient_10_2/network/admin/
cp tnsnames.ora /opt/local/oracle/instantclient_10_2/network/admin/

#
# and entries like these in tnsnames
#
#
# GDBT =
#   (DESCRIPTION =
#     (ADDRESS_LIST =
#       (ADDRESS = (PROTOCOL = TCP)(Host = 127.0.0.1)(Port = 1538))
#     )
#     (CONNECT_DATA =
#       (SERVICE_NAME = GDBT.SOMEWHERE.GOV)
#     )
#   )
#

#
# then i use ssh tunnels like so
#

ssh gdbt.somewhere.gov -L 1538:0.0.0.0:1538 -L

#
# and a config/database.yml looking like this - notice this makes the
# connection to localhost
#
#
#
# development:
#   adapter: oracle
#   database: GDBT
#   username: zaphod 
#   password: beblebrox 
#