1 | #!/bin/bash |
---|
2 | |
---|
3 | error() { |
---|
4 | local ERROR="$1"; shift |
---|
5 | |
---|
6 | if [ -n "${ERROR}" ]; then echo "Error: ${ERROR}"; fi |
---|
7 | exit 1 |
---|
8 | } |
---|
9 | |
---|
10 | usage() { |
---|
11 | local ERROR="$1"; shift |
---|
12 | |
---|
13 | set +x |
---|
14 | |
---|
15 | echo "Installs sina version from fat tarball." |
---|
16 | echo "" |
---|
17 | echo "A fat tarball contains a sina binary plus several required shared libs." |
---|
18 | echo "- it is created on all systems where sina succeeds to build (as part of the arb build)." |
---|
19 | echo "- it is provided for download for such systems on http://www.arb-home.de/" |
---|
20 | echo "- it allows to use sina on (some) of those systems where sina fails to build with arb." |
---|
21 | echo "" |
---|
22 | echo "Usage: arb_sina_install_from_fat_tarball.sh <fat-tarball> <arbhome> [--no-check]" |
---|
23 | echo " <fat-tarball> path of the fat sina tarball" |
---|
24 | echo " <arbhome> install inside this arb installation" |
---|
25 | echo "" |
---|
26 | echo "If --no-check is specified => skip call to sina binary." |
---|
27 | echo "To uninstall specify 'UNINSTALL' for <fat-tarball>." |
---|
28 | echo "" |
---|
29 | |
---|
30 | error "${ERROR}" |
---|
31 | } |
---|
32 | |
---|
33 | main() { |
---|
34 | local TARBALL="$1"; shift |
---|
35 | local ARBHOME="$1"; shift |
---|
36 | local THIRDARG="$1"; shift |
---|
37 | |
---|
38 | if [ "${TARBALL}" = "-h" -o "${TARBALL}" = "--help" ]; then usage; fi |
---|
39 | if [ -z "${ARBHOME}" ]; then usage "Missing arguments"; fi |
---|
40 | |
---|
41 | local CHECK=1 |
---|
42 | if [ -n "${THIRDARG}" ]; then |
---|
43 | if [ "${THIRDARG}" = "--no-check" ]; then |
---|
44 | CHECK=0 |
---|
45 | else |
---|
46 | usage "Unknown third argument '${THIRDARG}'" |
---|
47 | fi |
---|
48 | fi |
---|
49 | |
---|
50 | local ARB_PATH="$(dirname $0)/arb_path.sh" |
---|
51 | |
---|
52 | ARBHOME=$(${ARB_PATH} -r $ARBHOME) |
---|
53 | |
---|
54 | # remove all trailing slashes from directory and append one: |
---|
55 | shopt -s extglob; ARBHOME=${ARBHOME%%+(/)}/ |
---|
56 | |
---|
57 | local UNINSTALL=0 |
---|
58 | if [ "${TARBALL}" = "UNINSTALL" ]; then UNINSTALL=1; fi |
---|
59 | |
---|
60 | if [ $UNINSTALL = 0 ]; then |
---|
61 | TARBALL=$(${ARB_PATH} -r $TARBALL) |
---|
62 | test -e "${TARBALL}" || usage "No such file: ${TARBALL}" |
---|
63 | fi |
---|
64 | test -d "${ARBHOME}" || usage "No such directory: ${ARBHOME}" |
---|
65 | |
---|
66 | local BINDIR=${ARBHOME}bin/ |
---|
67 | test -d "${BINDIR}" || error "Expected 'bin' directory inside <arbhome>, i.e. ${BINDIR} (wrong <arbhome> specified?)" |
---|
68 | |
---|
69 | local ARB_BINARY=${BINDIR}arb_ntree |
---|
70 | test -x "${ARB_BINARY}" || error "Expected main arb binary ${ARB_BINARY} (wrong <arbhome> specified?)" |
---|
71 | |
---|
72 | local TARGETDIR=${BINDIR}fatsina/ |
---|
73 | if [ $UNINSTALL = 1 ]; then |
---|
74 | if [ ! -d ${TARGETDIR} ]; then |
---|
75 | error "sina installation directory '${TARGETDIR}' not found (nothing to uninstall)." |
---|
76 | fi |
---|
77 | |
---|
78 | echo "* uninstalling fatsina from arb installation ${ARBHOME}" |
---|
79 | rm -rf ${TARGETDIR} || error "Failed to remove '${TARGETDIR}'." |
---|
80 | else |
---|
81 | if [ -d ${TARGETDIR} ]; then |
---|
82 | error "sina installation directory '${TARGETDIR}' already exists." |
---|
83 | fi |
---|
84 | |
---|
85 | echo "* installing from fat sina tarball ${TARBALL}" |
---|
86 | echo "* installing into arb installation ${ARBHOME}" |
---|
87 | |
---|
88 | mkdir -p ${TARGETDIR} || error "Failed to make directory '${TARGETDIR}'." |
---|
89 | cd ${TARGETDIR} || error "Failed to cd to '${TARGETDIR}'." |
---|
90 | tar -zxf ${TARBALL} || error "Failed to unpack '${TARBALL}'." |
---|
91 | |
---|
92 | if [ ${CHECK} = 1 ]; then |
---|
93 | local SINACALL="LD_LIBRARY_PATH=${TARGETDIR} ${TARGETDIR}sina --has-cli-vers ARB7.1" |
---|
94 | # local SINACALL_VIABASH="bash -c '( ${SINACALL} )'" |
---|
95 | |
---|
96 | echo "* checking dynamic linkage of installed sina binary:" |
---|
97 | echo " using command: bash -c '( ${SINACALL} )'" |
---|
98 | echo "------------------------------------------------------------" |
---|
99 | bash -c "( ${SINACALL} )" |
---|
100 | echo "------------------------------------------------------------" |
---|
101 | echo "Expected output between dashed lines above would be similar to" |
---|
102 | echo "** SINA (SILVA Incremental Aligner) 1.2.3 present" |
---|
103 | echo "" |
---|
104 | echo "If it shows dynamic linking errors, you can try to fix that by" |
---|
105 | echo "deleting single libraries mentioned in error messages." |
---|
106 | echo "" |
---|
107 | echo "If that does not help, this sina-fat-tarball is incompatible with" |
---|
108 | echo "your operation system." |
---|
109 | echo "You could try fat-tarballs built on different OS versions." |
---|
110 | echo "" |
---|
111 | else |
---|
112 | echo "* assuming remote install (skipping compatibility test)" |
---|
113 | fi |
---|
114 | fi |
---|
115 | } |
---|
116 | |
---|
117 | # set -x |
---|
118 | |
---|
119 | main $* |
---|