source: branches/help/SH/arb

Last change on this file was 18439, checked in by westram, 5 years ago
  • improve error exit from script (kill self).
  • protect functions vs. wrong use (check param 3 of addpath; deny param 3 for append and prepend).
  • quote several expressions (to allow installation paths containing spaces)
    • arb is NOT intended to be installed into such paths! see also next commit.
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1#!/bin/bash -u
2
3# set -x
4
5# error message function (nested exit):
6trap "exit 1" TERM
7export ARB_SCRIPT_PID=$$
8abort_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)
14get_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.
38addpath () {
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.
65append () {
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.
73prepend () {
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
80if [ -z ${HOME:-} ]; then
81    HOME=~
82fi
83export HOME
84
85if [ -z ${DISPLAY:-} ]; then
86    DISPLAY=:0
87fi
88export DISPLAY
89
90# get absolute path to directory where this script resides
91# (avoid use of readlink as it is missing on OSX)
92ARBHOME_OF_SCRIPT="$(get_arbhome)"
93ARB_SH="$ARBHOME_OF_SCRIPT/SH"
94ARB_SCRIPT="$ARB_SH/arb"
95
96export ARB_SH ARB_SCRIPT ARBHOME_OF_SCRIPT
97
98if [ -n "${ARBHOME:-}" -a "${ARBHOME:-}" != "$ARBHOME_OF_SCRIPT" ]; then
99    echo "Ignoring set ARBHOME '$ARBHOME' (overridden by explicit call of '$0')"
100fi
101
102# use ARBHOME defined by location of script (comment out for old behavior)
103ARBHOME="$ARBHOME_OF_SCRIPT"
104
105echo "Using ARBHOME='$ARBHOME'"
106
107prepend PATH                    "$ARBHOME/bin"
108prepend LD_LIBRARY_PATH         "$ARBHOME/lib"
109append  LD_LIBRARY_PATH         /usr/dt/lib
110append  LD_LIBRARY_PATH         /usr/openwin/lib
111append  LD_LIBRARY_PATH         "$ARBHOME/lib/addlibs"
112prepend SHLIB_PATH              "$ARBHOME/lib"
113append  SHLIB_PATH              "$ARBHOME/lib/addlibs"
114append  PYTHONPATH              "$ARBHOME/lib/python2.6"
115append  PERl5LIB                "$ARBHOME/lib/perl5"
116
117# environment variables that this shell script sets/changes:
118export LD_LIBRARY_PATH MANPATH PATH ARBHOME SHLIB_PATH
119export PYTHONPATH PERL5LIB
120
121# global envs:
122
123export PWD HOME USER
124
125if [ -x "$ARBHOME/bin/ghostview" ] ; then
126  GS_LIB="$ARBHOME/DEPOT/ghostscript"
127  export GS_LIB
128fi
129
130ARB_PID="$$"; export ARB_PID
131
132if [ -z ${ARB_PROP:-} ]; then
133    ARB_PROP="${HOME}/.arb_prop"
134fi
135echo "Using properties from $ARB_PROP"
136if [ ! -d "${ARB_PROP}" ] ; then
137  echo "Directory ${ARB_PROP} not found - creating ..."
138  mkdir "${ARB_PROP}"
139fi
140export ARB_PROP
141
142ARB_LOCAL_PTS="${HOME}/.arb_pts"
143if [ ! -d "${ARB_LOCAL_PTS}" ] ; then
144  echo "Directory ${ARB_LOCAL_PTS} not found - creating ..."
145  mkdir "${ARB_LOCAL_PTS}"
146fi
147
148if [ -z ${ARBMACROHOME:-} ] ; then
149  ARBMACROHOME="${ARB_PROP}/macros";
150fi
151if [ ! -d "${ARBMACROHOME}" ] ; then
152  echo "Directory $ARBMACROHOME not found - creating ..."
153  mkdir "${ARBMACROHOME}"
154fi
155export ARBMACROHOME
156
157if [ -z "${ARBMACRO:-}" ] ; then
158  ARBMACRO="$ARBHOME/lib/macros"
159fi
160if [ ! -d "${ARBMACRO}" ] ; then
161  echo "Directory $ARBMACRO not found - creating ..."
162  mkdir "${ARBMACRO}"
163fi
164export ARBMACRO
165
166# set default command-tool used by ARB
167ARB_XTERM=${ARB_XTERM:-xterm -sl 1000 -sb -geometry 150x60}
168export ARB_XTERM
169ARB_XCMD=${ARB_XCMD:-$ARB_XTERM -e}
170export ARB_XCMD
171
172# save LD_LIBRARY_PATH
173ARB_LIBRARY_PATH="${LD_LIBRARY_PATH}"
174export ARB_LIBRARY_PATH
175
176case "${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 "$@"
209esac
210
Note: See TracBrowser for help on using the repository browser.