-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactivate
64 lines (55 loc) · 2.63 KB
/
activate
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
#!/bin/bash
# Define the root so that everybody knows how to access files in the cluster-utils package
# To avoid problems with shells other than bash (e.g. zsh, mac's default from now on),
# in install we define the root using $0 and we pass it to this script when we source it.
# Note that we do this because $0 does not contain the path of the file when sourcing
export CLUSTER_UTILS_ROOT=${CLUSTER_UTILS_ROOT:-$(dirname $(realpath ${BASH_SOURCE}))}
# It is EXTREMELY IMPORTANT that we define the following alias,
# since it will prevent accidental removal of all the files inside a mount.
# Without this protection, if one does "rm -r mounts/" and "mounts" contains
# a mounted cluster, it would be catastrophic, as it would remove all the
# contents inside a cluster
# Note that we implement the extra protection of removing write permissions
# from the directory where all the mounts are, which will ask you if
# you are sure to continue your recursive search (check cli/subcommands/mount).
# However, we are only going to do this if the --one-file-system is accepted by
# rm. (accepted by gnu core-utils rm, not necessarily the version that a Mac user has)
_testfile="${CLUSTER_UTILS_ROOT}/.test"
touch "${_testfile}"
if rm --one-file-system "${_testfile}" 2>/dev/null; then
alias rm="rm --one-file-system"
# We also define a function that does exactly the same because
# aliases are not transmitted to child processes, but exported functions do :)
# Note: we keep the alias because it's the only way of making it work with a
# sudo call (see below)
function rm(){
command rm --one-file-system "$@"
}
export -f rm
# Then we do this little trick so that sudo also sees the alias
# (check out https://askubuntu.com/a/22043)
alias sudo="sudo "
else
rm ${_testfile}
fi
# Source all the scripts so that they can be used. If we are in the main computer, we are going
# to use the "generic" folder. If we are in a host, only the relevant scripts are set, therefore
# there's only one level and we use ".".
set -a
for file in "${CLUSTER_UTILS_ROOT}"/scripts/{generic,.}/commands/*.sh; do
if [ -f "${file}" ]; then
source "${file}"
fi
done
set +a
# Add the bin folder to the path
export PATH="$(_clupath bin):$PATH"
# Provide tab completion for the command line interface (clu)
_clupycomplete
# Define also the place where the user scripts are expected to be
# (can be overwritten)
export CLUSTER_UTILS_USERSCRIPTS=$(_clupath user-scripts)
# Define the name of the host where we are running cluster-utils
export CLUSTER_UTILS_HOST=$(_clugethost)
# Define the place where, by default, cluster-utils will mount clusters
export CLUSTER_UTILS_MOUNTS=$(_clupath mounts)