1 | #!/bin/bash -u |
---|
2 | |
---|
3 | # set -x |
---|
4 | |
---|
5 | # error message function (nested exit): |
---|
6 | trap "exit 1" TERM |
---|
7 | export ARB_SCRIPT_PID=$$ |
---|
8 | abort_script_with() { |
---|
9 | echo "`basename $0`: $@" 1>&2 |
---|
10 | kill -s TERM $ARB_SCRIPT_PID |
---|
11 | } |
---|
12 | |
---|
13 | # find the installation path for this ARB (the ARBHOME) |
---|
14 | get_arbhome() { |
---|
15 | # save cwd |
---|
16 | pushd . >/dev/null |
---|
17 | # full path of this script, but may be symlinked |
---|
18 | me="${BASH_SOURCE[0]}" |
---|
19 | # while me is symlink |
---|
20 | while [ -h "$me" ]; do |
---|
21 | # change to directory where symlink "$me" resides |
---|
22 | cd "$(dirname "$me")" |
---|
23 | # set $me to whatever $me links to |
---|
24 | me="$(readlink "$(basename "$me")")" |
---|
25 | done |
---|
26 | # me isn't a symlink, so the directory it resides in |
---|
27 | # must be the actual $ARBHOME/SH |
---|
28 | cd "$(dirname "$me")" |
---|
29 | # in $ARBHOME now |
---|
30 | cd .. |
---|
31 | echo -n "$PWD" |
---|
32 | # restore old cwd |
---|
33 | popd >/dev/null |
---|
34 | } |
---|
35 | |
---|
36 | # Add to the path variable named by $1 the component $2. $3 must be |
---|
37 | # "append" or "prepend" to indicate where the component is added. |
---|
38 | addpath () { |
---|
39 | eval value=\"\$\{$1:-\}\" |
---|
40 | case "$value" in |
---|
41 | *:${2}:*|*:${2}|${2}:*|${2}) |
---|
42 | result="$value" |
---|
43 | ;; |
---|
44 | "") |
---|
45 | result="$2" |
---|
46 | ;; |
---|
47 | *) |
---|
48 | case "$3" in |
---|
49 | prepend) |
---|
50 | result="$2:${value}" |
---|
51 | ;; |
---|
52 | append) |
---|
53 | result="${value}:$2" |
---|
54 | ;; |
---|
55 | *) |
---|
56 | abort_script_with "addpath expects param 'append' or 'prepend'" |
---|
57 | ;; |
---|
58 | esac |
---|
59 | esac |
---|
60 | eval "$1=\"$result\"" |
---|
61 | unset result value |
---|
62 | } |
---|
63 | |
---|
64 | # convenience routine which appends a string to a path. |
---|
65 | append () { |
---|
66 | if [ -n "${3:-}" ]; then |
---|
67 | abort_script_with too many arguments to append: "\$3=$3" |
---|
68 | fi |
---|
69 | addpath "$1" "$2" append |
---|
70 | } |
---|
71 | |
---|
72 | # convenience routine which prepends a string to a path. |
---|
73 | prepend () { |
---|
74 | if [ -n "${3:-}" ]; then |
---|
75 | abort_script_with too many arguments to prepend: "\$3=$3" |
---|
76 | fi |
---|
77 | addpath "$1" "$2" prepend |
---|
78 | } |
---|
79 | |
---|
80 | if [ -z ${HOME:-} ]; then |
---|
81 | HOME=~ |
---|
82 | fi |
---|
83 | export HOME |
---|
84 | |
---|
85 | if [ -z ${DISPLAY:-} ]; then |
---|
86 | DISPLAY=:0 |
---|
87 | fi |
---|
88 | export DISPLAY |
---|
89 | |
---|
90 | # get absolute path to directory where this script resides |
---|
91 | # (avoid use of readlink as it is missing on OSX) |
---|
92 | ARBHOME_OF_SCRIPT="$(get_arbhome)" |
---|
93 | ARB_SH="$ARBHOME_OF_SCRIPT/SH" |
---|
94 | ARB_SCRIPT="$ARB_SH/arb" |
---|
95 | |
---|
96 | export ARB_SH ARB_SCRIPT ARBHOME_OF_SCRIPT |
---|
97 | |
---|
98 | if [ -n "${ARBHOME:-}" -a "${ARBHOME:-}" != "$ARBHOME_OF_SCRIPT" ]; then |
---|
99 | echo "Ignoring set ARBHOME '$ARBHOME' (overridden by explicit call of '$0')" |
---|
100 | fi |
---|
101 | |
---|
102 | # use ARBHOME defined by location of script (comment out for old behavior) |
---|
103 | ARBHOME="$ARBHOME_OF_SCRIPT" |
---|
104 | |
---|
105 | echo "Using ARBHOME='$ARBHOME'" |
---|
106 | |
---|
107 | prepend PATH "$ARBHOME/bin" |
---|
108 | prepend LD_LIBRARY_PATH "$ARBHOME/lib" |
---|
109 | append LD_LIBRARY_PATH /usr/dt/lib |
---|
110 | append LD_LIBRARY_PATH /usr/openwin/lib |
---|
111 | append LD_LIBRARY_PATH "$ARBHOME/lib/addlibs" |
---|
112 | prepend SHLIB_PATH "$ARBHOME/lib" |
---|
113 | append SHLIB_PATH "$ARBHOME/lib/addlibs" |
---|
114 | append PYTHONPATH "$ARBHOME/lib/python2.6" |
---|
115 | append PERl5LIB "$ARBHOME/lib/perl5" |
---|
116 | |
---|
117 | # environment variables that this shell script sets/changes: |
---|
118 | export LD_LIBRARY_PATH MANPATH PATH ARBHOME SHLIB_PATH |
---|
119 | export PYTHONPATH PERL5LIB |
---|
120 | |
---|
121 | # global envs: |
---|
122 | |
---|
123 | export PWD HOME USER |
---|
124 | |
---|
125 | if [ -x "$ARBHOME/bin/ghostview" ] ; then |
---|
126 | GS_LIB="$ARBHOME/DEPOT/ghostscript" |
---|
127 | export GS_LIB |
---|
128 | fi |
---|
129 | |
---|
130 | ARB_PID="$$"; export ARB_PID |
---|
131 | |
---|
132 | if [ -z ${ARB_PROP:-} ]; then |
---|
133 | ARB_PROP="${HOME}/.arb_prop" |
---|
134 | fi |
---|
135 | echo "Using properties from $ARB_PROP" |
---|
136 | if [ ! -d "${ARB_PROP}" ] ; then |
---|
137 | echo "Directory ${ARB_PROP} not found - creating ..." |
---|
138 | mkdir "${ARB_PROP}" |
---|
139 | fi |
---|
140 | export ARB_PROP |
---|
141 | |
---|
142 | ARB_LOCAL_PTS="${HOME}/.arb_pts" |
---|
143 | if [ ! -d "${ARB_LOCAL_PTS}" ] ; then |
---|
144 | echo "Directory ${ARB_LOCAL_PTS} not found - creating ..." |
---|
145 | mkdir "${ARB_LOCAL_PTS}" |
---|
146 | fi |
---|
147 | |
---|
148 | if [ -z ${ARBMACROHOME:-} ] ; then |
---|
149 | ARBMACROHOME="${ARB_PROP}/macros"; |
---|
150 | fi |
---|
151 | if [ ! -d "${ARBMACROHOME}" ] ; then |
---|
152 | echo "Directory $ARBMACROHOME not found - creating ..." |
---|
153 | mkdir "${ARBMACROHOME}" |
---|
154 | fi |
---|
155 | export ARBMACROHOME |
---|
156 | |
---|
157 | if [ -z "${ARBMACRO:-}" ] ; then |
---|
158 | ARBMACRO="$ARBHOME/lib/macros" |
---|
159 | fi |
---|
160 | if [ ! -d "${ARBMACRO}" ] ; then |
---|
161 | echo "Directory $ARBMACRO not found - creating ..." |
---|
162 | mkdir "${ARBMACRO}" |
---|
163 | fi |
---|
164 | export ARBMACRO |
---|
165 | |
---|
166 | # set default command-tool used by ARB |
---|
167 | ARB_XTERM=${ARB_XTERM:-xterm -sl 1000 -sb -geometry 150x60} |
---|
168 | export ARB_XTERM |
---|
169 | ARB_XCMD=${ARB_XCMD:-$ARB_XTERM -e} |
---|
170 | export ARB_XCMD |
---|
171 | |
---|
172 | # save LD_LIBRARY_PATH |
---|
173 | ARB_LIBRARY_PATH="${LD_LIBRARY_PATH}" |
---|
174 | export ARB_LIBRARY_PATH |
---|
175 | |
---|
176 | case "${1:-}" in |
---|
177 | help|-h|--help) |
---|
178 | arb_ntree --help |
---|
179 | echo "" |
---|
180 | echo "" |
---|
181 | echo "arb - script to start arb" |
---|
182 | echo "Usage:" |
---|
183 | echo " arb # startup arb intro window" |
---|
184 | echo " arb [ntargs] # start arb with arguments" |
---|
185 | echo " arb shell # startup arb environment, but do not run arb" |
---|
186 | echo " arb help # show help" |
---|
187 | echo " arb trace [ntargs] # trace arb (to detect errors)" |
---|
188 | echo "" |
---|
189 | echo "ntargs are any argument allowed to arb_ntree (see above)" |
---|
190 | echo "" |
---|
191 | echo "" |
---|
192 | ;; |
---|
193 | shell) |
---|
194 | echo "Opening an ARB shell" |
---|
195 | if [ -n "$SHELL" ]; then |
---|
196 | $SHELL |
---|
197 | else |
---|
198 | bash -i |
---|
199 | fi |
---|
200 | echo "ARB shell terminates" |
---|
201 | ;; |
---|
202 | trace) |
---|
203 | shift |
---|
204 | arb_launcher $ARBHOME/SH/arb_trace "$@" |
---|
205 | ;; |
---|
206 | *) |
---|
207 | echo "Please wait while the program ARB is starting ....." |
---|
208 | arb_launcher arb_ntree "$@" |
---|
209 | esac |
---|
210 | |
---|