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_aux_program "blastall"
212 test_aux_program "blat"
213 test_aux_program "bwa"
214 test_aux_program "bowtie"
215 test_aux_program "formatdb"
216 test_aux_program "gnuplot"
217 test_aux_program "idba"
218 test_aux_program "muscle"
219 test_aux_program "mummer"
220 test_aux_program "mysql"
221 test_aux_program "prodigal"
222 test_aux_program "Ray"
223 test_aux_program "scan_for_matches"
224 test_aux_program "uclust"
225 test_aux_program "velveth"
226 test_aux_program "velvetg"
227 test_aux_program "vmatch"
230 echo " Any WARNINGs indicate that the executable for that auxillary"
231 echo " program could not be found. While not critical, this will"
232 echo " cause some Biopieces to FAIL."
235 read -p "Continue (yes/no)? " answer
243 # Function to prompt the selection of the code directory.
244 function prompt_install_dir_code
246 read -p "Enter directory for the Biopieces code (default: $bp_code): " answer;
248 bp_code=${answer:-"$bp_code"}
250 if [ ! -d "$bp_code" ]; then
252 read -p "Create directory: $bp_code (yes/no)? " answer
254 [Yy]* ) dir_create $bp_code && break;;
260 dir_writable $bp_code
263 # Function to prompt the selection of the data directory.
264 function prompt_install_dir_data
266 read -p "Enter directory for the Biopieces data (default: $bp_data): " answer;
268 bp_data=${answer:-"$bp_data"}
270 if [ ! -d "$bp_data" ]; then
272 read -p "Create directory: $bp_data (yes/no)? " answer
274 [Yy]* ) dir_create $bp_data && break;;
280 dir_writable $bp_data
283 # Function to prompt the selection of the log directory.
284 function prompt_install_dir_log
286 read -p "Enter directory for the Biopieces log file (default: $bp_log): " answer;
288 bp_log=${answer:-"$bp_log"}
290 if [ ! -d "$bp_log" ]; then
292 read -p "Create directory: $bp_log (yes/no)? " answer
294 [Yy]* ) dir_create $bp_log && break;;
303 # Function to prompt the selection of the tmp directory.
304 function prompt_install_dir_tmp
306 read -p "Enter directory for the Biopieces temporary files (default: $bp_tmp): " answer;
308 bp_tmp=${answer:-"$bp_tmp"}
310 if [ ! -d "$bp_tmp" ]; then
312 read -p "Create directory: $bp_tmp (yes/no)? " answer
314 [Yy]* ) dir_create $bp_tmp && break;;
323 # Function to prompt the appending of a section to bashrc.
324 function prompt_append_bashrc
329 # >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<<
331 export BP_DIR=\"$bp_code\"
332 export BP_DATA=\"$bp_data\"
333 export BP_TMP=\"$bp_tmp\"
334 export BP_LOG=\"$bp_log\"
336 source \"\$BP_DIR/bp_conf/bashrc\"
338 # >>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<
343 echo "We need to append the below section to your .bashrc file."
345 echo_yellow "$section"
348 read -p "Append (yes/no/abort)? " answer
350 [Yy]* ) skip=0 && break;;
351 [Nn]* ) skip=1 && break;;
356 if [ $skip == 1 ]; then
359 if [ -f "$HOME/.bashrc" ]; then
360 echo "Existing .bashrc file located: $HOME/.bashrc"
361 echo -n "Creating backup: "
363 if ! cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"; then
368 echo " Backup is $HOME/.bashrc_biopieces"
372 echo -n "Appending $HOME/.bashrc: "
374 if ! echo "$section" >> "$HOME/.bashrc"; then
381 echo -n "Sourcing $HOME/.bashrc: "
383 if ! source "$HOME/.bashrc"; then
391 echo " \$BP_DIR is now set to: $BP_DIR"
392 echo " \$BP_DATA is now set to: $BP_DATA"
393 echo " \$BP_TMP is now set to: $BP_TMP"
394 echo " \$BP_LOG is now set to: $BP_LOG"
399 # Function to test if we are running bash.
402 echo -n " Testing if the running shell is bash: "
404 if [ `echo $SHELL | grep "bash"` ]; then
408 echo " Biopieces requires bash shell not - $SHELL."
413 # Function to test if subversion client is in $PATH.
418 echo -n " Testing subversion client - \"$program\": "
420 if command -v $program >/dev/null; then
424 echo " Subversion client $program was not found."
429 # Function to test if the required version of Perl is installed.
432 echo -n " Testing Perl version: "
434 if error=$( perl -e 'use 5.8.0;' 2>&1 ); then
438 echo " $error" | sed "s/, stopped.*//"
443 # Function to test if a given Perl module is installed.
444 function test_perl_module
448 echo -n " Testing required Perl module - \"$module\": "
450 if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then
452 echo " Try: perl -MCPAN -e 'install $module'"
459 # Function to test if the required version of Ruby is installed.
462 echo -n " Testing Ruby version: "
464 if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
472 # Function to test if a given Ruby gem is installed.
473 function test_ruby_gem
477 echo -n " Testing required Ruby gem - \"$gem\": "
479 if error=$( gem list --local | grep $gem ); then
483 echo " Try: gem install $gem"
488 # Function to test is a given auxillary program is in $PATH.
489 function test_aux_program
493 echo -n " Testing auxiliary program - \"$program\": "
495 if command -v $program >/dev/null; then
498 echo_yellow "WARNING"
502 # Function to checkout the Biopieces code from subversion.
503 function checkout_code
505 echo -n "Downloading Biopieces code from repository (please wait): "
507 if error=$( svn checkout http://biopieces.googlecode.com/svn/trunk/ $bp_code ); then
516 # Function to checkout the Biopieces wiki from subversion.
517 function checkout_wiki
519 echo -n "Downloading Biopieces wiki from repository (please wait): "
521 if error=$( svn checkout http://biopieces.googlecode.com/svn/wiki/ "$bp_code/bp_usage" ); then
530 # Function to run the Biopieces tests.
531 function prompt_test_biopieces
533 echo "Running the Biopieces test suite:"
536 "$BP_DIR/bp_test/test_all"
539 echo " Any FAIL indicates broken Biopieces. This is probably because of"
540 echo " missing prerequisites (see WARNINGs). You can verify this later by"
541 echo " inspecting the documentation for those Biopieces. Otherwise - seek help!"
544 read -p "Continue (yes/no)? " answer
553 prompt_install_existing
554 prompt_test_prerequisites
555 prompt_install_dir_code
556 prompt_install_dir_data
557 prompt_install_dir_log
558 prompt_install_dir_tmp
564 prompt_test_biopieces