]> git.donarmstrong.com Git - biopieces.git/blob - bp_scripts/biopieces_installer.sh
f9f74f71a6a9928aaa3b6563fb332814b4d7d2bd
[biopieces.git] / bp_scripts / biopieces_installer.sh
1 #!/bin/bash
2
3 # Install script for Biopieces.
4 # October 2011, Martin A. Hansen
5
6 bp_code="$HOME/biopieces"
7 bp_data="$HOME/BP_DATA"
8  bp_log="/var/log"
9  bp_tmp="/tmp"
10
11 # Function that renders a given message in ASCII green.
12 function echo_green
13 {
14     local msg=$1
15
16     echo -e "\033[32;38m$msg\033[0m"
17 }
18
19 # Function that renders a given message in ASCII yellow.
20 function echo_yellow
21 {
22     local msg=$1
23
24     echo -e "\033[33;38m$msg\033[0m"
25 }
26
27 # Function that renders a given message in ASCII red.
28 function echo_red
29 {
30     local msg=$1
31
32     echo -e "\033[31;38m$msg\033[0m"
33 }
34
35 # Function to output an abort message and exit
36 function abort
37 {
38     echo_red "abort"
39
40     exit
41 }
42
43 # Function to create a directory if it doesn't exist.
44 function dir_create
45 {
46     local dir=$1
47
48     echo -n "Creating $dir: "
49
50     if error=$( mkdir $dir 2>&1 ); then
51         echo_green "OK"
52     else
53         echo_red "FAIL"
54         echo $error
55         abort
56     fi
57 }
58
59 # Function to prompt for continuation of installation.
60 function prompt_install
61 {
62     echo ""
63     echo "Welcome to the Biopieces installer."
64     echo ""
65     echo "   This installer is experimental, and is being evaluated to replace"
66     echo "   the previous, tedious way:"
67     echo ""
68     echo "      http://code.google.com/p/biopieces/wiki/Installation"
69     echo ""
70     echo "   If you experience problems, please report to the Google Group (see below)"
71     echo ""
72     echo "   The installer will now do the following:"
73     echo ""
74     echo "   -  Check prerequisites:"
75     echo "      *  Subversion client"
76     echo "      *  Perl"
77     echo "      *  Perl modules"
78     echo "      *  Ruby"
79     echo "      *  Ruby gems"
80     echo "      *  Auxillary programs"
81     echo ""
82     echo "   -  Create installation directories"
83     echo "   -  Download code from repository"
84     echo "   -  Set environment in .bashrc"
85     echo "   -  Run tests"
86     echo ""
87     echo "   Problems? Check out the FAQ:"
88     echo ""
89     echo "      http://code.google.com/p/biopieces/wiki/FAQ"
90     echo ""
91     echo "   Help is available at the Biopieces Google Group:"
92     echo ""
93     echo "      http://groups.google.com/group/biopieces"
94     echo ""
95
96     while true; do
97         read -p "Continue (yes/no)? " answer
98         case $answer in
99             [Yy]* ) break;;
100             [Nn]* ) abort;;
101         esac
102     done
103 }
104
105 # Function to prompt the selection of the code directory.
106 function prompt_install_dir_code
107 {
108     read -p "Enter directory to install Biopieces code (default: $bp_code): " answer;
109
110     bp_code=${answer:-"$bp_code"}
111
112     if [ ! -d "$bp_code" ]; then
113         while true; do
114             read -p "Create directory: $bp_code (yes/no)? " answer
115             case $answer in
116                 [Yy]* ) dir_create $bp_code && break;;
117                 [Nn]* ) abort;;
118             esac
119         done
120     fi
121 }
122
123 # Function to prompt the selection of the data directory.
124 function prompt_install_dir_data
125 {
126     read -p "Enter directory to install Biopieces data (default: $bp_data): " answer;
127
128     bp_data=${answer:-"$bp_data"}
129
130     if [ ! -d "$bp_data" ]; then
131         while true; do
132             read -p "Create directory: $bp_data (yes/no)? " answer
133             case $answer in
134                 [Yy]* ) dir_create $bp_data && break;;
135                 [Nn]* ) abort;;
136             esac
137         done
138     fi
139 }
140
141 # Function to prompt the selection of the log directory.
142 function prompt_install_dir_log
143 {
144     read -p "Enter directory to install Biopieces log (default: $bp_log): " answer;
145
146     bp_log=${answer:-"$bp_log"}
147
148     if [ ! -d "$bp_log" ]; then
149         while true; do
150             read -p "Create directory: $bp_log (yes/no)? " answer
151             case $answer in
152                 [Yy]* ) dir_create $bp_log && break;;
153                 [Nn]* ) abort;;
154             esac
155         done
156     fi
157 }
158
159 # Function to prompt the selection of the tmp directory.
160 function prompt_install_dir_tmp
161 {
162     read -p "Enter directory to install Biopieces tmp (default: $bp_tmp): " answer;
163
164     bp_tmp=${answer:-"$bp_tmp"}
165
166     if [ ! -d "$bp_tmp" ]; then
167         while true; do
168             read -p "Create directory: $bp_tmp (yes/no)? " answer
169             case $answer in
170                 [Yy]* ) dir_create $bp_tmp && break;;
171                 [Nn]* ) abort;;
172             esac
173         done
174     fi
175 }
176
177 # Function to prompt the appending of a section to bashrc.
178 function prompt_append_bashrc
179 {
180     section="
181
182 # >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<<
183
184 export BP_DIR=\"$bp_code\"
185 export BP_DATA=\"$bp_data\"
186 export BP_TMP=\"$bp_tmp\"
187 export BP_LOG=\"$bp_log\"
188
189 source \"\$BP_DIR/bp_conf/bashrc\"
190
191 # >>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<
192
193 "
194
195     echo_yellow "$section"
196     echo "We need to append the above section to your .bashrc file."
197
198     while true; do
199         read -p "Continue (yes/no)? " answer
200         case $answer in
201             [Yy]* ) break;;
202             [Nn]* ) abort;;
203         esac
204     done
205
206     echo -n "Appending $HOME/.bashrc: "
207
208     cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"
209
210     echo "$section" >> "$HOME/.bashrc"
211
212     source "$HOME/.bashrc"
213
214     echo_green "OK"
215     echo ""
216     echo "Backup is $HOME/.bashrc_biopieces"
217 }
218
219
220 # Function to test if subversion client is in $PATH.
221 function test_svn
222 {
223     local program="svn"
224
225     echo -n "Testing subversion client - \"$program\": "
226
227     if command -v $program >/dev/null; then
228         echo_green "OK"
229     else
230         echo_red "FAIL"
231         echo "   Subversion client $program was not found."
232         abort
233     fi
234 }
235
236 # Function to test if the required version of Perl is installed.
237 function test_perl
238 {
239     echo -n "Testing Perl version: "
240
241     if error=$( perl -e 'use 5.8.0;' 2>&1 ); then
242         echo_green "OK"
243     else
244         echo_red "FAIL"
245         echo $error | sed "s/, stopped.*//"
246         abort
247     fi  
248 }
249
250 # Function to test if a given Perl module is installed.
251 function test_perl_module
252 {
253     local module=$1
254
255     echo -n "Testing required Perl module - \"$module\": "
256
257     if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then
258         echo_red "FAIL"
259         echo "   Try: perl -MCPAN -e 'install $module'"
260         abort
261     else
262         echo_green "OK"
263     fi
264 }
265
266 # Function to test if the required version of Ruby is installed.
267 function test_ruby
268 {
269     echo -n "Testing Ruby version: "
270
271     if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
272         echo_green "OK"
273     else
274         echo_red "FAIL"
275         echo $error | sed "s/.*: //"
276         abort
277     fi  
278 }
279
280 # Function to test if a given Ruby gem is installed.
281 function test_ruby_gem
282 {
283     local gem=$1
284
285     echo -n "Testing required Ruby gem - \"$gem\": "
286
287     if error=$( gem list --local | grep $gem ); then
288         echo_green "OK"
289     else
290         echo_red "FAIL"
291         echo "   Try: gem install $gem"
292         abort
293     fi
294 }
295
296 # Function to test is a given auxillary program is in $PATH.
297 function test_aux_program
298 {
299     local program=$1
300
301     echo -n "Testing auxiliary program - \"$program\": "
302
303     if command -v $program >/dev/null; then
304         echo_green "OK"
305     else
306         echo_yellow "WARNING"
307     fi
308 }
309
310 # Function to checkout the Biopieces code from subversion.
311 function checkout_code
312 {
313     echo -n "Downloading Biopieces code from repository: "
314
315     if error=$( svn checkout http://biopieces.googlecode.com/svn/trunk/ $bp_code ); then
316         echo_green "OK"
317     else
318         echo_red "FAIL"
319         echo $error
320         abort
321     fi  
322 }
323
324 # Function to checkout the Biopieces wiki from subversion.
325 function checkout_wiki
326 {
327     echo -n "Downloading Biopieces wiki from repository: "
328
329     if error=$( svn checkout http://biopieces.googlecode.com/svn/wiki/ "$bp_code/bp_usage" ); then
330         echo_green "OK"
331     else
332         echo_red "FAIL"
333         echo $error
334         abort
335     fi  
336 }
337
338 # Function to run the Biopieces test suite.
339 function run_tests
340 {
341     while true; do
342         read -p "Run the Biopieces test suite (yes/no)? " answer
343         case $answer in
344             [Yy]* ) "$BP_DIR/bp_test/test_all" && break;;
345             [Nn]* ) break;;
346         esac
347     done
348 }
349
350 prompt_install
351
352 test_svn
353 test_perl
354 test_perl_module "Inline"
355 test_perl_module "JSON::XS"
356 test_perl_module "SVG"
357 test_perl_module "Bit::Vector"
358 test_perl_module "Time::HiRes"
359 test_ruby
360 test_ruby_gem "gnuplot"
361 test_ruby_gem "narray"
362 test_aux_program "blastall"
363 test_aux_program "blat"
364 test_aux_program "bwa"
365 test_aux_program "bowtie"
366 test_aux_program "formatdb"
367 test_aux_program "gnuplot"
368 test_aux_program "idba"
369 test_aux_program "muscle"
370 test_aux_program "mummer"
371 test_aux_program "mysql"
372 test_aux_program "prodigal"
373 test_aux_program "Ray"
374 test_aux_program "scan_for_matches"
375 test_aux_program "uclust"
376 test_aux_program "velveth"
377 test_aux_program "velvetg"
378 test_aux_program "vmatch"
379
380 echo ""
381
382 prompt_install_dir_code
383 prompt_install_dir_data
384 prompt_install_dir_log
385 prompt_install_dir_tmp
386
387 checkout_code
388 checkout_wiki
389
390 prompt_append_bashrc
391
392 run_tests
393
394 echo ""
395 echo_green "Congratulations - you have now installed Biopieces."
396 echo ""
397 echo "   To list all available Biopieces try 'list_biopieces'"
398 echo ""
399 echo "   To see the synopsis of a Biopiece try 'read_fastq'"
400 echo ""
401 echo "   To see the full description and exampels try 'read_fastq -?'"
402 echo ""
403 echo "   Don't forget to join the Biopieces Google Group for important"
404 echo "   messages, questions, discussion, and suggestions:"
405 echo ""
406 echo "      http://groups.google.com/group/biopieces"
407 echo ""
408 echo "   And of cause there is the introduction:"
409 echo ""
410 echo "      http://code.google.com/p/biopieces/wiki/Introduction"
411 echo ""
412 echo "   Happy hacking!"
413 echo ""
414
415 exit