#!/bin/bash # 1. FIND THIS SCRIPT PATH #Next lines just finds the path of the file #Works for all versions,including #when called via multple depth soft link, #when script called by command "source" aka . (dot) operator. #when arg $0 is modified from caller. #"./script" "/full/path/to/script" "/some/path/../../another/path/script" "./some/folder/script" #SCRIPT_PATH is given in full path, no matter how it is called. #Just make sure you locate this at start of the script. SCRIPT_PATH="${BASH_SOURCE[0]}"; if([ -h "${SCRIPT_PATH}" ]) then while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done fi pushd . > /dev/null cd `dirname ${SCRIPT_PATH}` > /dev/null SCRIPT_PATH=`pwd`; popd > /dev/null echo "SCRIPT_PATH=$SCRIPT_PATH" #if [ -n "$RCDB_ENVIRONMENT_AUTOSET" ] #then # return 0 #fi # 2. SET PYTHON VERSION TO 2.7 (The path is for CUE machines with prehistoric RHEL) export PATH=/apps/python/bin:$PATH export LD_LIBRARY_PATH=/apps/python/lib:$LD_LIBRARY_PATH # 3. DEAL WITH RCDB_HOME export RCDB_HOME=/gluondaqfs/hdops/CDAQ/daq_dev_v0.31/daq/rcdb/github_rcdb if [ -z "$RCDB_HOME" ]; then export RCDB_HOME=$SCRIPT_PATH/github_rcdb export PYTHONPATH="$RCDB_HOME/python":$PYTHONPATH fi export PYTHONPATH="$RCDB_HOME/python":$PYTHONPATH # 4. DEAL WITH CONNECTION TO DATABASE if [ -f ~/.rcdb ]; then source ~/.rcdb fi if [ -z "$RCDB_CONNECTION" ]; then # Ok, no RCDB connection string is set. Then we will automatically use sqlite database # But... does SQLite database exists? RCDB_SQLITE_PATH=$SCRIPT_PATH/../../work/rcdb.sqlite.db if [ ! -f $RCDB_SQLITE_PATH ]; then #Copy template database there cp $RCDB_HOME/sql/runconf.sqlite.db $RCDB_SQLITE_PATH fi #Set connection string export RCDB_CONNECTION=sqlite:///$RCDB_SQLITE_PATH fi # 5. Add this dir to PATH export PATH=$SCRIPT_PATH:$PATH # 6. SET the we were here export RCDB_ENVIRONMENT_AUTOSET="TRUE" echo "RCDB_CONNECTION=$RCDB_CONNECTION" echo "RCDB_HOME=$RCDB_HOME" echo "PYTHONPATH=$PYTHONPATH"