forked from NOAA-EMC/hpc-stack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_modules.sh
executable file
·210 lines (180 loc) · 7.88 KB
/
setup_modules.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
# The purpose of this script is to define the compiler and MPI library to be
# used and to set up and deploy the associated modules. This needs to be each
# time a different compiler/MPI build is initiated.
#
# Arguments:
# compiler name/version and MPI Library/version: these are the names of the
# modules that this script is responsible for creating and that build_stack.sh
# will use to build the software stack.
#
# sample usage
# setup_modules.sh -p "prefix" -c "config.sh"
# setup_modules.sh -h
#
set -eu
# root directory for the repository
HPC_STACK_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
HPC_STACK_VERSION="$(head -n 1 ${HPC_STACK_ROOT}/VERSION)"
#===============================================================================
usage() {
set +x
echo
echo "Usage: $0 -p <prefix> | -c <config> | -h"
echo
echo " -p installation prefix <prefix> DEFAULT: $HOME/opt"
echo " -c use configuration file <config> DEFAULT: config/config_custom.sh"
echo " -h display this message and quit"
echo
exit 1
}
#===============================================================================
# Defaults:
PREFIX="$HOME/opt"
config="${HPC_STACK_ROOT}/config/config_custom.sh"
while getopts ":p:c:h" opt; do
case $opt in
p)
PREFIX=$OPTARG
;;
c)
config=$OPTARG
;;
h|\?|:)
usage
;;
esac
done
# ==============================================================================
# Source helper functions
source "${HPC_STACK_ROOT}/stack_helpers.sh"
#===============================================================================
# Source the config file
if [[ -e $config ]]; then
source $config
else
echo "ERROR: CONFIG FILE $config DOES NOT EXIST, ABORT!"
exit 1
fi
#===============================================================================
# Echo compiler and mpi information
compilermpi_info
compilerName=$(echo $HPC_COMPILER | cut -d/ -f1)
compilerVersion=$(echo $HPC_COMPILER | cut -d/ -f2)
mpiName=$(echo $HPC_MPI | cut -d/ -f1)
mpiVersion=$(echo $HPC_MPI | cut -d/ -f2)
pythonName=$(echo $HPC_PYTHON | cut -d/ -f1)
pythonVersion=$(echo $HPC_PYTHON | cut -d/ -f2)
#===============================================================================
# install with root permissions?
[[ $USE_SUDO =~ [yYtT] ]] && SUDO="sudo" || SUDO=""
#===============================================================================
# Deploy directory structure for modulefiles
$SUDO mkdir -p $PREFIX/modulefiles/python
$SUDO mkdir -p $PREFIX/modulefiles/core
$SUDO mkdir -p $PREFIX/modulefiles/compiler/$compilerName/$compilerVersion
$SUDO mkdir -p $PREFIX/modulefiles/mpi/$compilerName/$compilerVersion/$mpiName/$mpiVersion
$SUDO mkdir -p $PREFIX/modulefiles/core/hpc-$pythonName
$SUDO mkdir -p $PREFIX/modulefiles/core/hpc-$compilerName
$SUDO mkdir -p $PREFIX/modulefiles/compiler/$compilerName/$compilerVersion/hpc-$mpiName
$SUDO mkdir -p $PREFIX/modulefiles/stack/hpc
#===============================================================================
# Are the hpc-$pythonName.lua, hpc-$compilerName.lua, hpc-$mpiName.lua or hpc/stack.lua modulefiles present at $PREFIX?
# If yes, query the user to ask to over-write
if [[ -f $PREFIX/modulefiles/core/hpc-$pythonName/$pythonVersion.lua && ! $OVERWRITE =~ [yYtT] ]]; then
echo "WARNING: $PREFIX/modulefiles/core/hpc-$pythonName/$pythonVersion.lua exists!"
echo "Do you wish to over-write? [yes|YES|no|NO]: (DEFAULT: NO) "
read response
else
response="YES"
fi
[[ $response =~ [yYtT] ]] && overwritePythonModulefile=YES
unset response
if [[ -f $PREFIX/modulefiles/core/hpc-$compilerName/$compilerVersion.lua && ! $OVERWRITE =~ [yYtT] ]]; then
echo "WARNING: $PREFIX/modulefiles/core/hpc-$compilerName/$compilerVersion.lua exists!"
echo "Do you wish to over-write? [yes|YES|no|NO]: (DEFAULT: NO) "
read response
else
response="YES"
fi
[[ $response =~ [yYtT] ]] && overwriteCompilerModulefile=YES
unset response
if [[ -f $PREFIX/modulefiles/compiler/$compilerName/$compilerVersion/hpc-$mpiName/$mpiVersion.lua && ! $OVERWRITE =~ [yYtT] ]]; then
echo "WARNING: $PREFIX/modulefiles/compiler/$compilerName/$compilerVersion/hpc-$mpiName/$mpiVersion.lua exists!"
echo "Do you wish to over-write? [yes|YES|no|NO]: (DEFAULT: NO) "
read response
else
response="YES"
fi
[[ $response =~ [yYtT] ]] && overwriteMPIModulefile=YES
unset response
if [[ -f $PREFIX/modulefiles/stack/hpc/$HPC_STACK_VERSION.lua && ! $OVERWRITE =~ [yYtT] ]]; then
echo "WARNING: $PREFIX/modulefiles/stack/hpc/$HPC_STACK_VERSION.lua exists!"
echo "Do you wish to over-write? [yes|YES|no|NO]: (DEFAULT: NO) "
read response
else
response="YES"
fi
[[ $response =~ [yYtT] ]] && overwriteStackModulefile=YES
unset response
#===============================================================================
# Query the user if using native python, compiler and MPI, if overwriting (or writing for first time)
if [[ ${overwritePythonModulefile:-} =~ [yYtT] ]]; then
$SUDO cp $HPC_STACK_ROOT/modulefiles/core/hpc-$pythonName/hpc-$pythonName.lua \
$PREFIX/modulefiles/core/hpc-$pythonName/$pythonVersion.lua
echo "Are you using native python '$pythonName' [yes|YES|no|NO]: (DEFAULT: NO) "
read response
if [[ $response =~ [yYtT] ]]; then
echo -e "==========================\n USING NATIVE PYTHON"
cd $PREFIX/modulefiles/core/hpc-$pythonName
$SUDO sed -i -e '/load(python)/d' $pythonVersion.lua
$SUDO sed -i -e '/prereq(python)/d' $pythonVersion.lua
[[ -f $pythonVersion.lua-e ]] && $SUDO rm -f "$pythonVersion.lua-e" # Stupid macOS does not understand -i, and creates a backup with -e (-e is the next sed option)
echo
fi
unset response
fi
if [[ ${overwriteCompilerModulefile:-} =~ [yYtT] ]]; then
$SUDO cp $HPC_STACK_ROOT/modulefiles/core/hpc-$compilerName/hpc-$compilerName.lua \
$PREFIX/modulefiles/core/hpc-$compilerName/$compilerVersion.lua
echo "Are you using native compiler '$compilerName' [yes|YES|no|NO]: (DEFAULT: NO) "
read response
if [[ $response =~ [yYtT] ]]; then
echo -e "==========================\n USING NATIVE COMPILER"
cd $PREFIX/modulefiles/core/hpc-$compilerName
$SUDO sed -i -e '/load(compiler)/d' $compilerVersion.lua
$SUDO sed -i -e '/prereq(compiler)/d' $compilerVersion.lua
[[ -f $compilerVersion.lua-e ]] && $SUDO rm -f "$compilerVersion.lua-e" # Stupid macOS does not understand -i, and creates a backup with -e (-e is the next sed option)
echo
fi
unset response
fi
if [[ ${overwriteMPIModulefile:-} =~ [yYtT] ]]; then
$SUDO cp $HPC_STACK_ROOT/modulefiles/compiler/compilerName/compilerVersion/hpc-$mpiName/hpc-$mpiName.lua \
$PREFIX/modulefiles/compiler/$compilerName/$compilerVersion/hpc-$mpiName/$mpiVersion.lua
echo "Are you using native MPI '$mpiName' [yes|YES|no|NO]: (DEFAULT: NO) "
read response
if [[ $response =~ [yYtT] ]]; then
echo -e "===========================\n USING NATIVE MPI"
cd $PREFIX/modulefiles/compiler/$compilerName/$compilerVersion/hpc-$mpiName
$SUDO sed -i -e '/load(mpi)/d' $mpiVersion.lua
$SUDO sed -i -e '/prereq(mpi)/d' $mpiVersion.lua
[[ -f $mpiVersion.lua-e ]] && $SUDO rm -f "$mpiVersion.lua-e"
echo
fi
unset response
fi
if [[ ${overwriteStackModulefile:-} =~ [yYtT] ]]; then
$SUDO cp $HPC_STACK_ROOT/modulefiles/stack/hpc/hpc.lua \
$PREFIX/modulefiles/stack/hpc/$HPC_STACK_VERSION.lua
# Replace #PREFIX# from template with $PREFIX,
# sed does not like delimiter (/) to be a part of replacement string, do magic!
cd $PREFIX/modulefiles/stack/hpc
repl=$(echo ${PREFIX} | sed -e "s#/#\\\/#g")
$SUDO sed -i -e "s/#HPC_OPT#/${repl}/g" $PREFIX/modulefiles/stack/hpc/$HPC_STACK_VERSION.lua
[[ -f $HPC_STACK_VERSION.lua-e ]] && $SUDO rm -f "$HPC_STACK_VERSION.lua-e"
fi
#===============================================================================
echo "setup_modules.sh: SUCCESS!"
echo "To proceed run: ./build_stack.sh -p $PREFIX -c $config -y <stack.yaml>"
exit 0