forked from AIT-WATCHMAN/WMUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchmanInstaller.sh
executable file
·344 lines (321 loc) · 7.46 KB
/
watchmanInstaller.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
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
#!/bin/bash
# Since system dependencies, especially on clusters, are a pain
# Lets just pre-install everything (except GCC for now).
# Todo:
# --help, -h
# wmInstall.log
exec > >(tee -i wminstall.log)
exec 2>&1
function install(){
help $@
procuse=$(getnproc $@)
# End testing
export CC="$(command -v gcc)"
export CXX="$(command -v g++)"
# Check requirements; Git && GCC
if ! [ -x "$(command -v gcc)" ]; then
echo "gcc not installed"
exit 1
fi
if ! [ -x "$(command -v git)" ]; then
echo "git not installed"
exit 1
fi
skipping=false
skip_cmake=false
skip_python=false
skip_root=false
skip_geant=false
skip_ratpac=false
skip_sibyl=false
for element in $@;
do
if [ "$skipping" = true ]
then
if [ $element == "cmake" ]
then
skip_cmake=true
fi
if [ $element == "python" ]
then
skip_python=true
fi
if [ $element == "root" ]
then
skip_root=true
fi
if [ $element == "geant4" ]
then
skip_geant=true
fi
if [ $element == "ratpac" ]
then
skip_ratpac=true
fi
if [ $element == "sibyl" ]
then
skip_sibyl=true
fi
fi
if [ $element == "--skip" ]
then
skipping=true;
fi
done
boolOnly=false
for element in $@;
do
if [ "$boolOnly" = true ]
then
if [ $element == "cmake" ]
then
skip_cmake=false
fi
if [ $element == "python" ]
then
skip_python=false
fi
if [ $element == "root" ]
then
skip_root=false
fi
if [ $element == "geant4" ]
then
skip_geant=false
fi
if [ $element == "ratpac" ]
then
skip_ratpac=false
fi
if [ $element == "sibyl" ]
then
skip_sibyl=false
fi
fi
if [ $element == "--only" ]
then
# Only will overwrite the skipping rules
boolOnly=true
skip_cmake=true
skip_python=true
skip_root=true
skip_geant=true
skip_ratpac=true
skip_sibyl=true
fi
done
prefix=$(pwd -P)/local
mkdir -p $prefix/bin
export PATH=$prefix/bin:$PATH
export LD_LIBRARY_PATH=$prefix/lib:$LD_LIBRARY_PATH
# Install cmake
if ! [ "$skip_cmake" = true ]
then
git clone https://github.com/Kitware/CMake.git --single-branch --branch v3.16.0 cmake_src
mkdir -p cmake_build
cd cmake_build
../cmake_src/bootstrap --prefix=../local \
&& make -j$procuse \
&& make install
cd ../
# Check if cmake was successful, if so clean-up, otherwise exit
if test -f $prefix/bin/cmake
then
printf "Cmake install successful\n"
else
printf "Cmake install failed ... check logs\n"
exit 1
fi
rm -rf cmake_src cmake_build
fi
# Install python
if ! [ "$skip_python" = true ]
then
git clone https://github.com/python/cpython.git --single-branch --branch 3.7 python_src
cd python_src
./configure --prefix=$prefix --enable-shared \
&& make -j$procuse \
&& make install
cd ../
# Check if python was successful, if so clean-up, otherwise exit
if test -f $prefix/bin/python3
then
printf "Python install successful\n"
else
printf "Python install failed ... check logs\n"
exit 1
fi
rm -rf python_src
python3 -m pip install --upgrade pip
python3 -m pip install numpy docopt
fi
# Install root
if ! [ "$skip_root" = true ]
then
git clone https://github.com/root-project/root.git --single-branch --branch v6-18-00 root_src
mkdir -p root_build
cd root_build
cmake -D minuit2=ON -DCMAKE_INSTALL_PREFIX=$prefix \
-DPYTHON_EXECUTABLE=$(command -v python3) \
../root_src \
&& make -j$procuse \
&& make install
cd ../
# Check if root was successful, if so clean-up, otherwise exit
if test -f $prefix/bin/root
then
printf "Root install successful\n"
else
printf "Root install failed ... check logs\n"
exit 1
fi
rm -rf root_src root_build
fi
# Install Geant4
if ! [ "$skip_geant" = true ]
then
git clone https://github.com/geant4/geant4.git --single-branch --branch geant4-10.4-release geant_src
mkdir -p geant_build
cd geant_build
cmake -DCMAKE_INSTALL_PREFIX=$prefix ../geant_src -DGEANT4_BUILD_EXPAT=OFF -DGEANT4_BUILD_MULTITHREADED=OFF -DGEANT4_USE_QT=ON -DGEANT4_INSTALL_DATA=ON -DGEANT4_INSTALL_DATA_TIMEOUT=15000 \
&& make -j$procuse \
&& make install
cd ../
# Check if g4 was successful, if so clean-up, otherwise exit
if test -f $prefix/bin/geant4-config
then
printf "G4 install successful\n"
else
printf "G4 install failed ... check logs\n"
exit 1
fi
rm -rf geant_src geant_build
fi
# Install rat-pac
if ! [ "$skip_ratpac" = true ]
then
source $prefix/bin/thisroot.sh
source $prefix/bin/geant4.sh
rm -rf ratpac
git clone https://github.com/ait-watchman/rat-pac.git ratpac
cd ratpac
make -j$procuse && source ./ratpac.sh
# Check if ratpac was successful, if so clean-up, otherwise exit
if test -f build/bin/rat
then
printf "Ratpac install successful\n"
else
printf "Ratpac install failed ... check logs\n"
exit 1
fi
cd ../
fi
if ! [ "$skip_sibyl" = true ]
then
source $prefix/../ratpac/ratpac.sh
python3 -m pip install git+https://github.com/ait-watchman/sibyl#egg=sibyl
fi
outfile="env.sh"
printf "export PATH=$prefix/bin:\$PATH\n" > $outfile
printf "export LD_LIBRARY_PATH=$prefix/lib:\$LD_LIBRARY_PATH\n" >> $outfile
printf "pushd $prefix/bin 2>&1 >/dev/null\nsource thisroot.sh\nsource geant4.sh\npopd 2>&1 >/dev/null\n" >> $outfile
printf "source $prefix/../ratpac/ratpac.sh" >> $outfile
}
function help()
{
for element in $@
do
if [[ $element =~ "-h" ]];
then
printf "Watchman Installer -- in progress\n"
exit 0
fi
done
}
function getnproc()
{
local nproc=1
for element in $@
do
if [[ $element =~ "-j" ]];
then
nproc=$(echo $element | sed -e 's/-j//g')
fi
done
echo $nproc
}
function command_exists()
{
if (command -v $1 > /dev/null )
then
true
else
false
fi
}
function check_deps()
{
bool=true
# Before trying to install anything, confirm a list of dependencies
echo "Checking list of dependencies ..."
cmds=(gcc gfortran openssl curl)
for c in ${cmds[@]}
do
if command_exists $c
then
printf "%-30s%-20s\n" $c "Installed"
else
printf "%-30s%-20s\n" $c "NOT AVAILABLE"
bool=false
fi
done
# Check libraries with ldd
echo "Checking for libraries ..."
libraries=(libX11 libXpm libXft libffi libXext libQt libOpenGL)
for lb in ${libraries[@]}
do
if check_lib $lb
then
printf "%-30s%-20s\n" $lb "Installed"
else
printf "%-30s%-20s\n" $lb "NOT AVAILABLE"
bool=false
fi
done
echo "Dependencies look to be in check"
$bool
}
function check_lib()
{
if (ldconfig -p | grep -q $1)
then
true
else
false
fi
}
function skip_check()
{
bool=false
for elem in $@
do
if [[ $elem = "--skip-checks" ]];
then
printf "Skipping dependency checker\n"
bool=true
fi
done
$bool
}
if skip_check $@
then
install $@
else
if check_deps
then
install $@
else
printf "\033[31mPlease install system dependencies as indicated above.\033[0m\n"
printf "\033[31mYou can skip these checks by passing the --skip-checks flag.\033[0m\n"
fi
fi