-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinstall
executable file
·538 lines (436 loc) · 13.5 KB
/
install
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
#! /bin/bash
package=QA-DKRZ
hdf5=hdf5-1.8.14
netcdf=netcdf-4.3.2
zlib=zlib-1.2.8
udunits=udunits-2.2.20
defaultProject=CORDEX
descript()
{
echo "Usage: install [options] [project[s]]"
echo "Purpose: Install/update 'the Quality Control Software Package'"
echo "for checking climate simulation meta-data provided in netCDF format."
echo "Details at https://redmine.dkrz.de/projects/cordex/wiki/DKRZ_QC_Tool"
echo ''
echo "Options:"
echo " -B Unconditionally re-make all QA executables."
echo " -d Execute 'make' with debugging information."
echo " -h Display usage and exit."
echo " --auto-up Enable automatic updates from the repository at the"
echo " beginning of a run. Suspended by --auto-up=d[isable]."
echo " --build Download and build required libraries."
echo " --debug[=script] Display execution commands. If the name of a script"
echo " called internally is assigned, then debug only this one."
echo " --help Display usage and exit."
echo " --link=path Hard links of external NetCDF installations from the directories"
echo " in 'your-path/${package}/local'."
echo " Shared by all hdf, netcdf, udunits and zlib."
echo " --link_type=path Same as for 'link' but just for type=netcdf, hdf, zlib, or udunits"
echo " --local=str Path where lib and include directories are to be installed"
echo " [default: QA_DKRZ/local] for both real and hard-links."
echo " Note: unneccesary when install_configure points outside."
echo " --show-inst Display properties of the current installation."
echo " --up[date] Update the QA package from the repository."
echo " Note: not for netCDF, HDF5, udunits2 or zlib."
echo " --workspace=str Path to put updated tables [ ~/.qa-dkrz/tables by"
echo " default]. Also, str is the location of the CF test,"
echo " suite, an example run, and of qc check results for"
echo " omitted option QC_RESULTS. Special: Omitted str "
echo " defaults to the QA-DKRZ path, i.e. as for QC-0.4;"
echo " write permission required. The default for the workspace itself"
echo " is \$HOME\.qa-dkrz [if not available, then the user"
echo " is asked to provide --workspace".
echo ""
echo " project-name At present CF, CMIP5, and CORDEX; the latter by default."
}
getCurrPaths()
{
# where all the work is going to take place
if [ $QA_WORK ] ; then
test ! -d $QA_WORK && mkdir -p $QA_WORK 2> /dev/null
else
if [ $CONDA_ENV ] ; then
QA_WORK=~/.qa-dkrz
test ! -d $QA_WORK && mkdir -p $QA_WORK 2> /dev/null
else
QA_WORK=$QA_PATH
fi
fi
# the config filename and location
local isPrint=f
if [ ! ${CONFIG_FILE} ] ; then
if [ -w ~ ] ; then
local cPath=~/.qa-dkrz
test ! -d $cPath && mkdir -p $cPath 2> /dev/null
export CONFIG_FILE=$cPath/config.txt
elif [ -w "$QA_PATH" ] ; then
test ! -d $QA_PATH/.qa-dkrz && mkdir -p $QA_PATH/.qa-dkrz 2> /dev/null
export CONFIG_FILE=$QA_PATH/.qa-dkrz/config.txt
elif [ -w "$QA_WORK" ] ; then
# not determined but may-be provided by the user
test ! -d $QA_WORK && mkdir -p $QA_WORK/.qa-dkrz 2> /dev/null
export CONFIG_FILE=$QA_WORK/config.txt
else
isPrint=t
fi
fi
if [ ${isPrint} = t ] ; then
echo "HOME and QA_DKRZ without write permissions,"
echo "please restart with added option --workspace=path"
exit
fi
return
}
getGitBranch()
{
git branch | grep '*' | awk '{print $2}'
return
}
getRevNum()
{
# get current revision number; this determines whether it is
# before a change of defaults happened.
local branch currIdent
if [ $CONDA_ENV ] ; then
if branch=$(grep branch $QA_PATH/install.log 2> /dev/null) ; then
branch=${branch#*=}
fi
if currIdent=$(grep branch $QA_PATH/install.log 2> /dev/null) ; then
currIdent=${currIdent#*=}
fi
else
branch=$(getGitBranch)
currIdent=$(git log --pretty=format:'%h' -n 1)
fi
eval ${1}=${branch}-${currIdent}
return
}
getCondaPath()
{
local conda=f
local path=${1%/*}
path=${path%/*}
path=${path}/opt/qa-dkrz
if [ -d $path ] ; then
eval ${2}=$path
return 0
fi
return 1
}
getSrcPath()
{
# extract the path to the root of the QA package
# is it in a conda built?
getCondaPath $0 QA_PATH
if getCondaPath $0 QA_PATH ; then
export QA_PATH
CONDA_ENV=t
fi
test ${QA_PATH} && return
local target isInvalid
if [ ${1:0:1} = '/' ] ; then
target=$1
else
target=$(pwd)/$1
fi
if [ -h $target ] ; then
# get the link
local link=$(ls -l $target | awk '{print $(NF)}')
# link is relative, so make it absolute
test ${link:0:1} != '/' && link=${target%/*}/${link}
getSrcPath ${link}
elif [ -f $target ] ; then
# a real instance, at first resolve .. and .
# works also for . or .. in the middle of the path
local xname=${target##*/}
target=${target%/*} # remove the name of the script
local arr=( ${target//\// } )
local i j sz
sz=${#arr[*]}
for(( i=1 ; i < sz ; ++i )) ; do
if [ "${arr[i]}" = '.' ] ; then
unset arr[i]
elif [ "${arr[i]}" = '..' ] ; then
j=$((i-1))
# this takes into account adjacent . and/or .. with any depth
while [ ! ${arr[j]} ] ; do
j=$((j-1))
done
unset arr[j]
unset arr[i]
fi
done
# get rid of empty items
arr=( ${arr[*]} )
sz=${#arr[*]}
local tmp
for(( i=0 ; i < sz ; ++i )) ; do
tmp=${tmp}/${arr[i]}
if [ -f ${tmp}/.install_configure ] ; then
export QA_PATH=$tmp
break
fi
done
test $i -eq $sz && isInvalid=t
else
isInvalid=t
fi
if [ ${isInvalid:-f} = t ] ; then
local str=$(ls -l $target 2> /dev/null | awk '{print $(NF)}')
if [ ${#str} -gt 0 ] ; then
str="invalid path=$0"
else
str="broken path=$0"
fi
echo "${str}"
exit 1
fi
export QA_PATH=${QA_PATH}
return
}
log()
{
if [ ${isContinueLog:-f} = f ] ; then
isContinueLog=t
local logTxt="\n$(date +'%F_%T'):"
echo -e "${logTxt} install $*" >> install.log
fi
return
}
saveAsCycle()
{
for f in $* ; do
if [ ! \( -f $f -o -d $f \) ] ; then
echo "install.saveAsCycle: no such file or directory $f"
return
fi
local ext val x
local maxVal fs fx
maxVal=0
fs=( $(ls -d $f.* 2> /dev/null) )
for fx in ${fs[*]} ; do
ext=${fx##*.}
if val=$(expr match $ext '\([[:digit:]]\+$\)' 2> /dev/null) ; then
test ${val:-0} -gt ${maxVal} && maxVal=$val
fi
done
mv $f ${f}.$((++maxVal)) 2> /dev/null
done
}
tr_option()
{
local phrase="${!1}"
local sz i
local sz=${#phrase}
for((i=0 ; i < sz ; ++i )) ; do
test "${phrase:i:1}" = '=' && break
done
if [ ${i} -eq ${sz} ] ; then
phrase=$( echo "${phrase/% /}" | tr "[:lower:]" "[:upper:]" )
phrase=$( echo "${phrase}" | tr "-" "_" )
else
local tmp0="${phrase:0:i}"
tmp0="${tmp0//QC/QA}"
tmp0=$( echo "${tmp0/% /}" | tr "[:lower:]" "[:upper:]" )
tmp0=$( echo "${tmp0}" | tr "-" "_" )
phrase="${tmp0}""${phrase:i}"
fi
eval ${1}=\${phrase}
return
}
update()
{
if . $QA_PATH/scripts/updateConfigFile.txt ${AUTO_UPDATE:-AUTO_UPDATE} \
|| [ ${isUpdateQA:-f} = t ]; then
if [ $CONDA_ENV ] ; then
# look for a new conda-built package
local tmp
declare -a tmp
tmp=( $(conda search -c birdhouse qa-dkrz 2> /dev/null) )
local i item
for(( i=0 ; i < ${#tmp[*]} ; ++i )) ; do
if [ ${tmp[i]} = '*' ] ; then
item=${tmp[++i]}
item=${item}-${tmp[++i]}
if ! . $QA_PATH/scripts/updateConfigFile.txt CONDA_BUILD=$item ; then
conda update -c birdhouse qa-dkrz &> /dev/null
getRevNum packRev
exitVal=101
fi
break
fi
done
elif [ ! -f ${QA_PATH}/.ignore_GitHub ] ; then
cd $QA_PATH
# switch repository
asdf=( $( git remote -v ) )
if [ ${asdf[1]} != ${asdf[1]//h-dh/} ] ; then
git remote set-url origin https://github.com/IS-ENES-Data/QA-DKRZ.git
exec install $*
fi
# is qa-dkrz going to change?
local qa_dkrzDate=$(ls -l \
--time-style=+'%s' ${QA_PATH}/scripts/qa_dkrz \
| awk '{print $6}' 2> /dev/null )
test "$(getGitBranch)" != master && \
git checkout master &> /dev/null
git fetch && git reset --hard origin/master &> /dev/null
# git pull --no-edit -q origin master &> /dev/null
if [ ${qa_dkrzDate} != $( ls -l \
--time-style=+'%s' ${QA_PATH}/scripts/qa_dkrz \
| awk '{print $6}' 2> /dev/null ) ] ; then
exitVal=101
fi
# revison num of the updated package
getRevNum packRev
fi
fi
. $QA_PATH/scripts/updateConfigFile.txt QA_REVISION${packRev:+=}$packRev
if . $QA_PATH/scripts/updateConfigFile.txt \
${AUTO_TABLE_UPDATE:-AUTO_TABLE_UPDATE} \
|| [ ${FORCE_RSYNC:-f} = t ] ; then
if [ "$QA_WORK" != "$QA_PATH" ] ; then
rsync -auz $QA_PATH/tables $QA_WORK &> /dev/null
fi
${QA_PATH}/scripts/get_cfconventions \
--qa_path=${QA_PATH} \
--config_file=$CONFIG_FILE \
${QA_WORK}/tables/projects/CF
fi
return
}
# ----- main ------
zeroArg=$0
allArgs=($*)
if [ $# -gt 0 ] ; then
# safe arguments
sArgs=($*)
# higher priority options
for(( i=0 ; i < ${#sArgs[*]} ; ++i )) ; do
# some args are accepted without '--'
A="${sArgs[i]}"
tr_option A
if [ "${A:0:5}" = AUTO_ -o "${A:0:5}" = "AUTO-" ] ; then
sArgs[${i}]=--${sArgs[${i}]}
A="--${A}"
elif [ "${A:0:5}" = DEBUG ] ; then
sArgs[${i}]=--${sArgs[${i}]}
A="--${A}"
elif [ "${A:0:4}" = HELP ] ; then
sArgs[${i}]=--${sArgs[${i}]}
A="--${A}"
elif [ "${A:0:4}" = LINK ] ; then
sArgs[${i}]=--${sArgs[${i}]}
A="--${A}"
elif [ "${A:0:6}" = ONLY-Q ] ; then
sArgs[${i}]=--${sArgs[${i}]}
A="--${A}"
elif [ "${A:0:3}" = SRC ] ; then
sArgs[${i}]=--${sArgs[${i}]}
A="--${A}"
elif [ "${A:0:2}" = UP ] ; then
sArgs[${i}]=--${sArgs[${i}]}
A="--${A}"
fi
if [ "${A%=*}" = '--DEBUG' ] ; then
test ${A} = '--DEBUG' -o ${A#*=} = ${0##*/} && set -x
fi
done
fi
while getopts Bdh-: option ${sArgs[*]}
do
UOPTARG="${OPTARG}"
tr_option UOPTARG
case $option in
B) coll[${#coll[*]}]=-B ;;
d) coll[${#coll[*]}]=-d ;;
h) descript
exit ;;
-) OPTVAL=${OPTARG##*=}
if [ "${UOPTARG:0:7}" = AUTO_UP -o "${UOPTARG:0:7}" = AUTO-UP ] ; then
if [ "${OPTVAL}" ] ; then
AUTO_UPDATE=AUTO_UPDATE=${OPTVAL}
else
AUTO_UPDATE=AUTO_UPDATE=enabled
fi
elif [ "${UOPTARG:0:13}" = AUTO_TABLE_UP ] ; then
if [ "${OPTVAL}" ] ; then
AUTO_TABLE_UPDATE=AUTO_TABLE_UPDATE=${OPTVAL}
else
AUTO_TABLE_UPDATE=AUTO_TABLE_UPDATE=enabled
fi
elif [ "${UOPTARG:0:5}" = BUILD ] ; then
isBuild=t
elif [ "${UOPTARG:0:11}" = CONFIG_FILE ] ; then
export CONFIG_FILE=${OPTVAL}
elif [ ${UOPTARG:0:5} = DEBUG -o ${UOPTARG} = 'DEBUG=install' ] ; then
set -x
elif [ "${UOPTARG%%=*}" = HELP ] ; then
descript
exit
elif [ "${UOPTARG:0:4}" = LINK ] ; then
isLink=t
elif [ "${UOPTARG:0:6}" = ONLY_Q ] ; then
: # for backward compatibilty
elif [ "${UOPTARG:0:7}" = QA_PATH ] ; then
export QA_PATH=${OPTVAL}
elif [ "${UOPTARG:0:7}" = QA_WORK ] ; then
QA_WORK=${OPTVAL}
elif [ "${UOPTARG}" = SRC ] ; then
: # for backward compatibilty
elif [ "${UOPTARG%=*}" = SET_DEFAULT_PROJECT ] ; then
DEF_PRJ=${OPTVAL}
continue
elif [ "${UOPTARG:0:2}" = UP ] ; then
isUpdateQA=t
elif [ "${UOPTARG:0:9}" = WORKSPACE ] ; then
QA_WORK=${UOPTARG##*=}
fi
# collect options, which have not been processed above
coll[${#coll[*]}]=--${OPTARG}
;;
\?) descript
echo $*
exit 1 ;;
esac
done
shift $(( $OPTIND - 1 ))
for pck in $* ; do
PCK="${pck}"
tr_option PCK
if [ ${PCK:0:4} = ZLIB ] ; then
zlib=${pck}
elif [ ${PCK:0:4} = HDF5 ] ; then
hdf5=${pck}
elif [ ${PCK:0:6} = NETCDF ] ; then
netcdf=${pck}
elif [ ${PCK:0:7} = UDUNITS ] ; then
udunits=${pck}
elif [ ${PCK:0:7} = QA_WORK ] ; then
QA_WORK=${PCK:8}
FORCE_RSYNC=t
else
coll[${#coll[*]}]=$pck # collect project names
fi
done
getSrcPath $zeroArg # sets also CONDA_ENV
getCurrPaths
update ${allArgs[*]}
if . $QA_PATH/scripts/updateConfigFile.txt DEFAULT_PROJECT ; then
defPrj=--default_project=${DEFAULT_PROJECT#*=}
else
defPrj=--default_project=$defaultProject
fi
test ${CONDA_ENV} && exit # miniconda built executables
pcks="--zlib=$zlib --hdf5=$hdf5 --netcdf=$netcdf --udunits=$udunits"
if [ ${isBuild:-f} = t -a ${isLink:-f} = t ] ; then
echo "scripts/install.sh: options --build and --link exclude each other"
exit 1
elif [ ${isBuild:-f} = t -o ${isLink:-f} = t ] ; then
log ${allArgs[*]}
else
pcks=
fi
exec $QA_PATH/scripts/install.sh ${debug} --pack=${package} \
${isContinueLog:+--continue_log} ${pcks} ${defPrj} \
${coll[*]}