--- /dev/null
+#!/bin/bash
+
+# Install script for Biopieces.
+# October 2011, Martin A. Hansen
+
+bp_code="$HOME/biopieces"
+bp_data="$HOME/BP_DATA"
+ bp_log="/var/log"
+ bp_tmp="/tmp"
+
+# Function that renders a given message in ASCII green.
+function echo_green
+{
+ local msg=$1
+
+ echo -e "\033[32;38m$msg\033[0m"
+}
+
+# Function that renders a given message in ASCII yellow.
+function echo_yellow
+{
+ local msg=$1
+
+ echo -e "\033[33;38m$msg\033[0m"
+}
+
+# Function that renders a given message in ASCII red.
+function echo_red
+{
+ local msg=$1
+
+ echo -e "\033[31;38m$msg\033[0m"
+}
+
+# Function to output an abort message and exit
+function abort
+{
+ echo_red "abort"
+
+ exit
+}
+
+# Function to create a directory is it doesn't exist.
+function dir_create
+{
+ local dir=$1
+
+ echo -n "Creating $dir: "
+
+ if error=$( mkdir $dir 2>&1 ); then
+ echo_green "OK"
+ else
+ echo_red "FAIL"
+ echo $error
+ abort
+ fi
+}
+
+# Function to prompt for continuation of installation.
+function prompt_install
+{
+ echo ""
+ echo "Welcome to the Biopieces installer."
+ echo ""
+ echo " This installer is experimental, and is being evaluated to replace"
+ echo " the previous, tedious way:"
+ echo ""
+ echo " http://code.google.com/p/biopieces/wiki/Installation"
+ echo ""
+ echo " If you experience problems, please report to the Google Group (see below)"
+ echo ""
+ echo " The installer will now do the following:"
+ echo ""
+ echo " - Check prerequisites:"
+ echo " * Subversion client"
+ echo " * Perl"
+ echo " * Perl modules"
+ echo " * Ruby"
+ echo " * Ruby gems"
+ echo " * Auxillary programs"
+ echo ""
+ echo " - Create installation directories"
+ echo " - Download code from repository"
+ echo " - Set environment in .bashrc"
+ echo " - Run tests"
+ echo ""
+ echo " Problems? Check out the FAQ:"
+ echo ""
+ echo " http://code.google.com/p/biopieces/wiki/FAQ"
+ echo ""
+ echo " Help is available at the Biopieces Google Group:"
+ echo ""
+ echo " http://groups.google.com/group/biopieces"
+ echo ""
+
+ while true; do
+ read -p "Continue (yes/no)? " answer
+ case $answer in
+ [Yy]* ) break;;
+ [Nn]* ) abort;;
+ esac
+ done
+}
+
+# Function to prompt the selection of the code directory.
+function prompt_install_dir_code
+{
+ read -p "Enter directory to install Biopieces code (default: $bp_code): " answer;
+
+ bp_code=${answer:-"$bp_code"}
+
+ if [ ! -d "$bp_code" ]; then
+ while true; do
+ read -p "Create directory: $bp_code (yes/no)? " answer
+ case $answer in
+ [Yy]* ) dir_create $bp_code && break;;
+ [Nn]* ) abort;;
+ esac
+ done
+ fi
+}
+
+# Function to prompt the selection of the data directory.
+function prompt_install_dir_data
+{
+ read -p "Enter directory to install Biopieces data (default: $bp_data): " answer;
+
+ bp_data=${answer:-"$bp_data"}
+
+ if [ ! -d "$bp_data" ]; then
+ while true; do
+ read -p "Create directory: $bp_data (yes/no)? " answer
+ case $answer in
+ [Yy]* ) dir_create $bp_data && break;;
+ [Nn]* ) abort;;
+ esac
+ done
+ fi
+}
+
+# Function to prompt the selection of the log directory.
+function prompt_install_dir_log
+{
+ read -p "Enter directory to install Biopieces log (default: $bp_log): " answer;
+
+ bp_log=${answer:-"$bp_log"}
+
+ if [ ! -d "$bp_log" ]; then
+ while true; do
+ read -p "Create directory: $bp_log (yes/no)? " answer
+ case $answer in
+ [Yy]* ) dir_create $bp_log && break;;
+ [Nn]* ) abort;;
+ esac
+ done
+ fi
+}
+
+# Function to prompt the selection of the tmp directory.
+function prompt_install_dir_tmp
+{
+ read -p "Enter directory to install Biopieces tmp (default: $bp_tmp): " answer;
+
+ bp_tmp=${answer:-"$bp_tmp"}
+
+ if [ ! -d "$bp_tmp" ]; then
+ while true; do
+ read -p "Create directory: $bp_tmp (yes/no)? " answer
+ case $answer in
+ [Yy]* ) dir_create $bp_tmp && break;;
+ [Nn]* ) abort;;
+ esac
+ done
+ fi
+}
+
+# Function to prompt the appending of a section to bashrc.
+function prompt_append_bashrc
+{
+ section="
+
+# >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<<
+
+export BP_DIR=\"$bp_code\"
+export BP_DATA=\"$bp_data\"
+export BP_TMP=\"$bp_tmp\"
+export BP_LOG=\"$bp_log\"
+
+source \"\$BP_DIR/bp_conf/bashrc\"
+
+# >>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<
+
+"
+
+ echo_yellow "$section"
+ echo "We need to append the above section to your .bashrc file."
+
+ while true; do
+ read -p "Continue (yes/no)? " answer
+ case $answer in
+ [Yy]* ) break;;
+ [Nn]* ) abort;;
+ esac
+ done
+
+ echo -n "Appending $HOME/.bashrc: "
+
+ cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"
+
+ echo "$section" >> "$HOME/.bashrc"
+
+ source "$HOME/.bashrc"
+
+ echo_green "OK"
+}
+
+
+# Function to test if subversion client is in $PATH.
+function test_svn
+{
+ local program="svn"
+
+ echo -n "Testing subversion client - \"$program\": "
+
+ if command -v $program >/dev/null; then
+ echo_green "OK"
+ else
+ echo_red "FAIL"
+ echo " Subversion client $program was not found."
+ abort
+ fi
+}
+
+# Function to test if the required version of Perl is installed.
+function test_perl
+{
+ echo -n "Testing Perl version: "
+
+ if error=$( perl -e 'use 5.8.0;' 2>&1 ); then
+ echo_green "OK"
+ else
+ echo_red "FAIL"
+ echo $error | sed "s/, stopped.*//"
+ abort
+ fi
+}
+
+# Function to test if a given Perl module is installed.
+function test_perl_module
+{
+ local module=$1
+
+ echo -n "Testing required Perl module - \"$module\": "
+
+ if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then
+ echo_red "FAIL"
+ echo " Try: perl -MCPAN -e 'install $module'"
+ abort
+ else
+ echo_green "OK"
+ fi
+}
+
+# Function to test if the required version of Ruby is installed.
+function test_ruby
+{
+ echo -n "Testing Ruby version: "
+
+ if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
+ echo_green "OK"
+ else
+ echo_red "FAIL"
+ echo $error | sed "s/.*: //"
+ abort
+ fi
+}
+
+# Function to test if a given Ruby gem is installed.
+function test_ruby_gem
+{
+ local gem=$1
+
+ echo -n "Testing required Ruby gem - \"$gem\": "
+
+ if error=$( gem list --local | grep $gem ); then
+ echo_green "OK"
+ else
+ echo_red "FAIL"
+ echo " Try: gem install $gem"
+ abort
+ fi
+}
+
+# Function to test is a given auxillary program is in $PATH.
+function test_aux_program
+{
+ local program=$1
+
+ echo -n "Testing auxiliary program - \"$program\": "
+
+ if command -v $program >/dev/null; then
+ echo_green "OK"
+ else
+ echo_yellow "WARNING"
+ fi
+}
+
+# Function to checkout the Biopieces code from subversion.
+function checkout_code
+{
+ echo -n "Downloading Biopieces code from repository: "
+
+ if error=$( svn checkout http://biopieces.googlecode.com/svn/trunk/ $bp_code ); then
+ echo_green "OK"
+ else
+ echo_red "FAIL"
+ echo $error
+ abort
+ fi
+}
+
+# Function to checkout the Biopieces wiki from subversion.
+function checkout_wiki
+{
+ echo -n "Downloading Biopieces wiki from repository: "
+
+ if error=$( svn checkout http://biopieces.googlecode.com/svn/wiki/ "$bp_code/bp_usage" ); then
+ echo_green "OK"
+ else
+ echo_red "FAIL"
+ echo $error
+ abort
+ fi
+}
+
+# Function to run the Biopieces test suite.
+function run_tests
+{
+ while true; do
+ read -p "Run the Biopieces test suite (yes/no)? " answer
+ case $answer in
+ [Yy]* ) "$BP_DIR/bp_test/test_all" && break;;
+ [Nn]* ) break;;
+ esac
+ done
+}
+
+prompt_install
+
+test_svn
+test_perl
+test_perl_module "Inline"
+test_perl_module "JSON::XS"
+test_perl_module "SVG"
+test_perl_module "Bit::Vector"
+test_perl_module "Time::HiRes"
+test_ruby
+test_ruby_gem "gnuplot"
+test_ruby_gem "narray"
+test_aux_program "blastall"
+test_aux_program "blat"
+test_aux_program "bwa"
+test_aux_program "bowtie"
+test_aux_program "formatdb"
+test_aux_program "gnuplot"
+test_aux_program "idba"
+test_aux_program "muscle"
+test_aux_program "mummer"
+test_aux_program "mysql"
+test_aux_program "prodigal"
+test_aux_program "Ray"
+test_aux_program "scan_for_matches"
+test_aux_program "uclust"
+test_aux_program "velveth"
+test_aux_program "velvetg"
+test_aux_program "vmatch"
+
+echo ""
+
+prompt_install_dir_code
+prompt_install_dir_data
+prompt_install_dir_log
+prompt_install_dir_tmp
+
+checkout_code
+checkout_wiki
+
+prompt_append_bashrc
+
+run_tests
+
+echo ""
+echo_green "Congratulations - you have now installed Biopieces."
+echo ""
+echo " To list all available Biopieces try 'list_biopieces'"
+echo ""
+echo " To see the synopsis of a Biopiece try 'read_fastq'"
+echo ""
+echo " To see the full description and exampels try 'read_fastq -?'"
+echo ""
+echo " Don't forget to join the Biopieces Google Group for important"
+echo " messages, questions, discussion, and suggestions:"
+echo ""
+echo " http://groups.google.com/group/biopieces"
+echo ""
+echo " And of cause there is the introduction:"
+echo ""
+echo " http://code.google.com/p/biopieces/wiki/Introduction"
+echo ""
+echo " Happy hacking!"
+echo ""
+
+exit