lofarinit.sh.in 5.04 KB
Newer Older
Ger van Diepen's avatar
Ger van Diepen committed
1 2 3 4 5 6
#!/bin/echo Usage: .
#-----------------------------------------------------------------------------
# lofarinit.sh: Define the LOFAR environment for Bourne-like shells
#-----------------------------------------------------------------------------
#
# Copyright (C) 2005
Ger van Diepen's avatar
Ger van Diepen committed
7 8
# ASTRON (Netherlands Institute for Radio Astronomy)
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
Ger van Diepen's avatar
Ger van Diepen committed
9
#
Ger van Diepen's avatar
Ger van Diepen committed
10 11 12 13
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
Ger van Diepen's avatar
Ger van Diepen committed
14 15
# (at your option) any later version.
#
Ger van Diepen's avatar
Ger van Diepen committed
16
# The LOFAR software suite is distributed in the hope that it will be useful,
Ger van Diepen's avatar
Ger van Diepen committed
17 18 19 20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
Ger van Diepen's avatar
Ger van Diepen committed
21 22
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
Ger van Diepen's avatar
Ger van Diepen committed
23 24 25
#
# $Id$

Ger van Diepen's avatar
Ger van Diepen committed
26 27 28
# Define root here.
# This is a placeholder, so do NOT change the line.
# The actual value is filled in by make install (see Makefile.am).
29
lfr_root=@prefix@
Ger van Diepen's avatar
Ger van Diepen committed
30 31
lfr_libdir=@libdir@

32 33 34 35 36
# CMake does not define libdir, so we need to do things differently
if test "$lfr_libdir" = ""; then
  lfr_libdir=@CMAKE_INSTALL_PREFIX@/@LOFAR_LIBDIR@
fi

Ger van Diepen's avatar
Ger van Diepen committed
37 38
# Use only the basename of the the lib
lfr_libdir=`basename $lfr_libdir`
Ger van Diepen's avatar
Ger van Diepen committed
39

