forked from PCMDI/pcmdi_metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_metrics.bash
executable file
·449 lines (392 loc) · 17.1 KB
/
install_metrics.bash
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#!/usr/bin/env bash
## SYSTEM SPECIFIC OPTIONS, EDIT THESE TO MATCH YOUR SYSTEM
## Directory where to install UVCDAT and the METRICS Packages
install_prefix="PCMDI_METRICS"
## Temporary build directory
build_directory="${install_prefix}/tmp"
## Speed up your build by increasing the following to match your number of processors
num_cpus=4
#### BUILD OPTIONS #####
## Do we want to build with graphics capabilities
build_graphics=false
## Do we want to build with CMOR
build_cmor=false
## Do we build UV-CDAT with parallel capabilities (MPI)
build_parallel=false
## Speed up your build by increasing the following to match your number of processors
num_cpus=4
## Do we keep or remove uvcdat_build diretory before building UV-CDAT
## Useful for case where multiple make necessary
## valid values: true false
keep_uvcdat_build_dir=false
### DO NOT EDIT AFTER THIS POINT !!!!! ###
# Prevent installer from hanging due to cdms2 logging
export UVCDAT_ANONYMOUS_LOG=False
setup_cmake() {
## Source funcs needed by installer
. ${metrics_build_directory}/installer_funcs.bash
echo -n "Checking for CMake >= ${cmake_min_version} "
check_version_with cmake "cmake --version | head -n1 | awk '{print \$3}' | awk -F . '{print \$1\".\"\$2\".\"\$3}'" ${cmake_min_version} ${cmake_max_version}
[ $? == 0 ] && (( ! force_install )) && echo " [OK]" && return 0
echo
echo "*******************************"
echo "Setting up CMake ${cmake_version}"
echo "*******************************"
echo
local default="Y"
((force_install)) && default="N"
local dosetup
if [ -x ${cmake_install_dir}/bin/cmake ]; then
echo "Detected an existing CMAKE installation..."
read -e -p "Do you want to continue with CMAKE installation and setup? $([ "$default" = "N" ] && echo "[y/N]" || echo "[Y/n]") " dosetup
[ -z ${dosetup} ] && dosetup=${default}
if [ "${dosetup}" != "Y" ] && [ "${dosetup}" != "y" ]; then
echo "Skipping CMAKE installation and setup - will assume CMAKE is setup properly"
return 0
fi
echo
fi
#make top level directory for cmake repo clone
mkdir -p ${cmake_build_directory%/*}
chmod a+rw ${cmake_build_directory%/*}
if [ ! -d "${cmake_build_directory}" ]; then
echo "Cloning CMake repository ${cmake_repo}..."
git clone ${cmake_repo} ${cmake_build_directory}
if [ ! -d ${cmake_build_directory}/.git ]; then
echo "Apparently was not able to fetch from cmake repo using git protocol (port 9418)... trying https protocol..."
git clone ${cmake_repo_https} ${cmake_build_directory}
if [ ! -d ${cmake_build_directory}/.git ]; then
echo "Apparently was not able to fetch from cmake repo using https protocol (port 2)... trying http protocol..."
git clone ${cmake_repo_http} ${cmake_build_directory}
if [ ! -d ${cmake_build_directory}/.git ]; then
echo "Could not fetch from cmake repo (with git/https/http protocol). Please check you are online and your firewall settings"
exit 1
fi
fi
fi
fi
(
unset LD_LIBRARY_PATH
unset CFLAGS
unset LDFLAGS
((DEBUG)) && printf "\n-----\n cd ${cmake_build_directory} \n-----\n"
cd ${cmake_build_directory} >& /dev/null
((DEBUG)) && printf "\n-----\n git checkout v${cmake_version} \n-----\n"
git checkout v${cmake_version}
[ $? != 0 ] && echo "ERROR: Could not checkout CMake @ v${cmake_version}" && checked_done 2
((DEBUG)) && printf "\n-----\n ./configure --parallel=${num_cpus} --prefix=${cmake_install_dir} \n-----\n"
./configure --parallel=${num_cpus} --prefix=${cmake_install_dir}
[ $? != 0 ] && echo "ERROR: Could not configure CMake successfully" && checked_done 3
((DEBUG)) && printf "\n-----\n make -j ${num_cpus} \n-----\n"
make -j ${num_cpus}
[ $? != 0 ] && echo "ERROR: Could not make CMake successfully" && checked_done 4
((DEBUG)) && printf "\n-----\n make install \n-----\n"
make install
[ $? != 0 ] && echo "ERROR: Could not install CMake successfully" && checked_done 5
)
echo "returning from build subshell with code: [$?]"
(( $? > 1 )) && echo "ERROR: Could not setup CMake successfully, aborting... " && checked_done 1
cmake_version=$(${cmake_install_dir}/bin/cmake --version | awk '{print $3}' | sed -e 's/\([^-]*\)-.*/\1/')
printf "\ninstalled CMake version = ${cmake_version}\n\n"
checked_done 0
}
#####
# CDAT = Python+CDMS
#####
setup_cdat() {
FC=gfortran
F77=gfortran
F90=gfortran
CC=gcc
CXX=g++
echo -n "Checking for *UV* CDAT (Python+CDMS) ${cdat_version} "
#-----------CDAT -> UVCDAT Migration------------------
#rewrite cdat_home to new uvcdat location
#-----------------------------------------------------
cdat_home=$(perl -pe 's/(?<!uv)cdat/uvcdat/' <<<${cdat_home})
CDAT_HOME=${cdat_home}
#-----------------------------------------------------
${cdat_home}/bin/python -c "import cdat_info; print cdat_info.Version"
local ret=$?
((ret == 0)) && (( ! force_install )) && echo " [OK]" && return 0
echo "No python in your install directory, trying your PATH"
python -c "import cdat_info; print cdat_info.Version"
if [ $? == 0 ]; then
echo "you have a valid cdat in your path"
cdat_home=`python -c "import sys; print sys.prefix"`
echo "It is located at:" ${cdat_home}
cat > ${install_prefix}/bin/setup_runtime.sh << EOF
. ${cdat_home}/bin/setup_runtime.sh
export PYTHONPATH=${install_prefix}/lib/python2.7/site-packages:\${PYTHONPATH}
export PATH=${PATH}:${install_prefix}/bin
EOF
return 0
fi
## Source funcs needed by installer
. ${metrics_build_directory}/installer_funcs.bash
echo
echo "*******************************"
echo "Setting up CDAT - (Python + CDMS)... ${cdat_version}"
echo "*******************************"
echo
local dosetup="N"
if [ -x ${cdat_home}/bin/python ]; then
echo "Detected an existing CDAT installation..."
read -e -p "Do you want to continue with CDAT installation and setup? [Y/N] " dosetup
if [ "${dosetup}" != "Y" ] && [ "${dosetup}" != "y" ]; then
echo "Skipping CDAT installation and setup - will assume CDAT is setup properly"
return 0
fi
echo
fi
mkdir -p ${uvcdat_build_directory}
[ $? != 0 ] && checked_done 1
pushd ${uvcdat_build_directory} >& /dev/null
local cdat_git_protocol="git://"
if [ ! -d ${uvcdat_build_directory}/uvcdat ]; then
echo "Fetching the cdat project from GIT Repo..."
((DEBUG)) && echo "${cdat_repo}"
git clone ${cdat_repo} uvcdat
if [ ! -d ${uvcdat_build_directory}/uvcdat/.git ]; then
cdat_git_protocol="https://"
echo "Apparently was not able to fetch from GIT repo using git protocol. (port 9418).. trying https protocol..."
((DEBUG)) && echo "${cdat_repo_https}"
git clone ${cdat_repo_https} uvcdat
if [ ! -d ${uvcdat_build_directory}/uvcdat/.git ]; then
cdat_git_protocol="http://"
echo "Was still not able to fetch from GIT repo this time using https protocol... (port 22) trying http protocol..."
((DEBUG)) && echo "${cdat_repo_http}"
git clone ${cdat_repo_http} uvcdat
[ ! -d ${uvcdat_build_directory}/uvcdat/.git ] && echo "Could not fetch from cdat's repo (with git, https nor http protocol)i please check your internet connection and firewall settings" && checked_done 1
fi
fi
fi
cd uvcdat >& /dev/null
git checkout ${cdat_version}
[ $? != 0 ] && echo " WARNING: Problem with checking out cdat revision [${cdat_version}] from repository :-("
#NOTE:
#cdms configuration with --enable-esg flag looks for pg_config in
#$postgress_install_dir/bin. This location is created and added
#to the executable PATH by the 'setup_postgress' function.
#if [ -n "${certificate}" ]; then
# pip_string="-DPIP_CERTIFICATE="${certificate}
# echo "Using user defined certificate path: ${certificate}"
#fi
local uvcdat_build_directory_build=${uvcdat_build_directory}/uvcdat_build
(
unset LD_LIBRARY_PATH
unset PYTHONPATH
unset CFLAGS
unset LDFLAGS
if [ ${keep_uvcdat_build_dir} = false ]; then
echo "removing UVCDAT build directory"
[ -d ${uvcdat_build_directory_build} ] && rm -rf ${uvcdat_build_directory_build}
else
echo "You said you wanted to keep uvcdat_build_dir"
fi
mkdir -p ${uvcdat_build_directory_build} >& /dev/null
pushd ${uvcdat_build_directory_build} >& /dev/null
#(zlib patch value has to be 3,5,7 - default is 3)
local zlib_value=$(pkg-config --modversion zlib | sed -n -e 's/\(.\)*/\1/p' | sed -n -e '/\(3|5|7\)/p') ; [[ ! ${zlib_value} ]] && zlib_value=3
if [ ${build_graphics} = false ]; then
echo "LEAN MODE will not build graphics"
uvcdat_mode="-DCDAT_BUILD_MODE=LEAN -DCDAT_BUILD_ESMF_ESMP=ON"
else
echo "Turning on graphics this will take sensibly longer to build"
uvcdat_mode="-DCDAT_BUILD_MODE=DEFAULT -DCDAT_BUILD_GUI=OFF -DCDAT_BUILD_ESMF_ESMP=ON"
fi
if [ ${build_cmor} = false ]; then
uvcdat_cmor=""
else
echo "Turning on CMOR"
uvcdat_cmor="-DCDAT_BUILD_CMOR=ON"
fi
if [ ${build_parallel} = false ]; then
uvcdat_parallel=""
else
echo "Turning on build for parallel features, wil ltakes sensibly longer"
uvcdat_parallel="-DCDAT_BUILD_PARALLEL=ON"
fi
cmake_cmd="cmake ${uvcdat_build_directory}/uvcdat ${uvcdat_mode} ${uvcdat_cmor} ${uvcdat_parallel} -DCMAKE_INSTALL_PREFIX=${cdat_home} -DZLIB_PATCH_SRC=${zlib_value} -DGIT_PROTOCOL=${cdat_git_protocol} "
echo "CMAKE ARGS: "${cmake_cmd}
echo "PATH:"${PATH}
echo "PWD:"`pwd`
${cmake_cmd}
[ $? != 0 ] && echo " ERROR: Could not configure (cmake) cdat code (1)" && popd && checked_done 1
${cmake_cmd}
[ $? != 0 ] && echo " ERROR: Could not configure (cmake) cdat code (2)" && popd && checked_done 1
echo "CMAKE ARGS"${cmake_args}
make -j ${num_cpus}
[ $? != 0 ] && echo " ERROR: Could not compile (make) cdat code" && popd && checked_done 1
echo "CMAKE ARGS"${cmake_args}
echo "UVCDAT BDIR"${uvcdat_build_directory}
popd >& /dev/null
)
[ $? != 0 ] && echo " ERROR: Could not compile (make) cdat code" && popd && checked_done 1
${cdat_home}/bin/python -c "import cdms2" 2>/dev/null
[ $? != 0 ] && echo " ERROR: Could not load CDMS (cdms2) module" && popd && checked_done 1
popd >& /dev/null
echo
checked_done 0
}
setup_cdat_xtra() {
echo "Installing Extra Package ${1}"${uvcdat_build_directory}/uvcdat/Packages/$1
cd ${uvcdat_build_directory}/uvcdat/Packages/$1 >& /dev/null
env BUILD_DIR="." CFLAGS="-I${install_prefix}/Externals/include" ${install_prefix}/bin/python setup.py install
[ $? != 0 ] && echo " Error could not install CDAT extra python package ${1} using ${install_prefix}/bin/python"
}
setup_metrics() {
cd ${metrics_build_directory} >& /dev/null
${cdat_home}/bin/python setup.py install --prefix=${install_prefix}
[ $? != 0 ] && echo " Error could not install metrics python package using ${cdat_home}/bin/python"
}
_full_path() {
# Figure out the full path and resolved symlinks
# Saves current dir
local DIR=`pwd`
if [ ! -d $1 ]; then
if [ ${1:0:1} == "/" ]; then
local PTH=$1
else
local PTH=`pwd -P`/$1
fi
else
pushd $1 >& /dev/null
local PTH=`pwd -P`
fi
mkdir -p ${PTH}
echo ${PTH}
if [ $? != 0 ]; then
exit 1
fi
pushd ${DIR} >& /dev/null
exit 0
}
_readlinkf() {
# This is a portable implementation of GNU's "readlink -f" in
# bash/zsh, following symlinks recursively until they end in a
# file, and will print the full dereferenced path of the specified
# file even if the file isn't a symlink.
#
# Loop detection exists, but only as an abort after passing a
# maximum length.
local start_dir=$(pwd)
local file=${1}
local current_dir
current_dir=$(pwd -P)
cd $(dirname ${file}) >& /dev/null
if [ $? != 0 ]; then
echo ${current_dir}/${file}
exit 0
fi
file=$(basename ${file})
# Iterate down symlinks. If we exceed a maximum number symlinks, assume that
# we're looped and die horribly.
local maxlinks=20
local count=0
while [ -L "${file}" ] ; do
file=$(readlink ${file})
cd $(dirname ${file}) >& /dev/null
file=$(basename ${file})
((count++))
if (( count > maxlinks )) ; then
current_dir=$(pwd -P)
echo "CRITICAL FAILURE[4]: symlink loop detected on ${current_dir}/${file}"
cd ${start_dir} >& /dev/null
exit ${count}
fi
done
echo "${current_dir}/${file}"
cd ${start_dir} >& /dev/null
}
main() {
## Generic Build Parameters
cmake_repo=git://cmake.org/cmake.git
cmake_repo_http=http://cmake.org/cmake.git
cmake_repo_https=https://cmake.org/cmake.git
cmake_min_version=2.8.11
cmake_max_version=2.9
cmake_version=2.8.12
force_install=0
DEBUG=1
cdat_repo=git://github.com/UV-CDAT/uvcdat.git
cdat_repo_http=http://github.com/UV-CDAT/uvcdat.git
cdat_repo_https=https://github.com/UV-CDAT/uvcdat.git
cdat_version="master"
metrics_repo=git://github.com/PCMDI/pcmdi_metrics.git
metrics_repo_http=http://github.com/PCMDI/pcmdi_metrics.git
metrics_repo_https=https://github.com/PCMDI/pcmdi_metrics.git
metrics_checkout="master"
install_prefix=$(_full_path ${install_prefix})
if [ $? != 0 ]; then
echo "Could not create directory ${install_prefix}"
exit 1
fi
build_directory=$(_full_path ${build_directory})
if [ $? != 0 ]; then
echo "Could not create directory ${build_directory}"
exit 1
fi
metrics_build_directory=${build_directory}/metrics
cmake_build_directory=${build_directory}/cmake
uvcdat_build_directory=${build_directory}/uvcdat
cmake_install_dir=${install_prefix}/Externals
cdat_home=${install_prefix}
echo "Installing into: "${install_prefix}
echo "Temporary build directory: "${build_directory}
## clone pcmdi_metrics repo
git clone ${metrics_repo} ${metrics_build_directory}
if [ ! -e ${metrics_build_directory}/.git/config ]; then
echo " WARN: Could not clone metrics repo via git protocol (port 9418)! Trying https protocol"
git clone ${metrics_repo_https} ${metrics_build_directory}
if [ ! -e ${metrics_build_directory}/.git/config ]; then
echo " WARN: Could not clone metrics repo via https (port 22)! Trying http protocol (port 80)"
git clone ${metrics_repo_http} ${metrics_build_directory}
if [ ! -e ${metrics_build_directory}/.git/config ]; then
echo " ERROR: Could not clone metrics repo via git/https/http! Check you are connected to the internet or your firewall settings"
exit 1
fi
fi
fi
cd ${metrics_build_directory} >& /dev/null
git checkout ${metrics_checkout}
## Source funcs needed by installer
. ${metrics_build_directory}/installer_funcs.bash
mkdir -p ${install_prefix}
mkdir -p ${install_prefix}/Externals
mkdir -p ${install_prefix}/Externals/bin
mkdir -p ${install_prefix}/Externals/lib
mkdir -p ${install_prefix}/Externals/include
mkdir -p ${install_prefix}/Externals/share
PATH=${install_prefix}/Externals/bin:${PATH}
setup_cmake
setup_cdat
echo "After setup_cdat ${cdat_home}"
setup_metrics
pushd ${uvcdat_build_directory}/uvcdat >& /dev/null
git apply ${metrics_build_directory}/src/patch_uvcdat.patch
setup_cdat_xtra genutil
setup_cdat_xtra xmgrace
setup_cdat_xtra cdutil
rmdir ${install_prefix}/sample_data
echo
echo
echo "*******************************"
echo "UVCDAT - ${cdat_version} - Install Success"
echo "Metrics - ${metrics_checkout} - Install Success"
echo "*******************************"
echo "Please test as follow:"
echo "source ${cdat_home}/bin/setup_runtime.sh"
echo "pcmdi_metrics_driver.py -p ${install_prefix}/test/pcmdi/basic_test_parameters_file.py"
echo "compare: diff ${install_prefix}/test/pcmdi/tos_2.5x2.5_esmf_linear_metrics.json.good pcmdi_install_test_results/metrics_results/installationTest/tos_2.5x2.5_esmf_linear_metrics.json"
echo "*******************************"
echo "Create your customized input_parameters.py (inspire yourself from examples in ${install_prefix}/doc/pcmdi_input_parameters_sample.py"
echo "Once you have a parameter file run:"
echo "source ${install_prefix}/bin/setup_runtime.sh"
echo "pcmdi_metrics_driver.py -p /path/to/your/edited/parameter_file.py"
echo "*******************************"
echo "Once everything is ok, you can safely remove the temporary directory: ${build_directory}"
echo "*******************************"
echo
}
main