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 check if a directory is writable.
90 local file="$dir/bp_writable"
92 echo -n "Writable? $dir: "
94 if error=$( touch $file 2>&1 ); then
104 # Function to prompt for continuation of installation.
105 function prompt_install
108 echo "Welcome to the Biopieces installer."
110 echo " This installer is experimental, and is being evaluated to replace"
111 echo " the previous, tedious way:"
113 echo " http://code.google.com/p/biopieces/wiki/Installation"
115 echo " The installer will now do the following:"
117 echo " * Check for existing Biopieces installation."
118 echo " * Check prerequisites:"
119 echo " - Subversion client"
121 echo " - Perl modules"
124 echo " - Auxillary programs"
126 echo " * Create installation directories."
127 echo " * Download code from repository."
128 echo " * Set environment in .bashrc."
131 echo " Problems? Check out the FAQ:"
133 echo " http://code.google.com/p/biopieces/wiki/FAQ"
135 echo " Help is available at the Biopieces Google Group:"
137 echo " http://groups.google.com/group/biopieces"
139 echo " Bugs & issues:"
141 echo " http://code.google.com/p/biopieces/issues/list"
145 read -p "Continue (yes/no)? " answer
153 # Function to prompt the checking of any existing Biopieces installation.
154 function prompt_install_existing
156 echo "Checking for existing Biopieces installation:"
159 echo_yellow " WARNING: \$BP_DIR is already set to: $BP_DIR"
163 if [ $BP_DATA ]; then
164 echo_yellow " WARNING: \$BP_DATA is already set to: $BP_DATA"
169 echo_yellow " WARNING: \$BP_TMP is already set to: $BP_TMP"
174 echo_yellow " WARNING: \$BP_LOG is already set to: $BP_LOG"
180 echo " An old installation of Biopeices appears to exists."
183 echo " No installation of Biopeices found."
187 read -p "Continue (yes/no)? " answer
195 # Function to prompt the testing of prerequisites.
196 function prompt_test_prerequisites
198 echo "Testing prerequisites:"
203 test_perl_module "Inline"
204 test_perl_module "JSON::XS"
205 test_perl_module "SVG"
206 test_perl_module "Bit::Vector"
207 test_perl_module "Time::HiRes"
209 test_ruby_gem "gnuplot"
210 test_ruby_gem "narray"
211 test_ruby_gem "RubyInline"
212 test_aux_program "blastall"
213 test_aux_program "blat"
214 test_aux_program "bwa"
215 test_aux_program "bowtie"
216 test_aux_program "formatdb"
217 test_aux_program "gnuplot"
218 test_aux_program "idba"
219 test_aux_program "muscle"
220 test_aux_program "mummer"
221 test_aux_program "mysql"
222 test_aux_program "prodigal"
223 test_aux_program "Ray"
224 test_aux_program "scan_for_matches"
225 test_aux_program "usearch"
226 test_aux_program "velveth"
227 test_aux_program "velvetg"
228 test_aux_program "vmatch"
231 echo " Any WARNINGs indicate that the executable for that auxillary"
232 echo " program could not be found. While not critical, this will"
233 echo " cause some Biopieces to FAIL."
236 read -p "Continue (yes/no)? " answer
244 # Function to prompt the selection of the code directory.
245 function prompt_install_dir_code
247 read -p "Enter directory for the Biopieces code (default: $bp_code): " answer;
249 bp_code=${answer:-"$bp_code"}
251 if [ ! -d "$bp_code" ]; then
253 read -p "Create directory: $bp_code (yes/no)? " answer
255 [Yy]* ) dir_create $bp_code && break;;
261 dir_writable $bp_code
264 # Function to prompt the selection of the data directory.
265 function prompt_install_dir_data
267 read -p "Enter directory for the Biopieces data (default: $bp_data): " answer;
269 bp_data=${answer:-"$bp_data"}
271 if [ ! -d "$bp_data" ]; then
273 read -p "Create directory: $bp_data (yes/no)? " answer
275 [Yy]* ) dir_create $bp_data && break;;
281 dir_writable $bp_data
284 # Function to prompt the selection of the log directory.
285 function prompt_install_dir_log
287 read -p "Enter directory for the Biopieces log file (default: $bp_log): " answer;
289 bp_log=${answer:-"$bp_log"}
291 if [ ! -d "$bp_log" ]; then
293 read -p "Create directory: $bp_log (yes/no)? " answer
295 [Yy]* ) dir_create $bp_log && break;;
304 # Function to prompt the selection of the tmp directory.
305 function prompt_install_dir_tmp
307 read -p "Enter directory for the Biopieces temporary files (default: $bp_tmp): " answer;
309 bp_tmp=${answer:-"$bp_tmp"}
311 if [ ! -d "$bp_tmp" ]; then
313 read -p "Create directory: $bp_tmp (yes/no)? " answer
315 [Yy]* ) dir_create $bp_tmp && break;;
324 # Function to prompt the appending of a section to bashrc.
325 function prompt_append_bashrc
330 # >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<<
332 export BP_DIR=\"$bp_code\"
333 export BP_DATA=\"$bp_data\"
334 export BP_TMP=\"$bp_tmp\"
335 export BP_LOG=\"$bp_log\"
337 source \"\$BP_DIR/bp_conf/bashrc\"
339 # >>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<
344 echo "We need to append the below section to your .bashrc file."
346 echo_yellow "$section"
349 read -p "Append (yes/no/abort)? " answer
351 [Yy]* ) skip=0 && break;;
352 [Nn]* ) skip=1 && break;;
357 if [ $skip == 1 ]; then
360 if [ -f "$HOME/.bashrc" ]; then
361 echo "Existing .bashrc file located: $HOME/.bashrc"
362 echo -n "Creating backup: "
364 if ! cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"; then
369 echo " Backup is $HOME/.bashrc_biopieces"
373 echo -n "Appending $HOME/.bashrc: "
375 if ! echo "$section" >> "$HOME/.bashrc"; then
382 echo -n "Sourcing $HOME/.bashrc: "
384 if ! source "$HOME/.bashrc"; then
391 export BP_DIR="$bp_code"
392 export BP_DATA="$bp_data"
393 export BP_TMP="$bp_tmp"
394 export BP_LOG="$bp_log"
397 echo " \$BP_DIR is now set to: $BP_DIR"
398 echo " \$BP_DATA is now set to: $BP_DATA"
399 echo " \$BP_TMP is now set to: $BP_TMP"
400 echo " \$BP_LOG is now set to: $BP_LOG"
404 read -p "Continue (yes/no)? " answer
413 # Function to test if we are running bash.
416 echo -n " Testing if the running shell is bash: "
418 if [ `echo $SHELL | grep "bash"` ]; then
422 echo " Biopieces requires bash shell not - $SHELL."
427 # Function to test if subversion client is in $PATH.
432 echo -n " Testing subversion client - \"$program\": "
434 if command -v $program >/dev/null; then
438 echo " Subversion client $program was not found."
443 # Function to test if the required version of Perl is installed.
446 echo -n " Testing Perl version: "
448 if error=$( perl -e 'use 5.8.0;' 2>&1 ); then
452 echo " $error" | sed "s/, stopped.*//"
457 # Function to test if a given Perl module is installed.
458 function test_perl_module
462 echo -n " Testing required Perl module - \"$module\": "
464 if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then
466 echo " Try: perl -MCPAN -e 'install $module'"
473 # Function to test if the required version of Ruby is installed.
476 echo -n " Testing Ruby version: "
478 if ! [ `which ruby` ]; then
480 echo " Ruby version 1.9 required"
484 if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
493 # Function to test if a given Ruby gem is installed.
494 function test_ruby_gem
498 echo -n " Testing required Ruby gem - \"$gem\": "
500 if error=$( gem list --local | grep $gem ); then
502 elif [[ $gem == 'RubyInline' ]] && error=$( ruby -rinline -e '' ); then
506 echo " Try: gem install $gem"
511 # Function to test is a given auxillary program is in $PATH.
512 function test_aux_program
516 echo -n " Testing auxiliary program - \"$program\": "
518 if command -v $program >/dev/null; then
521 echo_yellow "WARNING"
525 # Function to checkout the Biopieces code from subversion.
526 function checkout_code
528 echo -n "Downloading Biopieces code from repository (please wait): "
530 if error=$( svn checkout http://biopieces.googlecode.com/svn/trunk/ $bp_code ); then
539 # Function to checkout the Biopieces wiki from subversion.
540 function checkout_wiki
542 echo -n "Downloading Biopieces wiki from repository (please wait): "
544 if error=$( svn checkout http://biopieces.googlecode.com/svn/wiki/ "$bp_code/bp_usage" ); then
553 # Function to run the Biopieces tests.
554 function prompt_test_biopieces
556 echo "Running the Biopieces test suite:"
559 "$BP_DIR/bp_test/test_all"
562 echo " Any FAIL indicates broken Biopieces. This is probably because of"
563 echo " missing prerequisites (see WARNINGs). You can verify this later by"
564 echo " inspecting the documentation for those Biopieces. Otherwise - seek help!"
567 read -p "Continue (yes/no)? " answer
576 prompt_install_existing
577 prompt_test_prerequisites
578 prompt_install_dir_code
579 prompt_install_dir_data
580 prompt_install_dir_log
581 prompt_install_dir_tmp
587 prompt_test_biopieces