source: branches/stable/arb_install.sh

Last change on this file was 18691, checked in by westram, 3 years ago
  • tweak arb installation script
    • add test to ensure script is running in bash.
    • fix bug for existing, but empty installation directory.
    • move code to remove unwanted characters from path into sub.
      • also check download directory for invalid characters.
    • tweak path selection: use different defaults + hints for root and normal users.
    • 'Note for sysadmins' only shown if installation runs as root.
    • improve on-screen instructions.
    • show leaner error messages.
    • remove useless unset-section
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 15.5 KB
Line 
1#!/bin/bash
2
3# error message function (nested exit):
4trap "exit 1" TERM
5export ARBINST_SCRIPT_PID=$$
6err() {
7    echo "Error in `basename $0`:" 1>&2
8    echo $@" 1>&2
9    echo "Please fix and then rerun script!" 1>&2
10    kill -s TERM $ARBINST_SCRIPT_PID
11}
12
13separator() {
14    echo ''
15    echo '*******************************************'
16}
17
18separator
19echo 'Welcome to the ARB Package'
20
21test -z "${BASH_VERSINFO}" && separator && err "Please call this script using 'bash arb_install.sh'"
22
23elim_invalid_chars() {
24    local FILE="${1}"
25    # remove some characters really unwanted in paths:
26    FILE=${FILE// /}
27    FILE=${FILE//\'/}
28    FILE=${FILE//\"/}
29    FILE=${FILE//\`/}
30    echo ${FILE}
31}
32
33DL_DIR=$(pwd)
34DL_NS=$(elim_invalid_chars "${DL_DIR}")
35
36if [ ! "$DL_NS" = "$DL_DIR" ]; then
37    separator
38    if [ ! "$DL_NS" = "" ]; then
39        echo "Note: the path '$DL_NS' would be ok.."
40    fi
41    err "Your download directory '$DL_DIR' contains invalid characters."
42fi
43
44cont() {
45    echo "Warning: $@" 1>&2
46    echo 'Do you want to continue [y]'
47    read var
48    case "$var" in
49        n) err "Script aborted by user" ;;
50        *) echo 'Continuing...' ;;
51    esac
52}
53
54untar() {
55    # remove old DEPOT BUG
56    rm -f DEPOT/gde/bin
57
58    if [ ! -r $cwd/$1 ]; then
59        err "Cannot find or read file  $cwd/$1"
60    fi
61    if gunzip --stdout $cwd/$1 | tar xfv -; then
62        echo ">>> $1 uncompressed and untared"
63        if [ ! -e bin/arb_ntree ]; then
64            err "bin/arb_ntree not found"
65        fi
66        if [ ! -x bin/arb_ntree ]; then
67            err "bin/arb_ntree not executable"
68        fi
69    else
70        err "Error in uncompressing or untaring $1"
71    fi
72}
73
74separator
75echo '  Note:   - You may abort this script with ctrl-"C"'
76echo '          - You can rerun this script as often as you like'
77echo '          - Old ARB data will be kept if requested (in this case'
78echo '            you can simply change some options)'
79echo '          - Pressing <return> will select the value in brackets'
80separator
81echo 'Please answer some questions:'
82separator
83echo 'Where would you like to install ARB?'
84echo '  ARB is not a single program but a set of programs, datafiles ...'
85echo '  To install ARB, all files will be stored in a single directory.'
86echo ''
87echo '  This script will create that directory, copy all needed files and'
88echo '  sets permissions correctly.'
89echo ''
90echo '  Please note that you will need write permission at the destination.'
91echo ''
92if [ "$EUID" -ne 0 ]; then
93    # normal user
94    ARBHOMED=${HOME}/arb
95    echo '  - to install ARB inside your home directory, enter "'${ARBHOMED}'"'
96    echo '  - otherwise press Ctrl-C now to abort installation and'
97    echo '    rerun this script using:'
98    echo '        sudo bash arb_install.sh'
99else
100    # root user
101    ARBHOMED=/usr/arb
102    echo '  - to install ARB for all users, enter "'${ARBHOMED}'"'
103fi
104echo ''
105
106if [ "$ARBHOME" != "" ]; then
107    if test -f $ARBHOME/lib/arb_tcp.dat; then
108        echo "  Note: There seems to be an existing arb installation at"
109        echo "        ${ARBHOME}"
110        echo ''
111    fi
112fi
113
114echo "Enter full installation path: [${ARBHOME:-${ARBHOMED}}]"
115read ARBHOMEI
116echo
117echo
118
119if [ "$ARBHOMEI" = "" ]; then
120    ARBHOME="${ARBHOME:-${ARBHOMED}}";
121else
122    ARBHOME="${ARBHOMEI}";
123fi
124
125# check for some really unwanted characters in path:
126AH_NS=$(elim_invalid_chars ${ARBHOME})
127if [ ! "$AH_NS" = "$ARBHOME" ]; then
128    separator
129    if [ ! "$AH_NS" = "" ]; then
130        echo "Note: the path '$AH_NS' would be ok.."
131    fi
132    err "The specified path '$ARBHOME' contains invalid characters."
133fi
134
135cwd=`pwd`
136
137if [ ! -f arb.tgz ]; then
138    if [ -e arb-*.tgz ]; then
139        # link any arb-*.tgz to arb.tgz
140        ln -s arb-*.tgz arb.tgz
141        ls -al arb.tgz arb-*.tgz
142        if [ ! -L arb.tgz ]; then
143            err "Failed to link any arb-tarball to arb.tgz (maybe there are multiple arb-*.tgz in this directory)"
144        fi
145    else
146        err "Expected exactly one arb-*.tgz in current directory."
147    fi
148else
149    ls -al arb.tgz arb-*.tgz
150fi
151
152if [ ! -f arb.tgz ]; then
153    if [ -L arb.tgz ]; then
154        rm arb.tgz
155        err "arb.tgz does not link to a file - removed link"
156    else
157        err "arb.tgz is neither file nor link - can't handle"
158    fi
159fi
160
161if test -d $ARBHOME; then
162    echo 'Creating backup copy of arb_tcp.dat ..'
163    cp $ARBHOME/lib/arb_tcp.dat arb_tcp_`date +%Y%m%d`.dat
164
165    if test -w $ARBHOME; then
166        separator
167        echo 'The destination directory'
168        echo "    $ARBHOME"
169        echo 'already exists!'
170        if [ -z "$(ls -A ${ARBHOME})" ]; then
171            echo "Note: directory is empty and will be used for arb installation."
172        else
173            echo '  You may now'
174            echo '  * either delete the old arb directory completely'
175            echo '  * or only update/change options of the old version.'
176            echo 'Delete old directory (y/n)[n]?'
177            read delete_dir
178            echo
179            case "$delete_dir" in
180                y)
181                    if rm -r $ARBHOME/* ;then
182                        echo ">>> all data in $ARBHOME deleted"
183                    else
184                        cont "failed to delete files in $ARBHOME"
185                    fi
186                    ;;
187                *)
188                    if test -f $ARBHOME/lib/arb_tcp.dat; then
189                        bckup=$ARBHOME/lib/arb_tcp.dat.`date +%y%m%d%H%M%S`
190                        echo ">>>old $ARBHOME/lib/arb_tcp.dat found"
191                        echo ">>>backup to $bckup"
192                        cp $ARBHOME/lib/arb_tcp.dat $bckup
193                    fi
194                    echo ">>> old data not deleted";;
195            esac
196        fi
197    else
198        err "directory exists and is not writable";
199    fi
200else
201    if mkdir -p $ARBHOME; then
202        echo ">>> $ARBHOME created"
203    else
204        err "cannot create directory $ARBHOME";
205    fi
206fi
207
208cd $ARBHOME
209ARBHOME=`pwd`
210
211if test -d lib/pictures; then
212    separator
213    echo "Old ARB package found (type n to change only some options)."
214    echo "  Do you want to update the old package: (y/n)[y]"
215    read var;
216    case "$var" in
217        n)
218        echo "Old version unchanged";;
219        *)
220        echo "updating ARB";
221        untar arb.tgz;;
222    esac
223else
224    untar arb.tgz;
225fi
226
227separator
228echo 'Specify PT_SERVER files location'
229echo '  ARB needs a writeable directory to store the pt_server files. '
230echo '  Those files are needed for fast database search'
231echo '  (by probe_design, probe_match and the automatic aligner)'
232echo '  and need a lot of disc space (up to several 100 mega bytes,'
233echo '  e.g. 4000 16S RNA sequences require about 40 MB).'
234echo '  This files are not created now. They can be build by any user via'
235echo '          <ARB_NTREE/Probes/PT_SERVER admin/Build server>'
236echo '  You may define a special directory as the pt_server files location.'
237echo '  This prevents any loss of data installing a new version of '
238echo '  ARB. '
239
240echo 'Where do you want to put your pt_server data'
241echo '          1. <CR> - (new installation of ARB)'
242echo '                    for placing pt_server data within ARB directory tree'
243echo '                    (Default location).'
244echo '                  - (updating ARB)'
245echo '                    using the previous location'
246echo '          2. "Path" to link pt_server data directory to'
247echo "              (if you choose this option you won't loose your PT-Servers when doing future software updates)"
248echo 'Enter path:'
249read pt_dir
250echo
251case "$pt_dir" in
252    "")
253    echo "installing the pt_server data in $ARBHOME/lib/pts"
254    if test -h ${ARBHOME}/lib/pts ; then
255        echo "Are you sure to delete "
256        echo ">>> pt_server files at non default location:"
257        ls -ld ${ARBHOME}/lib/pts
258    else
259        if test -d ${ARBHOME}/lib/pts; then
260            echo ">>> pt_server files at default location: unchanged"
261        else
262            (cd lib;rm -f pts;mkdir pts;)
263        fi
264    fi;;
265    *)
266    echo "changing your pt_server file location"
267    if test -h ${ARBHOME}/lib/pts; then
268        echo ">>> non default location found: removing old link"
269        rm lib/pts
270    else
271        if test -d ${ARBHOME}/lib/pts; then
272            echo ">>> data in default location found"
273            echo 'Do you want to remove old ptserver data (recommended)? [y]'
274            read ANSWER
275            case "$ANSWER" in
276                n) echo 'data not deleted' ;;
277                *) rm -r lib/pts
278                echo 'data deleted' ;;
279            esac
280        fi
281    fi
282    if test ! -d $pt_dir; then
283        echo ">>> Creating special PT_SERVER directory $pt_dir"
284        if mkdir -p $pt_dir; then
285            echo ">>> $pt_dir created"
286        else
287            err "Couldn't create $pt_dir"
288        fi
289    fi
290    (cd lib;ln -s $pt_dir pts;)
291esac
292
293separator
294echo 'Who is responsible for the PT_SERVER index files ?'
295echo '  Answer  y: if you trust your users (less administration; recommended)'
296echo '          n: if PT_SERVER files shall only be changable by administrator'
297echo '  or simply press return to keep the settings of an old installation.'
298echo 'Should everybody be allowed to build/update PT_SERVER files (y/n/dont_change)[dont_change]?'
299read var
300echo
301case "$var" in
302    y)
303    echo ">>> all users are allowed to update the PT_SERVER";
304    chmod 777 lib/pts
305    chmod 666 lib/pts/* 2>/dev/null ;;
306    n)
307    echo ">>> only `whoami` is allowed to update the pt_server";
308    chmod 755 lib/pts
309    chmod 644 lib/pts/* 2>/dev/null ;;
310    *)
311    echo ">>> flags unchanged";;
312esac
313
314separator
315echo 'NameServer installation'
316echo '  The NameServer is a program, that synchronizes all species names'
317echo '  of the databases of different users.'
318echo '  Users that import foreign data into their database and want to'
319echo '  export those data to other ARB users should be allowed to change'
320echo '  the names file in $ARBHOME/lib/nas/names.dat'
321echo '  Answer  y: if all users may import foreign databases'
322echo '          n: if there are some mean untrusty users'
323echo '  or simply press return to keep the old settings'
324echo 'Do you trust your users (y/n/dont_change)[dont_change]?'
325read var
326echo
327case "$var" in
328    y)
329    echo ">>> all user are allowed to change the names file";
330    chmod 777 lib/nas
331    chmod 666 lib/nas/*;;
332    n)
333    echo ">>> only `whoami` is allowed to change the names file ${ARBHOME}/lib/nas/names.dat"
334    chmod 755 lib/nas
335    chmod 644 lib/nas/*;;
336    *)
337    echo ">>> flags unchanged";;
338esac
339
340separator
341echo 'Networking'
342echo '  To speed up calculation one special host can be assigned as'
343echo '  the PT_SERVER host. That means that all database search is done'
344echo '  on that host. This saves computer resources as different users'
345echo '  may share one server.'
346echo '  To get the best results this host "H" should:'
347echo '                  1.      be fast,'
348echo '                  2.      have a lot of real memory (>=64 meg),'
349echo '                  3.      have a lot of swap space (>=400 meg),'
350echo '                  4.      allow all users to run "ssh H ...",'
351echo '                  5.      contain the discs with the PT_SERVER files.'
352
353echo '  n       You want to assign a special Network host'
354echo '  s       You have a Stand alone computer'
355if test "X$bckup" != "X"; then
356    echo '        o       Use information of already installed ARB'
357    echo 'Choose (s/n/o)[s]?'
358else
359    echo 'Choose (s/n)[s]?'
360
361fi
362read var
363echo
364
365
366
367case "$var" in
368    o)
369    mv $bckup lib/arb_tcp.dat;
370    echo ">>> old lib/arb_tcp.dat restored";;
371    n)
372    separator
373    echo "Enter the name of your host for the pt_server"
374    read host
375    echo "Checking connection to $host"
376    if ssh $host ls >/dev/zero; then
377        echo ">>> ssh $host ok"
378    else
379        err ">>> cannot run 'ssh $host'";
380    fi
381    rm -f lib/arb_tcp.dat;
382    cat lib/arb_tcp_org.dat |sed -e "/localhost\:/$host\:/g" >lib/arb_tcp.dat
383    echo ">>> server installed";;
384    *)
385    cp lib/arb_tcp_org.dat lib/arb_tcp.dat
386    echo ">>> server installed";;
387esac
388
389separator
390echo ">>> Installation Complete"
391
392separator
393SHELL_ANS=0
394
395while [ "$SHELL_ANS" = "0" ]; do
396
397    echo "Finally, you have to tell your system where to find arb."
398    echo "First find out which shell you are using, by opening a new terminal window and typing"
399    echo '        echo $SHELL'
400    echo ""
401    echo "Depending on what is your shell there are three choices:"
402    echo ""
403    echo "    1. Change your local .profile or .bashrc (if you are using ksh/bash, which"
404    echo "                                              is the default shell for Linux)"
405    echo "    2. Change your local .cshrc file         (if you are using csh/tcsh)"
406    echo "    3. Create an alias for arb               (any shell)"
407    echo ""
408
409    echo "Enter (1,2 or 3) to achieve further installation instructions:"
410
411    read var
412
413    echo '';
414    echo '**********************************************************************************************';
415    echo 'Follow the steps below with care!!!';
416    echo '';
417    case "$var" in
418        1)
419        echo '******************************************************';
420        echo "add the following lines to your ~/.profile";
421        echo "or to your ~/.bashrc for bash-users";
422        echo '******************************************************';
423        echo "     ARBHOME=$ARBHOME;export ARBHOME";
424        echo '     LD_LIBRARY_PATH=${ARBHOME}/lib:${LD_LIBRARY_PATH}';
425        echo '     export LD_LIBRARY_PATH';
426        echo '     PATH=${ARBHOME}/bin:${PATH}';
427        echo '     export PATH';
428        echo ' '
429        echo 'enter the following command:';
430        echo '     . ~/.profile'
431        SHELL_ANS=1 ;;
432        2)
433        echo '******************************************';
434        echo "add the following lines to your ~/.cshrc";
435        echo '******************************************';
436        echo "     setenv ARBHOME $ARBHOME";
437        if test "X${LD_LIBRARY_PATH}" != "X"; then
438            echo '     setenv LD_LIBRARY_PATH $ARBHOME/lib\:$LD_LIBRARY_PATH';
439        else
440            echo '     setenv LD_LIBRARY_PATH $ARBHOME/lib';
441        fi
442        echo '     setenv PATH $ARBHOME/bin\:$PATH';
443        echo ' '
444        echo 'enter the following command:';
445        echo '     source ~/.cshrc'
446        SHELL_ANS=1 ;;
447        3)
448        echo '**************************************************';
449        echo "add one of the following lines to your init file";
450        echo '**************************************************';
451        echo "# bash users add to ~/.bashrc:";
452        echo "  alias arb=$ARBHOME/bin/arb";
453        echo "# tcsh users add to ~/.cshrc:";
454        echo "  alias arb '$ARBHOME/bin/arb'";
455        SHELL_ANS=1 ;;
456        *)
457        echo 'Wrong answer';;
458    esac
459done
460
461if [ "$EUID" -eq 0 ]; then
462    # only shown to root user:
463    echo ""
464    echo "Note for sysadmins:"
465    echo "     In order to provide arb for all users, edit one or several"
466    echo "     of the global shell init files in /etc (e.g. /etc/bash.bashrc)"
467    echo "     in the same manner as described above for the"
468    echo "     local shell init files."
469    echo ""
470    echo "     Note for unintended sysadmins:"
471    echo "         To edit the global bash init file use e.g."
472    echo "             sudo nano /etc/bash.bashrc"
473    echo "         Insert the 'arb' alias on a separate line."
474fi
475echo ""
476echo "Please read the files"
477echo $ARBHOME/arb_INSTALL.txt"
478echo $ARBHOME/arb_UBUNTU.txt    (if you're using ubuntu)"
479echo "about additional libraries and tools needed by ARB."
480echo ""
481echo "After you have installed everything and performed the changes to your init file,"
482echo "open a new terminal window and start arb by typing"
483echo ""
484echo "     arb"
485echo ""
486echo "Have much fun using ARB"
487echo "ARB Team <arb@arb-home.de>"
488echo ""
489
Note: See TracBrowser for help on using the repository browser.