-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenable_local
More file actions
executable file
·70 lines (50 loc) · 2.7 KB
/
enable_local
File metadata and controls
executable file
·70 lines (50 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
## N.B.!!! This script load/enable the environment variable only for O2Physics and it's dependencies !!!
## then it adds to PATH the location of the example analysis task found within this repository!
[[ "${BASH_SOURCE[0]}" -ef "${0}" ]] && { echo -e "This script should be sourced! use:\nsource $(realpath ${0} optional_tag_argument)"; exit 1; }
SCRIPT_PATH=$(realpath -e -P "${BASH_SOURCE[0]}")
SCRIPT_DIR=$(cd -P $(dirname -- "${SCRIPT_PATH}") >/dev/null 2>&1 && pwd)
TAG_ARG="${1}"
shift
### DEFAULTS ###
export LOCAL_TAG="latest-o2physics-o2"
# Steering of the environment:
# O2OPENACCESS_SW_TAG_LOCAL : set the string name for local installation
export O2OPENACCESS_SW_TAG_LOCAL=${O2OPENACCESS_SW_TAG_LOCAL:-${LOCAL_TAG}}
# If argument is passed, overwrite any defaults or env variables
[[ -n "${TAG_ARG}" ]] && O2OPENACCESS_SW_TAG_LOCAL="${TAG_ARG}"
#####################################################
## HELPERS
SourceIfValid () { [[ -f "${1}" ]] && source "${1}"; }
# Check if 2nd arg is found in the list(terms delimited by ":") in the 1st arg
ITEM_IN_PATH () {
local LIST_STR ITEM path_arr n
[[ -z "${1}" ]] && return 1;
[[ -z "${2}" ]] && return 1;
LIST_STR="${1}"
ITEM="${2}"
IFS=':' read -ra path_arr <<< "${LIST_STR}"
for (( n=0; n < ${#path_arr[*]}; n++)); do [[ "$(realpath -q ${ITEM})" == "$(realpath -q ${path_arr[n]})" ]] && return 0; done
return 1;
}
# Insert/Add to $PATH if and only if not already present
__PATH_INS () { [[ -z "${1}" ]] && return 1; ITEM_IN_PATH "${PATH}" "${1}" && return 0; export PATH="${1}${PATH:+:}${PATH}"; }
__PATH_ADD () { [[ -z "${1}" ]] && return 1; ITEM_IN_PATH "${PATH}" "${1}" && return 0; export PATH="${PATH}${PATH:+:}${1}"; }
######################################################################
## if O2PHYSICS present (environemnt already enabled then just add path and return(we are sourced))
[[ -n "${O2PHYSICS_ROOT}" ]] && { __PATH_INS "${SCRIPT_DIR}/bin" ; return 0 ; }
# apply local customizations
SourceIfValid ./.aliopendata_cfg # apply local directory customization
# construct location for etc/profile.d/init.sh
O2PHYS_TAG="${O2OPENACCESS_SW_TAG_LOCAL}"
WORK_DIR="${ALIBUILD_WORK_DIR}"
DISABLE_GPU=1
ALIBUILD_ARCH_PREFIX="$(aliBuild architecture)"
O2PHYS_DIR="${WORK_DIR}/${ALIBUILD_ARCH_PREFIX}/O2Physics/${O2PHYS_TAG}"
[[ ! -d "${O2PHYS_DIR}" ]] && { echo "O2PHYS_DIR ${O2PHYS_DIR} not found!!"; return 1; }
export WORK_DIR DISABLE_GPU O2PHYS_DIR
O2PHYSICS_INIT="${O2PHYS_DIR}/etc/profile.d/init.sh"
[[ ! -f "${O2PHYSICS_INIT}" ]] && { echo "${O2PHYSICS_INIT} not available"; return 1; }
source "${O2PHYSICS_INIT}" &> /dev/null # if we load from cvmfs ignore any errors
# add to PATH built executables
__PATH_INS "${SCRIPT_DIR}/bin"