-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-plumed.sh
executable file
·119 lines (101 loc) · 3.28 KB
/
install-plumed.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
#! /bin/bash
# To me: the enviromental variable I am using as input are in CAPS,
# if I modify a variable is in lower case
cd "$(mktemp -dt plumed.XXXXXX)" || {
echo "Failed to create tempdir"
exit 1
}
if git clone --quiet "$REPO"; then
cd plumed2 || {
echo "Failed to cd into plumed2"
echo "Is the repository \"${REPO}\" a plumed repository?"
exit 1
}
else
echo "Failed to clone plumed2"
exit 1
fi
version=$VERSION
if [[ -n "$version" ]]; then
echo "installing plumed $version"
else
version=$(git tag --sort=version:refname |
grep '^v2\.[0-9][0-9]*\.[0-9][0-9]*' |
tail -n 1)
echo "installing latest stable plumed $version"
fi
#TODO: make plumed_options an array to solve spaces problems and solve SC2086
plumed_options="$EXTRA_OPTIONS"
program_name=plumed
if [[ -n "$SUFFIX" ]]; then
plumed_options="$plumed_options --program-suffix=$SUFFIX"
program_name=$program_name$SUFFIX
fi
#just to be sure
prefix=${PREFIX:-"$HOME/opt"}
prefix=${prefix/'~'/$HOME}
mkdir -p "$prefix"
prefix=$(realpath "$prefix")
plumed_options="$plumed_options --prefix=$prefix"
if [[ -n "$MODULES" ]]; then
plumed_options="$plumed_options --enable-modules=$MODULES"
fi
#cheking out to $version before compiling the dependency json for this $version
git checkout --quiet "$version"
if [[ -n $DEPPATH ]]; then
mypath=$(realpath $DEPPATH)
mkdir -pv "$mypath"
dependencies_file="${mypath}/extradeps${version}.json"
echo "Creating a dependencies file at $dependencies_file"
# This gets all the dependency information in plumed
{
firstline=""
echo '{'
for mod in src/*/Makefile; do
dir=${mod%/*}
modname=${dir##*/}
typename=$dir/module.type
if [[ ! -f $typename ]]; then
modtype="always"
else
modtype=$(head "$typename")
fi
dep=$(grep USE "$mod" | sed -e 's/USE=//')
IFS=" " read -r -a deparr <<<"$dep"
echo -e "${firstline}\"$modname\" : {"
echo "\"type\": \"$modtype\","
echo -n '"depends" : ['
pre=""
for d in "${deparr[@]}"; do
echo -n "${pre}\"$d\""
pre=", "
done
echo ']'
echo -n '}'
firstline=",\n"
done
echo -e '\n}'
} >"$dependencies_file"
echo "dependencies=$dependencies_file" >>"$GITHUB_OUTPUT"
fi
hash=$(git rev-parse HEAD)
if [[ -f ${prefix}/lib/$program_name/$hash ]]; then
echo "ALREADY AVAILABLE, NO NEED TO REINSTALL"
else
#remove the conflicting old installation
rm -fr "${prefix:?}/lib/$program_name"
rm -fr "${prefix:?}/bin/$program_name"
rm -fr "${prefix:?}/include/$program_name"
rm -fr "${prefix:?}"/lib/lib$program_name.so*
#{var:?} makes the shell fail to avoid unwanted "explosive" deletions in /lib and /bin
#${LD_LIBRARY_PATH+,${LD_LIBRARY_PATH}} wil print "," then the content of LD_LIBRARY_PATH, if it is not empty
set -e
(
set -x
./configure $plumed_options ${LD_LIBRARY_PATH+LDFLAGS=-Wl,-rpath,\"${LD_LIBRARY_PATH}\"}
)
make -j 5
make install
touch "${prefix}/lib/$program_name/$hash"
fi
echo "plumed_path=${prefix}" >>"$GITHUB_OUTPUT"