source: tags/arb-6.0/SH/arb

Last change on this file was 11070, checked in by westram, 10 years ago
  • tested 'arb' script with EMPTY environment. sets defaults for
    • $HOME ('~'; seems to work; might be problematic, but i have no better idea how to get a default)
    • $DISPLAY (':0')
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1#!/bin/bash -u
2
3# set -x
4
5# error message function
6err () {
7        echo "`basename $0`: $@" 1>&2
8        exit 1
9}
10
11# find the installation path for this ARB (the ARBHOME)
12get_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.
36addpath () {
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.
60append () {
61    addpath "$1" "$2" append
62}
63
64# convenience routine which prepends a string to a path.
65prepend () {
66    addpath "$1" "$2" prepend
67}
68
69if [ -z ${HOME:-} ]; then
70    HOME=~
71fi
72export HOME
73
74if [ -z ${DISPLAY:-} ]; then
75    DISPLAY=:0
76fi
77export DISPLAY
78
79# get absolute path to directory where this script resides
80# (avoid use of readlink as it is missing on OSX)
81ARBHOME_OF_SCRIPT="$(get_arbhome)"
82ARB_SH="$ARBHOME_OF_SCRIPT/SH"
83ARB_SCRIPT="$ARB_SH/arb"
84
85export ARB_SH ARB_SCRIPT ARBHOME_OF_SCRIPT
86
87if [ -n "${ARBHOME:-}" -a "${ARBHOME:-}" != "$ARBHOME_OF_SCRIPT" ]; then
88    echo "Ignoring set ARBHOME '$ARBHOME' (overridden by explicit call of '$0')"
89fi
90
91# use ARBHOME defined by location of script (comment out for old behavior)
92ARBHOME=$ARBHOME_OF_SCRIPT
93
94echo "Using ARBHOME='$ARBHOME'"
95
96prepend PATH                    $ARBHOME/bin
97prepend LD_LIBRARY_PATH         $ARBHOME/lib
98append  LD_LIBRARY_PATH         /usr/dt/lib
99append  LD_LIBRARY_PATH         /usr/openwin/lib
100append  LD_LIBRARY_PATH         $ARBHOME/lib/addlibs
101prepend SHLIB_PATH              $ARBHOME/lib
102append  SHLIB_PATH              $ARBHOME/lib/addlibs
103append  PYTHONPATH      $ARBHOME/lib/python2.6
104append  PERl5LIB        $ARBHOME/lib/perl5 
105
106# environment variables that this shell script sets/changes:
107export LD_LIBRARY_PATH MANPATH PATH ARBHOME SHLIB_PATH
108export PYTHONPATH PERL5LIB
109
110# global envs:
111
112export PWD HOME USER
113
114if [ -x $ARBHOME/bin/ghostview ] ; then
115  GS_LIB="$ARBHOME/DEPOT/ghostscript"
116  export GS_LIB
117fi
118
119ARB_PID="$$"; export ARB_PID
120
121if [ -z ${ARB_PROP:-} ]; then
122    ARB_PROP=${HOME}/.arb_prop
123fi
124echo "Using properties from $ARB_PROP"
125if [ ! -d ${ARB_PROP} ] ; then
126  echo "Directory ${ARB_PROP} not found - creating ..."
127  mkdir ${ARB_PROP}
128fi
129export ARB_PROP
130
131ARB_LOCAL_PTS=${HOME}/.arb_pts
132if [ ! -d ${ARB_LOCAL_PTS} ] ; then
133  echo "Directory ${ARB_LOCAL_PTS} not found - creating ..."
134  mkdir ${ARB_LOCAL_PTS}
135fi
136
137if [ -z ${ARBMACROHOME:-} ] ; then
138  ARBMACROHOME="${ARB_PROP}/macros";
139fi
140if [ ! -d ${ARBMACROHOME} ] ; then
141  echo "Directory $ARBMACROHOME not found - creating ..."
142  mkdir ${ARBMACROHOME}
143fi
144export ARBMACROHOME
145
146if [ -z ${ARBMACRO:-} ] ; then
147  ARBMACRO="$ARBHOME/lib/macros"
148fi
149if [ ! -d ${ARBMACRO} ] ; then
150  echo "Directory $ARBMACRO not found - creating ..."
151  mkdir ${ARBMACRO}
152fi
153export ARBMACRO
154
155# set default command-tool used by ARB
156ARB_XTERM=${ARB_XTERM:-xterm -sl 1000 -sb -geometry 120x50}
157export ARB_XTERM
158ARB_XCMD=${ARB_XCMD:-$ARB_XTERM -e}
159export ARB_XCMD
160
161# save LD_LIBRARY_PATH
162ARB_LIBRARY_PATH="${LD_LIBRARY_PATH}"
163export ARB_LIBRARY_PATH
164
165case "${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 "$@"
198esac
199
Note: See TracBrowser for help on using the repository browser.