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