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"
125 read -p "Continue (yes/no)? " answer
133 # Function to prompt the checking of any existing Biopieces installation.
134 function prompt_install_existing
136 echo "Checking for existing Biopieces installation:"
139 echo_yellow " WARNING: \$BP_DIR is already set to: $BP_DIR"
143 if [ $BP_DATA ]; then
144 echo_yellow " WARNING: \$BP_DATA is already set to: $BP_DATA"
149 echo_yellow " WARNING: \$BP_TMP is already set to: $BP_TMP"
154 echo_yellow " WARNING: \$BP_LOG is already set to: $BP_LOG"
160 echo " It appears that an old installation of Biopeices exists."
164 read -p "Continue (yes/no)? " answer
172 # Function to prompt the testing of prerequisites.
173 function prompt_test_prerequisites
175 echo "Testing prerequisites:"
179 test_perl_module "Inline"
180 test_perl_module "JSON::XS"
181 test_perl_module "SVG"
182 test_perl_module "Bit::Vector"
183 test_perl_module "Time::HiRes"
185 test_ruby_gem "gnuplot"
186 test_ruby_gem "narray"
187 test_aux_program "blastall"
188 test_aux_program "blat"
189 test_aux_program "bwa"
190 test_aux_program "bowtie"
191 test_aux_program "formatdb"
192 test_aux_program "gnuplot"
193 test_aux_program "idba"
194 test_aux_program "muscle"
195 test_aux_program "mummer"
196 test_aux_program "mysql"
197 test_aux_program "prodigal"
198 test_aux_program "Ray"
199 test_aux_program "scan_for_matches"
200 test_aux_program "uclust"
201 test_aux_program "velveth"
202 test_aux_program "velvetg"
203 test_aux_program "vmatch"
206 echo " Any WARNINGs indicate that the executable for that auxillary"
207 echo " program could not be found. While not critical, this will"
208 echo " cause some Biopieces to fail."
211 read -p "Continue (yes/no)? " answer
219 # Function to prompt the selection of the code directory.
220 function prompt_install_dir_code
222 read -p "Enter directory to install Biopieces code (default: $bp_code): " answer;
224 bp_code=${answer:-"$bp_code"}
226 if [ ! -d "$bp_code" ]; then
228 read -p "Create directory: $bp_code (yes/no)? " answer
230 [Yy]* ) dir_create $bp_code && break;;
237 # Function to prompt the selection of the data directory.
238 function prompt_install_dir_data
240 read -p "Enter directory to install Biopieces data (default: $bp_data): " answer;
242 bp_data=${answer:-"$bp_data"}
244 if [ ! -d "$bp_data" ]; then
246 read -p "Create directory: $bp_data (yes/no)? " answer
248 [Yy]* ) dir_create $bp_data && break;;
255 # Function to prompt the selection of the log directory.
256 function prompt_install_dir_log
258 read -p "Enter directory to install Biopieces log (default: $bp_log): " answer;
260 bp_log=${answer:-"$bp_log"}
262 if [ ! -d "$bp_log" ]; then
264 read -p "Create directory: $bp_log (yes/no)? " answer
266 [Yy]* ) dir_create $bp_log && break;;
273 # Function to prompt the selection of the tmp directory.
274 function prompt_install_dir_tmp
276 read -p "Enter directory to install Biopieces tmp (default: $bp_tmp): " answer;
278 bp_tmp=${answer:-"$bp_tmp"}
280 if [ ! -d "$bp_tmp" ]; then
282 read -p "Create directory: $bp_tmp (yes/no)? " answer
284 [Yy]* ) dir_create $bp_tmp && break;;
291 # Function to prompt the appending of a section to bashrc.
292 function prompt_append_bashrc
297 # >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<<
299 export BP_DIR=\"$bp_code\"
300 export BP_DATA=\"$bp_data\"
301 export BP_TMP=\"$bp_tmp\"
302 export BP_LOG=\"$bp_log\"
304 source \"\$BP_DIR/bp_conf/bashrc\"
306 # >>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<
311 echo "We need to append the below section to your .bashrc file."
313 echo_yellow "$section"
316 read -p "Append (yes/no/abort)? " answer
318 [Yy]* ) skip=0 && break;;
319 [Nn]* ) skip=1 && break;;
324 if [ $skip == 1 ]; then
327 echo -n "Appending $HOME/.bashrc: "
329 cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"
331 echo "$section" >> "$HOME/.bashrc"
333 source "$HOME/.bashrc"
337 echo " Backup is $HOME/.bashrc_biopieces"
341 # Function to test if subversion client is in $PATH.
346 echo -n " Testing subversion client - \"$program\": "
348 if command -v $program >/dev/null; then
352 echo " Subversion client $program was not found."
357 # Function to test if the required version of Perl is installed.
360 echo -n " Testing Perl version: "
362 if error=$( perl -e 'use 5.8.0;' 2>&1 ); then
366 echo $error | sed "s/, stopped.*//"
371 # Function to test if a given Perl module is installed.
372 function test_perl_module
376 echo -n " Testing required Perl module - \"$module\": "
378 if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then
380 echo " Try: perl -MCPAN -e 'install $module'"
387 # Function to test if the required version of Ruby is installed.
390 echo -n " Testing Ruby version: "
392 if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
396 echo $error | sed "s/.*: //"
401 # Function to test if a given Ruby gem is installed.
402 function test_ruby_gem
406 echo -n " Testing required Ruby gem - \"$gem\": "
408 if error=$( gem list --local | grep $gem ); then
412 echo " Try: gem install $gem"
417 # Function to test is a given auxillary program is in $PATH.
418 function test_aux_program
422 echo -n " Testing auxiliary program - \"$program\": "
424 if command -v $program >/dev/null; then
427 echo_yellow "WARNING"
431 # Function to checkout the Biopieces code from subversion.
432 function checkout_code
434 echo -n "Downloading Biopieces code from repository: "
436 if error=$( svn checkout http://biopieces.googlecode.com/svn/trunk/ $bp_code ); then
445 # Function to checkout the Biopieces wiki from subversion.
446 function checkout_wiki
448 echo -n "Downloading Biopieces wiki from repository: "
450 if error=$( svn checkout http://biopieces.googlecode.com/svn/wiki/ "$bp_code/bp_usage" ); then
459 # Function to run the Biopieces tests.
460 function prompt_test_biopieces
462 echo "Running the Biopieces test suite:"
465 "$BP_DIR/bp_test/test_all"
468 echo " Any FAIL indicates broken Biopieces - seek help!"
471 read -p "Continue (yes/no)? " answer
480 prompt_install_existing
481 prompt_test_prerequisites
482 prompt_install_dir_code
483 prompt_install_dir_data
484 prompt_install_dir_log
485 prompt_install_dir_tmp
491 prompt_test_biopieces