source: trunk/arb_install.sh

Last change on this file was 19266, checked in by westram, 23 months ago
  • replace realpath locally in install script
    • cannot use arb_path.sh here, because it's not yet installed.
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 20.7 KB
Line 
1#!/bin/bash
2
3bold=$(tput bold)
4underline=$(tput smul)
5normal=$(tput sgr0)
6
7echoerr() {
8    cat <<< "$@" 1>&2
9}
10
11# error message function (nested exit):
12trap "exit 1" TERM
13export ARBINST_SCRIPT_PID=$$
14err() {
15    echoerr "Error in `basename $0`:"
16    echoerr "${bold}  $@${normal}"
17    echoerr "Please fix and then rerun script!"
18    kill -s TERM $ARBINST_SCRIPT_PID
19}
20
21separator() {
22    echo ''
23}
24
25separator
26echo "${bold}${underline}Welcome to the ARB Package${normal}"
27
28test -z "${BASH_VERSINFO}" && separator && err "Please call this script using 'bash arb_install.sh'"
29
30elim_invalid_chars() {
31    local FILE="${1}"
32    # remove some characters really unwanted in paths:
33    FILE=${FILE// /}
34    FILE=${FILE//\'/}
35    FILE=${FILE//\"/}
36    FILE=${FILE//\`/}
37    echo ${FILE}
38}
39
40DL_DIR=$(pwd)
41DL_NS=$(elim_invalid_chars "${DL_DIR}")
42
43if [ ! "$DL_NS" = "$DL_DIR" ]; then
44    separator
45    if [ ! "$DL_NS" = "" ]; then
46        echo "Note: the path '$DL_NS' would be ok.."
47    fi
48    err "Your download directory '$DL_DIR' contains invalid characters."
49fi
50
51cont() {
52    echo "Warning: $@" 1>&2
53    echo "${bold}Do you want to continue [y]${normal}"
54    read var
55    case "$var" in
56        n) err "Script aborted by user" ;;
57        *) echo 'Continuing...' ;;
58    esac
59}
60
61untar() {
62    local TGZ="$1"; shift
63
64    # remove old DEPOT BUG
65    rm -f DEPOT/gde/bin
66
67    if [ ! -r "${TGZ}" ]; then
68        err "Cannot find or read file '${TGZ}'"
69    fi
70    if gunzip --stdout "${TGZ}" | tar xfv -; then
71        echo ">>> ${TGZ} uncompressed and untared"
72        if [ ! -e bin/arb_ntree ]; then
73            err "bin/arb_ntree not found (wrong archive?)"
74        fi
75        if [ ! -x bin/arb_ntree ]; then
76            err "bin/arb_ntree not executable (wrong archive?)"
77        fi
78    else
79        err "Failed to uncompress/untar '${TGZ}'"
80    fi
81}
82
83arb_realpath() {
84    # replacement for 'realpath'
85    #
86    # Note: this function is duplicated in SH/arb_path.sh@arb_realpath
87    local FILE="$1"; shift
88
89    local REALPATH=$(realpath    "$FILE" 2>/dev/null )
90    local READLINK=$(readlink -f "$FILE" 2>/dev/null )
91
92    if [ -z "${REALPATH}" ]; then
93        if [ -z "${READLINK}" ]; then
94            echoerr "Warning: neighter realpath nor readlink works here"
95            if [ -e "${FILE}" ]; then
96                local PWDFILE="$(pwd)/${FILE}"
97                if [ -e "${PWDFILE}" ]; then echo "${PWDFILE}"
98                else echo "${FILE}"
99                fi
100            else echo "${FILE}"
101            fi
102        else echo "${READLINK}"
103        fi
104    else
105        if [ -z "${READLINK}" ]; then echo "${REALPATH}"
106        else
107            if [ "${READLINK}" != "${REALPATH}" ]; then
108                echoerr "Warning: realpath and readlink differ (REALPATH=${REALPATH} READLINK=${READLINK})"
109            fi
110            echo "${REALPATH}"
111        fi
112    fi
113}
114
115# --------------------------------------------------
116# detect input archives:
117
118separator
119
120ARB_TGZ=
121SINA_TGZ=
122
123for TGZ in arb*.tgz; do
124    NOSINA=${TGZ%-sina-fat.tgz}
125    if [ "${NOSINA}" = "$TGZ" ]; then
126        if [ -z "${ARB_TGZ}" ]; then
127            ARB_TGZ="${TGZ}"
128        else
129            echo "Found two arb archives:"
130            ls -al -h "${ARB_TGZ}" "${TGZ}"
131            echo ""
132            err "cannot decide which to use. Please remove one of these!"
133        fi
134    else
135        if [ -z "${SINA_TGZ}" ]; then
136            SINA_TGZ="${TGZ}"
137        else
138            echo "Found two sina archives:"
139            ls -al -h "${SINA_TGZ}" "${TGZ}"
140            echo ""
141            err "cannot decide which to use. Please remove one of these!"
142        fi
143    fi
144done
145
146if [ -n "${SINA_TGZ}" ]; then
147    SINA_TGZ=$(arb_realpath "${SINA_TGZ}")
148    echo "Detected sina tarball: ${SINA_TGZ}"
149fi
150
151if [ -z "${ARB_TGZ}" ]; then
152    echo "For available arb versions please refer to"
153    echo "    http://bugs.arb-home.de/wiki#ARBversions"
154    separator
155    err "No arb tarball found in `pwd`"
156fi
157ARB_TGZ=$(arb_realpath "${ARB_TGZ}")
158echo "Detected arb  tarball: ${ARB_TGZ}"
159
160# --------------------------------------------------
161# general instructions + ask for destination:
162
163separator
164echo '  Note:   - You may abort this script with ctrl-"C"'
165echo '          - You can rerun this script as often as you like'
166echo '          - Old ARB data will be kept if requested (in this case'
167echo '            you can simply change some options)'
168echo '          - Pressing <return> will select the value in brackets'
169separator
170echo "${underline}Please answer some questions:${normal}"
171separator
172echo 'Where would you like to install ARB?'
173echo '  ARB is not a single program but a set of programs, datafiles ...'
174echo '  To install ARB, all files will be stored in a single directory.'
175separator
176echo '  This script will create that directory, copy all needed files and'
177echo '  sets permissions correctly.'
178separator
179echo '  Please note that you will need write permission at the destination.'
180separator
181if [ "$EUID" -ne 0 ]; then
182    # normal user
183    ARBHOMED=${HOME}/arb
184    echo '  - to install ARB inside your home directory, enter "'${ARBHOMED}'"'
185    echo '  - otherwise press Ctrl-C now to abort installation and'
186    echo '    rerun this script using:'
187    echo '        sudo bash arb_install.sh'
188else
189    # root user
190    ARBHOMED=/usr/arb
191    echo '  - to install ARB for all users, enter "'${ARBHOMED}'"'
192fi
193separator
194
195if [ "$ARBHOME" != "" ]; then
196    if test -f $ARBHOME/lib/arb_tcp.dat; then
197        echo "  Note: There seems to be an existing arb installation at"
198        echo "        ${ARBHOME}"
199        separator
200    fi
201fi
202
203echo "${bold}Enter full installation path: [${ARBHOME:-${ARBHOMED}}]${normal}"
204read ARBHOMEI
205separator
206
207if [ "$ARBHOMEI" = "" ]; then
208    ARBHOME="${ARBHOME:-${ARBHOMED}}";
209else
210    ARBHOME="${ARBHOMEI}";
211fi
212
213# check for some really unwanted characters in path:
214AH_NS=$(elim_invalid_chars ${ARBHOME})
215if [ ! "$AH_NS" = "$ARBHOME" ]; then
216    separator
217    if [ ! "$AH_NS" = "" ]; then
218        echo "Note: the path '$AH_NS' would be ok.."
219    fi
220    err "The specified path '$ARBHOME' contains invalid characters."
221fi
222
223ARBHOME=$(arb_realpath "${ARBHOME}")
224
225# --------------------------------------------------
226# handle existing arb installation:
227
228if test -d $ARBHOME; then
229    if test -w $ARBHOME; then
230        separator
231        echo 'The destination directory'
232        echo "    $ARBHOME"
233        echo 'already exists!'
234
235        if [ -z "$(ls -A ${ARBHOME})" ]; then
236            echo "Note: directory is empty and will be used for arb installation."
237        else
238            ARB_TCP_BAK=arb_tcp_`date +%Y%m%d`.dat
239            if [ ! -e ${ARB_TCP_BAK} -a -e $ARBHOME/lib/arb_tcp.dat ]; then
240                echo '[creating backup copy of arb_tcp.dat in download directory]'
241                cp $ARBHOME/lib/arb_tcp.dat ${ARB_TCP_BAK}
242            fi
243
244            echo '  You may now'
245            echo '  * either delete the old arb directory completely'
246            echo '  * or only update/change options of the old version.'
247            echo "${bold}Delete old directory? (y/n)[n]${normal}"
248            read delete_dir
249            echo
250            case "$delete_dir" in
251                y)
252                    if rm -r $ARBHOME/* ;then
253                        echo ">>> all data in $ARBHOME deleted"
254                    else
255                        cont "failed to delete files in $ARBHOME"
256                    fi
257                    ;;
258                *)
259                    if test -f $ARBHOME/lib/arb_tcp.dat; then
260                        bckup=$ARBHOME/lib/arb_tcp.dat.`date +%y%m%d%H%M%S`
261                        echo ">>>old $ARBHOME/lib/arb_tcp.dat found"
262                        echo ">>>backup to $bckup"
263                        cp $ARBHOME/lib/arb_tcp.dat $bckup
264                    fi
265                    echo ">>> old data not deleted";;
266            esac
267        fi
268    else
269        err "directory exists and is not writable";
270    fi
271else
272    if mkdir -p $ARBHOME; then
273        echo ">>> $ARBHOME created"
274    else
275        err "cannot create directory $ARBHOME";
276    fi
277fi
278
279cd $ARBHOME
280ARBHOME=`pwd`
281
282if [ -d lib/pictures ]; then
283    separator
284    echo "${underline}Old ARB package found${normal} (type n to change only some options)."
285    echo "${bold}  Do you want to update the old package? (y/n)[y]${normal}"
286    read var;
287    case "$var" in
288        n)
289            echo "Old version unchanged"
290            ;;
291        *)
292            echo "updating ARB";
293            untar "${ARB_TGZ}"
294            ;;
295    esac
296else
297    untar "${ARB_TGZ}"
298fi
299
300# --------------------------------------------------
301# configure ptserver:
302
303separator
304echo "${underline}Specify PT_SERVER files location${normal}"
305echo '  ARB needs a writeable directory to store the pt_server files. '
306echo '  Those files are needed for fast database search'
307echo '  (by probe_design, probe_match and the automatic aligner)'
308echo '  and need a lot of disc space (up to several 100 mega bytes,'
309echo '  e.g. 4000 16S RNA sequences require about 40 MB).'
310echo '  This files are not created now. They can be build by any user via'
311echo '          <ARB_NTREE/Probes/PT_SERVER admin/Build server>'
312echo '  You may define a special directory as the pt_server files location.'
313echo '  This prevents any loss of data installing a new version of '
314echo '  ARB. '
315
316echo 'Where do you want to put your pt_server data'
317echo '          1. <CR> - (new installation of ARB)'
318echo '                    for placing pt_server data within ARB directory tree'
319echo '                    (Default location).'
320echo '                  - (updating ARB)'
321echo '                    using the previous location'
322echo '          2. "Path" to link pt_server data directory to'
323echo "              (if you choose this option you won't loose your PT-Servers when doing future software updates)"
324echo "${bold}Enter path:${normal}"
325read pt_dir
326echo
327case "$pt_dir" in
328    "")
329        echo "installing the pt_server data in $ARBHOME/lib/pts"
330        if test -h ${ARBHOME}/lib/pts ; then
331            echo "Are you sure to delete "
332            echo ">>> pt_server files at non default location:"
333            ls -ld ${ARBHOME}/lib/pts
334        else
335            if test -d ${ARBHOME}/lib/pts; then
336                echo ">>> pt_server files at default location: unchanged"
337            else
338                (cd lib;rm -f pts;mkdir pts;)
339            fi
340        fi;;
341    *)
342        echo "changing your pt_server file location"
343        if test -h ${ARBHOME}/lib/pts; then
344            echo ">>> non default location found: removing old link"
345            rm lib/pts
346        else
347            if test -d ${ARBHOME}/lib/pts; then
348                echo ">>> data in default location found"
349                echo "${bold}Do you want to remove old ptserver data (recommended)? [y]${normal}"
350                read ANSWER
351                case "$ANSWER" in
352                    n) echo 'data not deleted' ;;
353                    *) rm -r lib/pts
354                       echo 'data deleted' ;;
355                esac
356            fi
357        fi
358        if test ! -d $pt_dir; then
359            echo ">>> Creating special PT_SERVER directory $pt_dir"
360            if mkdir -p $pt_dir; then
361                echo ">>> $pt_dir created"
362            else
363                err "Couldn't create $pt_dir"
364            fi
365        fi
366        (cd lib;ln -s $pt_dir pts;)
367esac
368
369separator
370echo 'Who is responsible for the PT_SERVER index files?'
371echo '  Answer  y: if you trust your users (less administration; recommended)'
372echo '          n: if PT_SERVER files shall only be changable by administrator'
373echo '  or simply press return to keep the settings of an old installation.'
374echo "${bold}Should everybody be allowed to build/update PT_SERVER files? (y/n/dont_change)[dont_change]${normal}"
375read var
376echo
377case "$var" in
378    y)
379        echo ">>> all users are allowed to update the PT_SERVER";
380        chmod 777 lib/pts
381        chmod 666 lib/pts/* 2>/dev/null ;;
382    n)
383        echo ">>> only `whoami` is allowed to update the pt_server";
384        chmod 755 lib/pts
385        chmod 644 lib/pts/* 2>/dev/null ;;
386    *)
387        echo ">>> permissions of lib/pts remain unchanged";;
388esac
389
390# --------------------------------------------------
391# configure nameserver:
392
393separator
394echo "${underline}NameServer installation${normal}"
395echo '  The NameServer is a program, that synchronizes all species names'
396echo '  of the databases of different users.'
397echo '  Users that import foreign data into their database and want to'
398echo '  export those data to other ARB users should be allowed to change'
399echo '  the names file in $ARBHOME/lib/nas/names.dat'
400echo '  Answer  y: if all users may import foreign databases'
401echo '          n: if there are some mean untrusty users'
402echo '  or simply press return to keep the old settings'
403echo "${bold}Do you trust your users? (y/n/dont_change)[dont_change]${normal}"
404read var
405echo
406case "$var" in
407    y)
408        echo ">>> all user are allowed to change the names file";
409        chmod 777 lib/nas
410        chmod 666 lib/nas/*;;
411    n)
412        echo ">>> only `whoami` is allowed to change the names file ${ARBHOME}/lib/nas/names.dat"
413        chmod 755 lib/nas
414        chmod 644 lib/nas/*;;
415    *)
416        echo ">>> permissions of lib/nas remain unchanged";;
417esac
418
419# --------------------------------------------------
420# setup arb_tcp.dat:
421
422separator
423echo "${underline}Networking${normal}"
424echo '  To speed up calculation one special host can be assigned as'
425echo '  the PT_SERVER host. That means that all database search is done'
426echo '  on that host. This saves computer resources as different users'
427echo '  may share one server.'
428echo '  To get the best results this host "H" should:'
429echo '                  1.      be fast,'
430echo '                  2.      have a lot of real memory (>=64 meg),'
431echo '                  3.      have a lot of swap space (>=400 meg),'
432echo '                  4.      allow all users to run "ssh H ...",'
433echo '                  5.      contain the discs with the PT_SERVER files.'
434
435echo '  n       You want to assign a special Network host'
436echo '  s       You have a Stand alone computer'
437if test "X$bckup" != "X"; then
438    echo '  o       Use information of already installed ARB'
439    echo "${bold}Choose (s/n/o)[s]${normal}"
440else
441    echo "${bold}Choose (s/n)[s]${normal}"
442
443fi
444read var
445echo
446
447
448case "$var" in
449    o)
450        mv $bckup lib/arb_tcp.dat;
451        echo ">>> old lib/arb_tcp.dat restored";;
452    n)
453        separator
454        echo "Enter the name of your host for the pt_server"
455        read host
456        echo "Checking connection to $host"
457        if ssh $host ls >/dev/zero; then
458            echo ">>> ssh $host ok"
459        else
460            err ">>> cannot run 'ssh $host'";
461        fi
462        rm -f lib/arb_tcp.dat;
463        cat lib/arb_tcp_org.dat |sed -e "/localhost\:/$host\:/g" >lib/arb_tcp.dat
464        echo ">>> server installed";;
465    *)
466        cp lib/arb_tcp_org.dat lib/arb_tcp.dat
467        echo ">>> server installed";;
468esac
469
470# --------------------------------------------------
471# install sina:
472
473separator
474echo "${underline}SINA integration${normal}"
475if [ -n "${SINA_TGZ}" ]; then
476    echo "Detected sina archive: ${SINA_TGZ}"
477    if [ -x bin/sina ]; then
478        echo "Note: The installed arb already seems to contain sina."
479        echo "      => will not install another sina!"
480    else
481        INSTALL_SINA=0
482        HAVE_SINA=0
483        # check for installation via SH/arb_sina_install_from_fat_tarball.sh
484        if [ -d bin/fatsina ]; then
485            echo "Note: there is already another sina installed from a tarball."
486            HAVE_SINA=1
487            echo "${bold}  Do you want to update the sina installation? (y/n)[y]${normal}"
488        else
489            echo "${bold}  Do you want to install sina into arb? (y/n)[y]${normal}"
490            INSTALL_SINA=1
491        fi
492
493        read var;
494        case "$var" in
495            n)
496                if [ ${HAVE_SINA} = 1 ]; then
497                    echo "Old sina version unchanged."
498                else
499                    echo "Will not install sina."
500                fi
501                ;;
502
503            *)
504                if [ ${HAVE_SINA} = 1 ]; then
505                    echo "updating SINA from ${SINA_TGZ}";
506                    SH/arb_sina_install_from_fat_tarball.sh UNINSTALL "${ARBHOME}"
507                else
508                    echo "installing SINA from ${SINA_TGZ}";
509                fi
510                SH/arb_sina_install_from_fat_tarball.sh "${SINA_TGZ}" "${ARBHOME}"
511                ;;
512        esac
513    fi
514else
515    if [ ! -x bin/sina ]; then
516        if [ ! -d bin/fatsina ]; then
517            echo "No sina installed with arb."
518            echo "Hint: the installation script will attempt to install sina for you,"
519            echo "      if you download an arb-XXX-fat-sina.tgz and"
520            echo "      save it into ${DL_DIR}"
521        fi
522    fi
523fi
524
525# --------------------------------------------------
526# finish + print instructions for setup
527
528separator
529echo "${bold}>>> ARB installation completed${normal}"
530
531separator
532SHELL_ANS=0
533
534echo "${underline}Finally, you have to tell your system where to find arb${normal}"
535echo "First find out which shell you are using, by opening a new terminal window and typing"
536echo '        echo $SHELL'
537echo ""
538echo "Depending on what is your shell there are several choices:"
539echo ""
540echo "    1. Change your local .profile or .bashrc (if you are using ksh/bash, which"
541echo "                                              is the default shell for Linux)"
542echo "    2. Change your local .cshrc file         (if you are using csh/tcsh)"
543echo "    3. Create an alias for arb               (any shell)"
544echo "    4. I don't want to edit anything         (any shell)"
545echo ""
546
547echo "${bold}Enter (1,2,3 or 4) to achieve further installation instructions:${normal}"
548
549while [ "$SHELL_ANS" = "0" ]; do
550
551    read var
552
553    separator
554    case "$var" in
555        1)
556            echo '******************************************************';
557            echo "${bold}add the following lines to your ~/.profile${normal}";
558            echo "${bold}or to your ~/.bashrc for bash-users${normal}";
559            echo '******************************************************';
560            echo "     ARBHOME=$ARBHOME;export ARBHOME";
561            echo '     LD_LIBRARY_PATH=${ARBHOME}/lib:${LD_LIBRARY_PATH}';
562            echo '     export LD_LIBRARY_PATH';
563            echo '     PATH=${ARBHOME}/bin:${PATH}';
564            echo '     export PATH';
565            separator
566            echo 'enter the following command:';
567            echo '     . ~/.profile'
568            SHELL_ANS=1
569            ;;
570        2)
571            echo '******************************************';
572            echo "${bold}add the following lines to your ~/.cshrc${normal}";
573            echo '******************************************';
574            echo "     setenv ARBHOME $ARBHOME";
575            if test "X${LD_LIBRARY_PATH}" != "X"; then
576                echo '     setenv LD_LIBRARY_PATH $ARBHOME/lib\:$LD_LIBRARY_PATH';
577            else
578                echo '     setenv LD_LIBRARY_PATH $ARBHOME/lib';
579            fi
580            echo '     setenv PATH $ARBHOME/bin\:$PATH';
581            separator
582            echo 'enter the following command:';
583            echo '     source ~/.cshrc'
584            SHELL_ANS=1
585            ;;
586        3)
587            echo '**************************************************';
588            echo "${bold}add one of the following lines to your init file${normal}";
589            echo '**************************************************';
590            echo "# bash users add to ~/.bashrc:";
591            echo "  alias arb=$ARBHOME/bin/arb";
592            echo "# tcsh users add to ~/.cshrc:";
593            echo "  alias arb '$ARBHOME/bin/arb'";
594            SHELL_ANS=1
595            ;;
596        4)
597            echo "Note: You will need to specify the full path to start arb.";
598            SHELL_ANS=2
599            ;;
600        *)
601            echo 'wrong answer'
602            ;;
603    esac
604done
605
606if [ "$EUID" -eq 0 ]; then
607    # only shown to root user:
608    separator
609    echo "${underline}Note for sysadmins:${normal}"
610    echo "     In order to provide arb for all users, edit one or several"
611    echo "     of the global shell init files in /etc (e.g. /etc/bash.bashrc)"
612    echo "     in the same manner as described above for the"
613    echo "     local shell init files."
614    separator
615    echo "     Note for unintended sysadmins:"
616    echo "         To edit the global bash init file use e.g."
617    echo "             sudo nano /etc/bash.bashrc"
618    echo "         Insert the 'arb' alias on a separate line."
619fi
620separator
621echo "Please read the files"
622echo $ARBHOME/arb_INSTALL.txt"
623echo $ARBHOME/arb_UBUNTU.txt    (if you're using ubuntu)"
624echo "about additional libraries and tools needed by ARB."
625separator
626echo "After you have installed everything and performed the changes to your init file,"
627echo "open a new terminal window and start arb by typing"
628separator
629if [ $SHELL_ANS = 2 ]; then
630    echo "     $ARBHOME/bin/arb";
631else
632    echo "     arb"
633fi
634separator
635echo "${bold}Have much fun using ARB${normal}"
636echo "ARB Team <arb@arb-home.de>"
637separator
638
Note: See TracBrowser for help on using the repository browser.