}
# Function to output an abort message and exit
-function abort
+function exit_abort
{
echo_red "abort"
exit
}
-# Function to create a directory is it doesn't exist.
+# Function to output an success message and exit
+function exit_success
+{
+ 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
+}
+
+# Function to create a directory if it doesn't exist.
function dir_create
{
local dir=$1
else
echo_red "FAIL"
echo $error
- abort
+ exit_abort
fi
}
echo ""
echo " The installer will now do the following:"
echo ""
+ echo " - Check for existing Biopieces installation."
echo " - Check prerequisites:"
echo " * Subversion client"
echo " * Perl"
echo " * Ruby gems"
echo " * Auxillary programs"
echo ""
- echo " - Create installation directories"
- echo " - Download code from repository"
- echo " - Set environment in .bashrc"
+ echo " - Create installation directories."
+ echo " - Download code from repository."
+ echo " - Set environment in .bashrc."
echo " - Run tests"
echo ""
echo " Problems? Check out the FAQ:"
read -p "Continue (yes/no)? " answer
case $answer in
[Yy]* ) break;;
- [Nn]* ) abort;;
+ [Nn]* ) exit_abort;;
+ esac
+ done
+}
+
+# Function to prompt the checking of any existing Biopieces installation.
+function prompt_install_existing
+{
+ echo "Checking for existing Biopieces installation:"
+
+ if [ $BP_DIR ]; then
+ echo_yellow " WARNING: \$BP_DIR is already set to: $BP_DIR"
+ found=1
+ fi
+
+ if [ $BP_DATA ]; then
+ echo_yellow " WARNING: \$BP_DATA is already set to: $BP_DATA"
+ found=1
+ fi
+
+ if [ $BP_TMP ]; then
+ echo_yellow " WARNING: \$BP_TMP is already set to: $BP_TMP"
+ found=1
+ fi
+
+ if [ $BP_LOG ]; then
+ echo_yellow " WARNING: \$BP_LOG is already set to: $BP_LOG"
+ found=1
+ fi
+
+ if [ $found ]; then
+ echo ""
+ echo " It appears that an old installation of Biopeices exists."
+ fi
+
+ while true; do
+ read -p "Continue (yes/no)? " answer
+ case $answer in
+ [Yy]* ) break;;
+ [Nn]* ) exit_abort;;
+ esac
+ done
+}
+
+# Function to prompt the testing of prerequisites.
+function prompt_test_prerequisites
+{
+ echo "Testing prerequisites:"
+
+ 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 ""
+ echo " Any WARNINGs indicate that the executable for that auxillary"
+ echo " program could not be found. While not critical, this will"
+ echo " cause some Biopieces to fail."
+
+ while true; do
+ read -p "Continue (yes/no)? " answer
+ case $answer in
+ [Yy]* ) break;;
+ [Nn]* ) exit_abort;;
esac
done
}
read -p "Create directory: $bp_code (yes/no)? " answer
case $answer in
[Yy]* ) dir_create $bp_code && break;;
- [Nn]* ) abort;;
+ [Nn]* ) exit_abort;;
esac
done
fi
read -p "Create directory: $bp_data (yes/no)? " answer
case $answer in
[Yy]* ) dir_create $bp_data && break;;
- [Nn]* ) abort;;
+ [Nn]* ) exit_abort;;
esac
done
fi
read -p "Create directory: $bp_log (yes/no)? " answer
case $answer in
[Yy]* ) dir_create $bp_log && break;;
- [Nn]* ) abort;;
+ [Nn]* ) exit_abort;;
esac
done
fi
read -p "Create directory: $bp_tmp (yes/no)? " answer
case $answer in
[Yy]* ) dir_create $bp_tmp && break;;
- [Nn]* ) abort;;
+ [Nn]* ) exit_abort;;
esac
done
fi
# Function to prompt the appending of a section to bashrc.
function prompt_append_bashrc
{
- section="
+ local skip=0
+ local section="
# >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<<
"
+ echo ""
+ echo "We need to append the below section to your .bashrc file."
+
echo_yellow "$section"
- echo "We need to append the above section to your .bashrc file."
while true; do
- read -p "Continue (yes/no)? " answer
+ read -p "Append (yes/no/abort)? " answer
case $answer in
- [Yy]* ) break;;
- [Nn]* ) abort;;
+ [Yy]* ) skip=0 && break;;
+ [Nn]* ) skip=1 && break;;
+ [Aa]* ) exit_abort;;
esac
done
- echo -n "Appending $HOME/.bashrc: "
+ if [ $skip == 1 ]; then
+ echo "Skipping"
+ else
+ echo -n "Appending $HOME/.bashrc: "
- cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"
+ cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"
- echo "$section" >> "$HOME/.bashrc"
+ echo "$section" >> "$HOME/.bashrc"
- source "$HOME/.bashrc"
+ source "$HOME/.bashrc"
- echo_green "OK"
+ echo_green "OK"
+ echo ""
+ echo " Backup is $HOME/.bashrc_biopieces"
+ fi
}
-
# Function to test if subversion client is in $PATH.
function test_svn
{
local program="svn"
- echo -n "Testing subversion client - \"$program\": "
+ 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
+ echo " Subversion client $program was not found."
+ exit_abort
fi
}
# Function to test if the required version of Perl is installed.
function test_perl
{
- echo -n "Testing Perl version: "
+ 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
+ exit_abort
fi
}
{
local module=$1
- echo -n "Testing required Perl module - \"$module\": "
+ 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
+ exit_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: "
+ 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
+ exit_abort
fi
}
{
local gem=$1
- echo -n "Testing required Ruby gem - \"$gem\": "
+ 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
+ echo " Try: gem install $gem"
+ exit_abort
fi
}
{
local program=$1
- echo -n "Testing auxiliary program - \"$program\": "
+ echo -n " Testing auxiliary program - \"$program\": "
if command -v $program >/dev/null; then
echo_green "OK"
else
echo_red "FAIL"
echo $error
- abort
+ exit_abort
fi
}
else
echo_red "FAIL"
echo $error
- abort
+ exit_abort
fi
}
-# Function to run the Biopieces test suite.
-function run_tests
+# Function to run the Biopieces tests.
+function prompt_test_biopieces
{
+ echo "Running the Biopieces test suite:"
+ echo ""
+
+ "$BP_DIR/bp_test/test_all"
+
+ echo ""
+ echo " Any FAIL indicates broken Biopieces - seek help!"
+
while true; do
- read -p "Run the Biopieces test suite (yes/no)? " answer
+ read -p "Continue (yes/no)? " answer
case $answer in
- [Yy]* ) "$BP_DIR/bp_test/test_all" && break;;
- [Nn]* ) break;;
+ [Yy]* ) break;;
+ [Nn]* ) exit_abort;;
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_existing
+prompt_test_prerequisites
prompt_install_dir_code
prompt_install_dir_data
prompt_install_dir_log
checkout_wiki
prompt_append_bashrc
+prompt_test_biopieces
-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
+exit_success