forked from FESOM/fesom2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.sh
executable file
·64 lines (56 loc) · 1.76 KB
/
env.sh
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
#!/usr/bin/env bash
# - - -
# # synopsis
# determine which environment directory is to be used for the current host
# # usage
# *source* to silently source the environment for this host system
# *execute* to print the environment directory for this host system
# - - -
# see if we are being sourced or executed
# as we use bash to execute (see shebang), BASH_SOURCE is set when executing
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
BEING_EXECUTED=true
else
BEING_EXECUTED=false
fi
# if an arg is given, use it as hostname
if [ -z "$1" ]; then
# no argument given
LOGINHOST="$(hostname -f)"
else
LOGINHOST=$1
fi
if [[ $LOGINHOST =~ ^m[A-Za-z0-9]+\.hpc\.dkrz\.de$ ]]; then
STRATEGY="mistral.dkrz.de"
elif [[ $LOGINHOST =~ ^ollie[0-9]$ ]] || [[ $LOGINHOST =~ ^prod-[0-9]{4}$ ]]; then
STRATEGY="ollie"
elif [[ $LOGINHOST =~ ^h[A-Za-z0-9]+\.hsn\.hlrn\.de$ ]]; then
STRATEGY="hlogin.hlrn.de"
elif [[ $LOGINHOST =~ ^b[A-Za-z0-9]+\.hsn\.hlrn\.de$ ]]; then
STRATEGY="blogin.hlrn.de"
elif [[ $LOGINHOST =~ \.hww\.de$ ]] || [[ $LOGINHOST =~ ^nid[0-9]{5}$ ]]; then
STRATEGY="hazelhen.hww.de"
elif [[ $LOGINHOST =~ \.jureca$ ]]; then
STRATEGY="jureca"
elif [[ $LOGINHOST =~ ^juwels[0-9]+\.fz\-juelich\.de$ ]]; then
STRATEGY="juwels"
else
echo "can not determine environment for host: "$LOGINHOST
[ $BEING_EXECUTED = true ] && exit 1
return # if we are being sourced, return from this script here
fi
if [ -n "$BASH_VERSION" ]; then
# assume bash
SOURCE="${BASH_SOURCE[0]}"
elif [ -n "$ZSH_VERSION" ]; then
# assume zsh
SOURCE=${(%):-%N}
fi
DIR="$( cd "$( dirname "${SOURCE}" )" && pwd )"
if [ $BEING_EXECUTED = true ]; then
# file is being executed
echo $DIR/env/$STRATEGY
else
# file is being sourced
source $DIR/env/$STRATEGY/shell
fi