3 # Install script for Biopieces.
4 # Copyright (C) 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 " Now you must either run 'source ~/.bashrc' or re-login to your system."
51 echo " * To test your Biopieces installation try 'bp_test'."
52 echo " * To list all available Biopieces try 'list_biopieces'."
53 echo " * To see the synopsis of a Biopiece try 'read_fastq'."
54 echo " * To see the full description and exampels try 'read_fastq -?'."
56 echo " Don't forget to join the Biopieces Google Group for important"
57 echo " messages, questions, discussion, and suggestions:"
59 echo " http://groups.google.com/group/biopieces"
61 echo " And of cause there is the introduction:"
63 echo " http://code.google.com/p/biopieces/wiki/Introduction"
65 echo " Happy hacking!"
71 # Function to create a directory if it doesn't exist.
76 echo -n "Creating $dir: "
78 if error=$( mkdir $dir 2>&1 ); then
87 # Function check if a directory is writable.
91 local file="$dir/bp_writable"
93 echo -n "Writable? $dir: "
95 if error=$( touch $file 2>&1 ); then
105 # Function to prompt for continuation of installation.
106 function prompt_install
109 echo "Welcome to the Biopieces installer."
111 echo " This installer is experimental, and is being evaluated to replace"
112 echo " the previous, tedious way:"
114 echo " http://code.google.com/p/biopieces/wiki/Installation"
116 echo " The installer will now do the following:"
118 echo " * Check for existing Biopieces installation."
119 echo " * Check prerequisites:"
120 echo " - Subversion client"
122 echo " - Perl modules"
125 echo " - Auxillary programs"
127 echo " * Create installation directories."
128 echo " * Download code from repository."
129 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_ruby_gem "terminal-table"
213 test_aux_program "blastall"
214 test_aux_program "blat"
215 test_aux_program "bwa"
216 test_aux_program "bowtie"
217 test_aux_program "formatdb"
218 test_aux_program "gnuplot"
219 test_aux_program "idba"
220 test_aux_program "muscle"
221 test_aux_program "mummer"
222 test_aux_program "mysql"
223 test_aux_program "prodigal"
224 test_aux_program "Ray"
225 test_aux_program "scan_for_matches"
226 test_aux_program "usearch"
227 test_aux_program "velveth"
228 test_aux_program "velvetg"
229 test_aux_program "vmatch"
232 echo " Any WARNINGs indicate that the executable for that auxillary"
233 echo " program could not be found. While not critical, this will"
234 echo " cause some Biopieces to FAIL. You can install these afterwards."
237 read -p "Continue (yes/no)? " answer
245 # Function to prompt the selection of the code directory.
246 function prompt_install_dir_code
248 read -p "Enter directory for the Biopieces code (default: $bp_code): " answer;
250 bp_code=${answer:-"$bp_code"}
252 if [ ! -d "$bp_code" ]; then
254 read -p "Create directory: $bp_code (yes/no)? " answer
256 [Yy]* ) dir_create $bp_code && break;;
262 dir_writable $bp_code
265 # Function to prompt the selection of the data directory.
266 function prompt_install_dir_data
268 read -p "Enter directory for the Biopieces data (default: $bp_data): " answer;
270 bp_data=${answer:-"$bp_data"}
272 if [ ! -d "$bp_data" ]; then
274 read -p "Create directory: $bp_data (yes/no)? " answer
276 [Yy]* ) dir_create $bp_data && break;;
282 dir_writable $bp_data
285 # Function to prompt the selection of the log directory.
286 function prompt_install_dir_log
288 read -p "Enter directory for the Biopieces log file (default: $bp_log): " answer;
290 bp_log=${answer:-"$bp_log"}
292 if [ ! -d "$bp_log" ]; then
294 read -p "Create directory: $bp_log (yes/no)? " answer
296 [Yy]* ) dir_create $bp_log && break;;
305 # Function to prompt the selection of the tmp directory.
306 function prompt_install_dir_tmp
308 read -p "Enter directory for the Biopieces temporary files (default: $bp_tmp): " answer;
310 bp_tmp=${answer:-"$bp_tmp"}
312 if [ ! -d "$bp_tmp" ]; then
314 read -p "Create directory: $bp_tmp (yes/no)? " answer
316 [Yy]* ) dir_create $bp_tmp && break;;
325 # Function to prompt the appending of a section to bashrc.
326 function prompt_append_bashrc
331 # >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<<
333 export BP_DIR=\"$bp_code\"
334 export BP_DATA=\"$bp_data\"
335 export BP_TMP=\"$bp_tmp\"
336 export BP_LOG=\"$bp_log\"
338 source \"\$BP_DIR/bp_conf/bashrc\"
340 # >>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<
345 echo "We need to append the below section to your .bashrc file."
347 echo_yellow "$section"
350 read -p "Append (yes/no/abort)? " answer
352 [Yy]* ) skip=0 && break;;
353 [Nn]* ) skip=1 && break;;
358 if [ $skip == 1 ]; then
361 if [ -f "$HOME/.bashrc" ]; then
362 echo "Existing .bashrc file located: $HOME/.bashrc"
363 echo -n "Creating backup: "
365 if ! cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"; then
370 echo " Backup is $HOME/.bashrc_biopieces"
374 echo -n "Appending $HOME/.bashrc: "
376 if ! echo "$section" >> "$HOME/.bashrc"; then
383 echo -n "Testing $HOME/.bashrc: "
385 if ! source "$HOME/.bashrc"; then
392 export BP_DIR="$bp_code"
393 export BP_DATA="$bp_data"
394 export BP_TMP="$bp_tmp"
395 export BP_LOG="$bp_log"
398 echo " \$BP_DIR is now set to: $BP_DIR"
399 echo " \$BP_DATA is now set to: $BP_DATA"
400 echo " \$BP_TMP is now set to: $BP_TMP"
401 echo " \$BP_LOG is now set to: $BP_LOG"
405 read -p "Continue (yes/no)? " answer
414 # Function to test if we are running bash.
417 echo -n " Testing if the running shell is bash: "
419 if [ `echo $SHELL | grep "bash"` ]; then
423 echo " Biopieces requires bash shell not - $SHELL."
428 # Function to test if subversion client is in $PATH.
433 echo -n " Testing subversion client - \"$program\": "
435 if command -v $program >/dev/null; then
439 echo " Subversion client $program was not found."
444 # Function to test if the required version of Perl is installed.
447 echo -n " Testing Perl version: "
449 if error=$( perl -e 'use 5.8.0;' 2>&1 ); then
453 echo " $error" | sed "s/, stopped.*//"
458 # Function to test if a given Perl module is installed.
459 function test_perl_module
463 echo -n " Testing required Perl module - \"$module\": "
465 if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then
467 echo " Try: perl -MCPAN -e 'install $module'"
474 # Function to test if the required version of Ruby is installed.
477 echo -n " Testing Ruby version: "
479 if ! [ `which ruby` ]; then
481 echo " Ruby version 1.9 required"
485 if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
494 # Function to test if a given Ruby gem is installed.
495 function test_ruby_gem
499 echo -n " Testing required Ruby gem - \"$gem\": "
501 if error=$( gem list --local | grep $gem ); then
503 elif [[ $gem == 'RubyInline' ]] && error=$( ruby -rinline -e '' ); then
507 echo " Try: gem install $gem"
512 # Function to test is a given auxillary program is in $PATH.
513 function test_aux_program
517 echo -n " Testing auxiliary program - \"$program\": "
519 if command -v $program >/dev/null; then
522 echo_yellow "WARNING"
526 # Function to checkout the Biopieces code from subversion.
527 function checkout_code
529 echo -n "Downloading Biopieces code from repository (please wait): "
531 if error=$( svn checkout http://biopieces.googlecode.com/svn/trunk/ $bp_code ); then
540 # Function to checkout the Biopieces wiki from subversion.
541 function checkout_wiki
543 echo -n "Downloading Biopieces wiki from repository (please wait): "
545 if error=$( svn checkout http://biopieces.googlecode.com/svn/wiki/ "$bp_code/bp_usage" ); then
555 prompt_install_existing
556 prompt_test_prerequisites
557 prompt_install_dir_code
558 prompt_install_dir_data
559 prompt_install_dir_log
560 prompt_install_dir_tmp