-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdeploy_modulefiles.sh.in
59 lines (42 loc) · 1.94 KB
/
deploy_modulefiles.sh.in
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
#!/bin/bash
set -e
# Defaults to user options will be provided by CMake
modulesDestDir=${1:-"@CMAKE_INSTALL_PREFIX@/modules"}
DOVERWRITEMODULES=${2:-"@OVERWRITEMODULES@"}
# These will be filled by CMake
nceplibsInstallDir=@CMAKE_INSTALL_PREFIX@
tmplModulefilesDir=@CMAKE_CURRENT_SOURCE_DIR@/tmplModulefiles
LIBCOMPS=@LIBCOMPS_FILE@
DFLAT="@FLAT@"
[[ $DOVERWRITEMODULES == "ON" ]] && OVERWRITE="Y" || OVERWRITE="N"
[[ $DFLAT == "ON" ]] && FLAT="Y" || FLAT="N"
echo "Begin deploying modules ..."
for libName in $(ls -1 $tmplModulefilesDir); do
# Ensure $libName is indeed a library being installed
isAbsent=$(cat $LIBCOMPS | grep -w $libName | wc -l)
[[ $isAbsent -eq 0 ]] && continue
echo "deploying modulefile for ... $libName"
# Get the version being installed (if a branch, replace "/" with "-")
# Must be consistent with CMakeLists.txt
ver=$(cat $LIBCOMPS | grep -w $libName | cut -d"|" -f3)
ver=$(echo ${ver} | sed -e "s/\//-/g")
# Define source and destination modulefile name
# Destination filename must be consistent with CMakeLists.txt
srcModulefile=$tmplModulefilesDir/$libName/$libName.lua
dstModulefile=$modulesDestDir/$libName/$ver.lua
# Create destination directory for the modulefile and copy template to it
mkdir -p $modulesDestDir/$libName
if [[ -f $dstModulefile ]]; then
[[ $OVERWRITE =~ [YyTt] ]] && ( echo "WARNING: $dstModulefile exists, OVERWRITING!"; \rm -f $dstModulefile ) \
|| ( echo "ERROR: $dstModulefile exists, ABORT!"; exit 1 )
fi
\cp $srcModulefile $dstModulefile
[[ $FLAT =~ [YyTt] ]] && prefix=${nceplibsInstallDir} || prefix=${nceplibsInstallDir}/$libName
# sed does not like delimiter (/) to be a part of replacement string
# so do magic
repl=$(echo ${prefix} | sed -e "s#/#\\\/#g")
# Replace #NCEPLIBS_ROOT# from template with $nceplibsInstallDir
sed -i -e "s/#NCEPLIBS_ROOT#/${repl}/g" $dstModulefile
done
echo "Done deploying modules ..."
exit 0