40 41 42
# Get directory for Python modules relative to install prefix.
lfr_pylibdir=@PYTHON_INSTALL_DIR@
lfr_pylibdir=${lfr_pylibdir#@CMAKE_INSTALL_PREFIX@/}
43

Ger van Diepen's avatar
Ger van Diepen committed
44 45

# First strip the current LOFARROOT from PATH, LD_LIBRARY_PATH, and PYTHONPATH.
Ger van Diepen's avatar
Ger van Diepen committed
46
# Take care that a possible . is preceeded by a backslash (for the later sed).
Ger van Diepen's avatar
Ger van Diepen committed
47
if [ "$LOFARROOT" != "" ]; then
Ger van Diepen's avatar
Ger van Diepen committed
48
    lfr_path=`echo $LOFARROOT | sed -e 's/\./\\\./g'`
Ger van Diepen's avatar
Ger van Diepen committed
49
    for lfr_bin in bin sbin
Ger van Diepen's avatar
Ger van Diepen committed
50
    do
Ger van Diepen's avatar
Ger van Diepen committed
51
      lfr_bin="$lfr_path/$lfr_bin"
Ger van Diepen's avatar
Ger van Diepen committed
52 53 54
      PATH=`echo $PATH | sed -e "s%:$lfr_bin:%:%g" -e "s%^$lfr_bin:%%"  -e "s%:$lfr_bin$%%" -e "s%^$lfr_bin$%%"`
      export PATH
    done
Ger van Diepen's avatar
Ger van Diepen committed
55
    lfr_lib="$lfr_path/$lfr_libdir"
Ger van Diepen's avatar
Ger van Diepen committed
56
    LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | sed -e "s%:$lfr_lib:%:%g" -e "s%^$lfr_lib:%%"  -e "s%:$lfr_lib$%%" -e "s%^$lfr_lib$%%"`
Ger van Diepen's avatar
Ger van Diepen committed
57
    export LD_LIBRARY_PATH
58 59 60 61 62
    if [ "$lfr_pylibdir" != "" ]; then
      lfr_pyt="$lfr_path/$lfr_pylibdir"
      PYTHONPATH=`echo $PYTHONPATH | sed -e "s%:$lfr_pyt:%:%g" -e "s%^$lfr_pyt:%%"  -e "s%:$lfr_pyt$%%" -e "s%^$lfr_pyt$%%"`
      export PYTHONPATH
    fi
Ger van Diepen's avatar
Ger van Diepen committed
63 64
fi

Ger van Diepen's avatar
Ger van Diepen committed
65 66
# Now define the new LOFARROOT (if possible)
# Do it only if the bin directory exists.
Ger van Diepen's avatar
Ger van Diepen committed
67
lfr_nroot=`cd $lfr_root > /dev/null; pwd`      # make path absolute
68 69
if [ "$lfr_nroot" = "" -o ! -d $lfr_nroot ]; then
    echo "LOFAR root directory $lfr_nroot does not exist; keeping old LOFARROOT $LOFARROOT"
Ger van Diepen's avatar
Ger van Diepen committed
70
else
Ger van Diepen's avatar
Ger van Diepen committed
71
    LOFARROOT=$lfr_nroot
Ger van Diepen's avatar
Ger van Diepen committed
72
    export LOFARROOT
Ger van Diepen's avatar
Ger van Diepen committed
73

Ger van Diepen's avatar
Ger van Diepen committed
74
    # Also strip root from the current paths (in case it is contained).
Ger van Diepen's avatar
Ger van Diepen committed
75
    lfr_path=`echo $LOFARROOT | sed -e 's/\./\\\./g'`
Ger van Diepen's avatar
Ger van Diepen committed
76
    for lfr_bin in bin sbin
Ger van Diepen's avatar
Ger van Diepen committed
77
    do
Ger van Diepen's avatar
Ger van Diepen committed
78
      lfr_bin="$lfr_path/$lfr_bin"
Ger van Diepen's avatar
Ger van Diepen committed
79 80 81
      PATH=`echo $PATH | sed -e "s%:$lfr_bin:%:%g" -e "s%^$lfr_bin:%%"  -e "s%:$lfr_bin$%%" -e "s%^$lfr_bin$%%"`
      export PATH
    done
Ger van Diepen's avatar
Ger van Diepen committed
82
    lfr_lib="$lfr_path/$lfr_libdir"
Ger van Diepen's avatar
Ger van Diepen committed
83
    LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | sed -e "s%:$lfr_lib:%:%g" -e "s%^$lfr_lib:%%"  -e "s%:$lfr_lib$%%" -e "s%^$lfr_lib$%%"`
Ger van Diepen's avatar
Ger van Diepen committed
84
    export LD_LIBRARY_PATH
85 86 87 88 89
    if [ "$lfr_pylibdir" != "" ]; then
      lfr_pyt="$lfr_path/$lfr_pylibdir"
      PYTHONPATH=`echo $PYTHONPATH | sed -e "s%:$lfr_pyt:%:%g" -e "s%^$lfr_pyt:%%"  -e "s%:$lfr_pyt$%%" -e "s%^$lfr_pyt$%%"`
      export PYTHONPATH
    fi
Ger van Diepen's avatar
Ger van Diepen committed
90
fi
Ger van Diepen's avatar
Ger van Diepen committed
91

92 93 94
# Add to the paths
if [ "$LOFARROOT" = "" -o ! -d $LOFARROOT ]; then
    echo "LOFARROOT is empty or does not point to a directory."
Ger van Diepen's avatar
Ger van Diepen committed
95
else
Ger van Diepen's avatar
Ger van Diepen committed
96 97
    # Add the path to the standard paths.
    if [ "$PATH" = "" ]; then
98
        PATH=$LOFARROOT/sbin:$LOFARROOT/bin
Ger van Diepen's avatar
Ger van Diepen committed
99
    else
100
        PATH=$LOFARROOT/sbin:$LOFARROOT/bin:$PATH
Ger van Diepen's avatar
Ger van Diepen committed
101 102 103
    fi
    export PATH
    if [ "$LD_LIBRARY_PATH" = "" ]; then
Ger van Diepen's avatar
Ger van Diepen committed
104
        LD_LIBRARY_PATH=$LOFARROOT/$lfr_libdir
Ger van Diepen's avatar
Ger van Diepen committed
105
    else
Ger van Diepen's avatar
Ger van Diepen committed
106
        LD_LIBRARY_PATH=$LOFARROOT/$lfr_libdir:$LD_LIBRARY_PATH
Ger van Diepen's avatar
Ger van Diepen committed
107 108
    fi
    export LD_LIBRARY_PATH
109 110 111
    if [ "$lfr_pylibdir" != "" ]; then
      lfr_pyt="$LOFARROOT/$lfr_pylibdir"
      if [ "$PYTHONPATH" = "" ]; then
Ger van Diepen's avatar
Ger van Diepen committed
112
        PYTHONPATH=$lfr_pyt
113
      else
Ger van Diepen's avatar
Ger van Diepen committed
114
        PYTHONPATH=$lfr_pyt:$PYTHONPATH
115 116
      fi
      export PYTHONPATH
Ger van Diepen's avatar
Ger van Diepen committed
117
    fi
Ger van Diepen's avatar
Ger van Diepen committed
118
fi
Arthur Coolen's avatar
Arthur Coolen committed
119

Ger van Diepen's avatar
Ger van Diepen committed
120 121
# Now define the new LOFARDATAROOT (if possible).
# First try as data directory of the LOFAR install directory.
Ger van Diepen's avatar
Ger van Diepen committed
122 123 124
lfr_path=`echo $LOFARROOT | sed -e 's%/installed.*%%'`
if [ "$lfr_path" != ""  -a  -d $lfr_path/data ]; then
    LOFARDATAROOT=$lfr_path/data
Arthur Coolen's avatar
Arthur Coolen committed
125
    export LOFARDATAROOT
Ger van Diepen's avatar
Ger van Diepen committed
126 127
else
    # Try it as the LOFARDATA directory (part of the source tree).
Ger van Diepen's avatar
Ger van Diepen committed
128 129 130
    lfr_path=`echo $LOFARROOT | sed -e 's%/LOFAR/.*%/LOFAR%'`
    if [ "$lfr_path" != ""  -a  -d ${lfr_path}DATA ]; then
        LOFARDATAROOT=${lfr_path}DATA
Ger van Diepen's avatar
Ger van Diepen committed
131
        export LOFARDATAROOT
Ger van Diepen's avatar
Ger van Diepen committed
132 133 134
    else
        LOFARDATAROOT=/opt/lofar/data
        export LOFARDATAROOT
Ger van Diepen's avatar
Ger van Diepen committed
135
    fi
Ger van Diepen's avatar
Ger van Diepen committed
136
fi
Ger van Diepen's avatar
Ger van Diepen committed
137 138

# Clean up
139
unset lfr_root lfr_nroot lfr_bin lfr_libdir lfr_lib lfr_pylibdir lfr_pyt lfr_path