3 # Install script for Biopieces.
4 # October 2011, Martin A. Hansen
6 bp_code="$HOME/biopieces"
7 bp_data="$HOME/BP_DATA"
11 # Function that renders a given message in ASCII green.
16 echo -e "\033[32;38m$msg\033[0m"
19 # Function that renders a given message in ASCII yellow.
24 echo -e "\033[33;38m$msg\033[0m"
27 # Function that renders a given message in ASCII red.
32 echo -e "\033[31;38m$msg\033[0m"
35 # Function to output an abort message and exit
43 # Function to output an success message and exit
47 echo_green "Congratulations - you have now installed Biopieces."
49 echo " To list all available Biopieces try 'list_biopieces'"
51 echo " To see the synopsis of a Biopiece try 'read_fastq'"
53 echo " To see the full description and exampels try 'read_fastq -?'"
55 echo " Don't forget to join the Biopieces Google Group for important"
56 echo " messages, questions, discussion, and suggestions:"
58 echo " http://groups.google.com/group/biopieces"
60 echo " And of cause there is the introduction:"
62 echo " http://code.google.com/p/biopieces/wiki/Introduction"
64 echo " Happy hacking!"
70 # Function to create a directory if it doesn't exist.
75 echo -n "Creating $dir: "
77 if error=$( mkdir $dir 2>&1 ); then
86 # Function to prompt for continuation of installation.
87 function prompt_install
90 echo "Welcome to the Biopieces installer."
92 echo " This installer is experimental, and is being evaluated to replace"
93 echo " the previous, tedious way:"
95 echo " http://code.google.com/p/biopieces/wiki/Installation"
97 echo " If you experience problems, please report to the Google Group (see below)."
99 echo " The installer will now do the following:"
101 echo " - Check for existing Biopieces installation."
102 echo " - Check prerequisites:"
103 echo " * Subversion client"
105 echo " * Perl modules"
108 echo " * Auxillary programs"
110 echo " - Create installation directories."
111 echo " - Download code from repository."
112 echo " - Set environment in .bashrc."
115 echo " Problems? Check out the FAQ:"
117 echo " http://code.google.com/p/biopieces/wiki/FAQ"
119 echo " Help is available at the Biopieces Google Group:"
121 echo " http://groups.google.com/group/biopieces"
123 echo " Bugs & issues:"
125 echo " http://code.google.com/p/biopieces/issues/list"
129 read -p "Continue (yes/no)? " answer
137 # Function to prompt the checking of any existing Biopieces installation.
138 function prompt_install_existing
140 echo "Checking for existing Biopieces installation:"
143 echo_yellow " WARNING: \$BP_DIR is already set to: $BP_DIR"
147 if [ $BP_DATA ]; then
148 echo_yellow " WARNING: \$BP_DATA is already set to: $BP_DATA"
153 echo_yellow " WARNING: \$BP_TMP is already set to: $BP_TMP"
158 echo_yellow " WARNING: \$BP_LOG is already set to: $BP_LOG"
164 echo " It appears that an old installation of Biopeices exists."
168 read -p "Continue (yes/no)? " answer
176 # Function to prompt the testing of prerequisites.
177 function prompt_test_prerequisites
179 echo "Testing prerequisites:"
184 test_perl_module "Inline"
185 test_perl_module "JSON::XS"
186 test_perl_module "SVG"
187 test_perl_module "Bit::Vector"
188 test_perl_module "Time::HiRes"
190 test_ruby_gem "gnuplot"
191 test_ruby_gem "narray"
192 test_aux_program "blastall"
193 test_aux_program "blat"
194 test_aux_program "bwa"
195 test_aux_program "bowtie"
196 test_aux_program "formatdb"
197 test_aux_program "gnuplot"
198 test_aux_program "idba"
199 test_aux_program "muscle"
200 test_aux_program "mummer"
201 test_aux_program "mysql"
202 test_aux_program "prodigal"
203 test_aux_program "Ray"
204 test_aux_program "scan_for_matches"
205 test_aux_program "uclust"
206 test_aux_program "velveth"
207 test_aux_program "velvetg"
208 test_aux_program "vmatch"
211 echo " Any WARNINGs indicate that the executable for that auxillary"
212 echo " program could not be found. While not critical, this will"
213 echo " cause some Biopieces to FAIL."
216 read -p "Continue (yes/no)? " answer
224 # Function to prompt the selection of the code directory.
225 function prompt_install_dir_code
227 read -p "Enter directory for the Biopieces code (default: $bp_code): " answer;
229 bp_code=${answer:-"$bp_code"}
231 if [ ! -d "$bp_code" ]; then
233 read -p "Create directory: $bp_code (yes/no)? " answer
235 [Yy]* ) dir_create $bp_code && break;;
242 # Function to prompt the selection of the data directory.
243 function prompt_install_dir_data
245 read -p "Enter directory for the Biopieces data (default: $bp_data): " answer;
247 bp_data=${answer:-"$bp_data"}
249 if [ ! -d "$bp_data" ]; then
251 read -p "Create directory: $bp_data (yes/no)? " answer
253 [Yy]* ) dir_create $bp_data && break;;
260 # Function to prompt the selection of the log directory.
261 function prompt_install_dir_log
263 read -p "Enter directory for the Biopieces log file (default: $bp_log): " answer;
265 bp_log=${answer:-"$bp_log"}
267 if [ ! -d "$bp_log" ]; then
269 read -p "Create directory: $bp_log (yes/no)? " answer
271 [Yy]* ) dir_create $bp_log && break;;
278 # Function to prompt the selection of the tmp directory.
279 function prompt_install_dir_tmp
281 read -p "Enter directory for the Biopieces temporary files (default: $bp_tmp): " answer;
283 bp_tmp=${answer:-"$bp_tmp"}
285 if [ ! -d "$bp_tmp" ]; then
287 read -p "Create directory: $bp_tmp (yes/no)? " answer
289 [Yy]* ) dir_create $bp_tmp && break;;
296 # Function to prompt the appending of a section to bashrc.
297 function prompt_append_bashrc
302 # >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<<
304 export BP_DIR=\"$bp_code\"
305 export BP_DATA=\"$bp_data\"
306 export BP_TMP=\"$bp_tmp\"
307 export BP_LOG=\"$bp_log\"
309 source \"\$BP_DIR/bp_conf/bashrc\"
311 # >>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<
316 echo "We need to append the below section to your .bashrc file."
318 echo_yellow "$section"
321 read -p "Append (yes/no/abort)? " answer
323 [Yy]* ) skip=0 && break;;
324 [Nn]* ) skip=1 && break;;
329 if [ $skip == 1 ]; then
332 if [ -f "$HOME/.bashrc" ]; then
333 echo "Existing .bashrc file located: $HOME/.bashrc"
334 echo -n "Creating backup: "
336 if ! cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"; then
341 echo " Backup is $HOME/.bashrc_biopieces"
345 echo -n "Appending $HOME/.bashrc: "
347 if ! echo "$section" >> "$HOME/.bashrc"; then
354 echo -n "Sourcing $HOME/.bashrc: "
356 if ! source "$HOME/.bashrc"; then
364 echo " \$BP_DIR is now set to: $BP_DIR"
365 echo " \$BP_DATA is now set to: $BP_DATA"
366 echo " \$BP_TMP is now set to: $BP_TMP"
367 echo " \$BP_LOG is now set to: $BP_LOG"
372 # Function to test if we are running bash.
375 echo -n " Testing if the running shell is bash: "
377 if [ `echo $SHELL | grep "bash"` ]; then
381 echo " Biopieces requires bash shell not - $SHELL."
386 # Function to test if subversion client is in $PATH.
391 echo -n " Testing subversion client - \"$program\": "
393 if command -v $program >/dev/null; then
397 echo " Subversion client $program was not found."
402 # Function to test if the required version of Perl is installed.
405 echo -n " Testing Perl version: "
407 if error=$( perl -e 'use 5.8.0;' 2>&1 ); then
411 echo $error | sed "s/, stopped.*//"
416 # Function to test if a given Perl module is installed.
417 function test_perl_module
421 echo -n " Testing required Perl module - \"$module\": "
423 if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then
425 echo " Try: perl -MCPAN -e 'install $module'"
432 # Function to test if the required version of Ruby is installed.
435 echo -n " Testing Ruby version: "
437 if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
441 echo $error | sed "s/.*: //"
446 # Function to test if a given Ruby gem is installed.
447 function test_ruby_gem
451 echo -n " Testing required Ruby gem - \"$gem\": "
453 if error=$( gem list --local | grep $gem ); then
457 echo " Try: gem install $gem"
462 # Function to test is a given auxillary program is in $PATH.
463 function test_aux_program
467 echo -n " Testing auxiliary program - \"$program\": "
469 if command -v $program >/dev/null; then
472 echo_yellow "WARNING"
476 # Function to checkout the Biopieces code from subversion.
477 function checkout_code
479 echo -n "Downloading Biopieces code from repository: "
481 if error=$( svn checkout http://biopieces.googlecode.com/svn/trunk/ $bp_code ); then
490 # Function to checkout the Biopieces wiki from subversion.
491 function checkout_wiki
493 echo -n "Downloading Biopieces wiki from repository: "
495 if error=$( svn checkout http://biopieces.googlecode.com/svn/wiki/ "$bp_code/bp_usage" ); then
504 # Function to run the Biopieces tests.
505 function prompt_test_biopieces
507 echo "Running the Biopieces test suite:"
510 "$BP_DIR/bp_test/test_all"
513 echo " Any FAIL indicates broken Biopieces. This is probably because of"
514 echo " missing prerequisites (see WARNINGs). You can verify this later by"
515 echo " inspecting the documentation for those Biopieces. Otherwise - seek help!"
518 read -p "Continue (yes/no)? " answer
527 prompt_install_existing
528 prompt_test_prerequisites
529 prompt_install_dir_code
530 prompt_install_dir_data
531 prompt_install_dir_log
532 prompt_install_dir_tmp
538 prompt_test_biopieces