Merge branch 'develop'
[archipelago] / xseg / envsetup
1 #!/bin/bash
2
3 # Copyright 2012 GRNET S.A. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or
6 # without modification, are permitted provided that the following
7 # conditions are met:
8 #
9 #   1. Redistributions of source code must retain the above
10 #      copyright notice, this list of conditions and the following
11 #      disclaimer.
12 #   2. Redistributions in binary form must reproduce the above
13 #      copyright notice, this list of conditions and the following
14 #      disclaimer in the documentation and/or other materials
15 #      provided with the distribution.
16 #
17 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29 #
30 # The views and conclusions contained in the software and
31 # documentation are those of the authors and should not be
32 # interpreted as representing official policies, either expressed
33 # or implied, of GRNET S.A.
34 #
35
36
37 set -e
38
39 dirname=$(dirname -- "${0}")
40 if cd "${dirname}"; then
41         XSEG_HOME=$(pwd -P)
42         cd - > /dev/null
43 fi
44
45 if [ -z "$XSEG_HOME" ]; then
46         echo 'Cannot set $XSEG_HOME'
47         exit 1
48 fi
49
50 PEERS=${XSEG_HOME}/peers
51 TOOLS=${XSEG_HOME}/tools
52 LIBS=${XSEG_HOME}/lib/user
53
54 if [ ! -d "${LIBS}" ] || [ ! -d "${PEERS}" ]; then
55         echo "Cannot find basic xseg layout"
56         exit 1
57 fi
58
59 if ! echo ${PATH} | grep -E -e '(^|:)'"${PEERS}"'(:|$)' > /dev/null 2>&1; then
60         PATH=${PATH}:${PEERS}
61 fi
62
63 if ! echo ${PATH} | grep -E -e '(^|:)'"${TOOLS}"'(:|$)' > /dev/null 2>&1; then
64         PATH=${PATH}:${TOOLS}
65 fi
66
67 if ! echo ${LD_LIBRARY_PATH} | grep -E -e '(^|:)'"${LIBS}"'(:|$)' > /dev/null 2>&1; then
68         LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${LIBS}
69 fi
70
71 export PATH LD_LIBRARY_PATH XSEG_HOME
72 source ${XSEG_HOME}/config.env
73 export XSEG_DOMAIN_DIRS XSEG_DIRS
74
75 if [ "$1" = "show" ]; then
76         echo "export XSEG_HOME="${XSEG_HOME}
77         echo "export XSEG_DIRS="${XSEG_DIRS}
78         echo "export XSEG_DOMAIN_DIRS="${XSEG_DOMAIN_DIRS}
79         echo "export PATH="${PATH}
80         echo "export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}
81 else
82         if [ -z "${NONINTERACTIVE}" ]; then
83                 [ -z "$SHELL" ] && SHELL=/bin/bash
84
85                 selfname=$(basename -- "${0}")
86                 [ "$selfname" = "envsetup" ] && exec "$SHELL"
87         fi
88 fi