-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
475 lines (399 loc) · 9.15 KB
/
install.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
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
# =========================
# DEFINE
# =========================
# input
CONDA_ENV='nvnmd'
NVNMD_PATH="nvnmd"
PHASE_ST=0
SUBPH_ST=0
PHASE_ED=100
SUBPH_ED=100
# base
INSTALL_PATH=`pwd`
PACKAGE="$INSTALL_PATH/package"
PATCH="$INSTALL_PATH/patch"
LOG_FN="$INSTALL_PATH/install.log"
# conda
CONDA_VERSION="4.11.0"
ENV_PATH=""
# gcc
GCC_VERSION="9.0.0"
# git
GIT_VERSION="2.34.0"
# python
PYTHON_VERSION="3.9.0"
# cmake
CMAKE_VERSION="3.10.0"
CMAKE="cmake"
CMAKE_BIN=$INSTALL_PATH/cmake/$CMAKE/bin/
# tensorflow
TENSORFLOW_VERSION="2.7.0"
TENSORFLOW="tensorflow"
LIBTF_CC_VERSION=2.7.0
LIBTF_CC_BUILD=cpu_h6ddf1b9_0
# nvnmd
NVNMD_VERSION="2.0.0"
NVNMD="nvnmd"
NVNMD_BIN="$INSTALL_PATH/nvnmd/bin/"
# head
HEAD_INFO="\033[32m #INFO \033[0m"
HEAD_WARNING="\033[33m #WARNING \033[0m"
HEAD_ERROR="\033[31m #ERROR \033[0m"
# flga
FLAG_RIGHT="\033[32m [v] \033[0m"
FLAG_NRIGHT="\033[33m [ ] \033[0m"
FLAG_FALSE="\033[31m [x] \033[0m"
# funtion return
RT_MATCH_VERSION=0
RT_FIND_CMD=0
RT_FIND_ENV=0
# global
phase=0
ist_phase=0
nxt_phase=0
subph=0
ist_subph=0
nxt_subph=0
TITLE=""
#
CPU_CORE=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $4}'`
# =========================
# FUNCTION
# =========================
function title {
TITLE=$1
echo
echo "=================================================="
echo -e "$HEAD_INFO: $TITLE"
echo "=================================================="
echo
}
function error_exit {
echo "$1" 1>&2
exit 1
}
function get_phase {
fn=$LOG_FN
if [ -f $fn ]; then
ph=`tail -n 1 $fn`
else
echo "0 0" > $fn
ph="0 0"
fi
# return
phase=`echo $ph | awk '{print $1}'`
subph=`echo $ph | awk '{print $2}'`
}
function cfg_phase {
ist_phase=$nxt_phase
get_phase
nxt_phase=`echo $((ist_phase+1))`
}
function cfg_subph {
ist_subph=$nxt_subph
get_phase
nxt_subph=`echo $((ist_subph+1))`
title "$TITLE -> $ist_subph"
}
function rm_f {
fn=$1
if [ -f $fn ]; then
rm -r $fn
fi
}
function rm_d {
dn=$1
if [ -d $dn ]; then
rm -r $dn
fi
}
function finish {
get_phase
if [ $subph -eq $nxt_subph ]; then
echo "$nxt_phase 0" >> $LOG_FN
fi
}
function finish_subph {
cd $INSTALL_PATH
if [ $subph -eq $ist_subph ]; then
echo "$phase $nxt_subph" >> $LOG_FN
fi
if [ $phase -eq $PHASE_ED -a $subph -eq $SUBPH_ED ]; then
exit
fi
}
# =========================
# CHECK VERSION
# =========================
function normalize_version {
version=$1
echo $version | awk -F '.' '{print $1" "$2" "$3" x x x"}' | awk '{print $1"."$2"."$3}'
}
function match_version {
name=$1 #
version_target=$2 #target version
version=$3 #version
version_target=`normalize_version $version_target`
version=`normalize_version $version`
#
RT_MATCH_VERSION=0
if [ $version = "x.x.x" ]; then
echo -e "$FLAG_FALSE $name is not installed"
RT_MATCH_VERSION=0
else
if [ $version = $version_target ]; then
echo -e "$FLAG_RIGHT $name==$version : Recommended version==$version_target "
RT_MATCH_VERSION=1
else
echo -e "$FLAG_NRIGHT $name==$version : Recommended version==$version_target "
RT_MATCH_VERSION=2
fi
fi
}
function find_cmd {
#find command, such as git, bazel
cmd=$1
RT_FIND_CMD=1
which $cmd || RT_FIND_CMD=0
if [ $RT_FIND_CMD -eq 0 ]; then
echo -e "${FLAG_FALSE} $cmd"
else
echo -e "${FLAG_RIGHT} $cmd"
fi
}
function find_env {
#find environment created by conda
env=$1
RT_FIND_ENV=1
conda env list | grep "$env\ " || RT_FIND_ENV=0
if [ $RT_FIND_ENV -eq 0 ]; then
echo -e "${FLAG_FALSE} $env"
else
echo -e "${FLAG_RIGHT} $env"
fi
}
function pip_check_install {
name=$1
version_target=$2
version=`pip list | grep "$name\ " | awk '{print $2}'`
match_version $name $version_target $version
if [ $RT_MATCH_VERSION -eq 0 ]; then
echo "pip install $name==$version_target"
pip install $name==$version_target || error_exit "$LINENO: failed"
version=`pip list | grep "$name\ " | awk '{print $2}'`
match_version $name $version_target $version
fi
}
# =========================
# INSTAL PHASE
# =========================
function install_dependency
{
title "install dependency"
# conda
find_cmd conda
if [ $RT_FIND_CMD -eq 0 ]; then
echo "Please install conda"
exit
fi
# gcc
version=`gcc --version | grep gcc | awk '{print $NF}'`
match_version gcc $GCC_VERSION $version
if [ $RT_MATCH_VERSION -ne 1 ]; then
echo "Please install Recommended gcc==$GCC_VERSION"
sleep 1
fi
# git
find_cmd git
if [ $RT_FIND_CMD -eq 0 ]; then
echo "Install git by conda"
conda install git
fi
# env
CONDA_ENV=`conda info | grep "active\ environment" | awk '{print $NF}'`
if [ $CONDA_ENV = "None" ]; then
echo "Please create a conda environment and activate it: such as"
echo "\$ conda create -n nvnmd"
echo "\$ conda activate nvnmd"
exit
fi
ENV_PATH=`conda info | grep "active\ env\ location" | awk '{print $NF}'`
echo "conda environment is : $CONDA_ENV"
echo "environment location is : $ENV_PATH"
# python
# find_cmd python
version=`python --version | awk '{print $NF}'`
match_version python $PYTHON_VERSION $version
if [ $RT_MATCH_VERSION -ne 1 ]; then
echo "conda install python==$PYTHON_VERSION"
conda install python==$PYTHON_VERSION || error_exit "$LINENO: failed"
find_cmd python
fi
version=`python --version | awk '{print $NF}'`
match_version python $PYTHON_VERSION $version
}
function install_cmake
{
title "install cmake"
nxt_subph=0
cfg_subph
if [ $subph -eq $ist_subph ]; then
rm_d $INSTALL_PATH/cmake
mkdir -p $INSTALL_PATH/cmake
cp $PACKAGE/$CMAKE.tar.gz cmake
cd cmake
tar -zxf $CMAKE.tar.gz
rm -r $CMAKE.tar.gz
cd $CMAKE
cp $PATCH/cmake/* .
fi
finish_subph
cfg_subph
if [ $subph -eq $ist_subph ]; then
cd cmake/$CMAKE
chmod +x ./bootstrap
./bootstrap || error_exit "$LINENO: failed"
fi
finish_subph
cfg_subph
if [ $subph -eq $ist_subph ]; then
cd cmake/$CMAKE
make || error_exit "$LINENO: failed"
sudo make install || error_exit "$LINENO: failed"
fi
finish_subph
}
function install_tensorflow {
title "install tensorflow"
nxt_subph=0
cfg_subph
if [ $subph -eq $ist_subph ]; then
RT_FIND_TF=1
ls $ENV_PATH/lib/libtensorflow_cc.so* || RT_FIND_TF=0
if [ $RT_FIND_TF -eq 0 ]; then
echo -e "${FLAG_FALSE} have not installed libtensorflow_cc"
echo "installed libtensorflow_cc"
#conda search libtensorflow_cc -c deepmodeling
conda install libtensorflow_cc=$LIBTF_CC_VERSION=$LIBTF_CC_BUILD -c deepmodeling || error_exit "$LINENO: failed"
fi
fi
finish_subph
cfg_subph
if [ $phase -eq $ist_subph ]; then
pip_check_install tensorflow $TENSORFLOW_VERSION || error_exit "$LINENO: failed"
fi
finish_subph
}
function install_nvnmd {
title "install nvnmd"
nxt_subph=0
cfg_subph
if [ $subph -eq $ist_subph ]; then
pip_check_install matplotlib 3.5.1 || error_exit "$LINENO: failed"
pip_check_install ase 3.22.1 || error_exit "$LINENO: failed"
fi
finish_subph
cfg_subph
if [ $subph -eq $ist_subph ]; then
rm_d $INSTALL_PATH/$NVNMD_PATH
mkdir -p $INSTALL_PATH/$NVNMD_PATH
cp $PACKAGE/nvnmd.tar.gz $NVNMD_PATH
cd $NVNMD_PATH
tar -zxf $NVNMD.tar.gz
rm -r $NVNMD.tar.gz
# patch
if [ -d $PATCH/nvnmd ]; then
cp -r $PATCH/nvnmd/* nvnmd
fi
fi
finish_subph
cfg_subph
if [ $subph -eq $ist_subph ]; then
cd $NVNMD_PATH/nvnmd
cd ./source
rm_d build
mkdir build
cd build
$CMAKE_BIN/cmake -DTENSORFLOW_ROOT=$ENV_PATH -DCMAKE_INSTALL_PREFIX=$NVNMD_BIN .. || error_exit "$LINENO: failed"
make -j $CPU_CORE || error_exit "$LINENO: failed"
make install || error_exit "$LINENO: failed"
fi
finish_subph
cfg_subph
if [ $subph -eq $ist_subph ]; then
cd $NVNMD_PATH/nvnmd/
pip install . || error_exit "$LINENO: failed"
if [ -f "./deepmd/nvnmd/__main__.py" ]; then
echo "python $INSTALL_PATH/$NVNMD_PATH/nvnmd/deepmd/nvnmd/__main__.py \$@" > $ENV_PATH/bin/nvnmd
chmod +x $ENV_PATH/bin/nvnmd
fi
fi
finish_subph
}
function help {
echo "bash install.sh [-i \"PHASE_ST SUBPH_ST PHASE_ED SUBPH_ED\"] "
echo " [-p NVNMD_PATH]"
echo "PHASE:"
echo "phase 0 : install cmake : 0-3"
echo "phase 1 : install tensorflow and libtensorflow_cc : 0-2"
echo "phase 2 : install nvnmd : 0-4"
echo "phase 3 : finish : 0"
exit
}
# =========================
# MAIN
# =========================
get_phase
# get the parameter
while getopts 'i:p:' OPT; do
case $OPT in
i)
PHASE_ST=`echo "$OPTARG" | awk '{print $1}'`
SUBPH_ST=`echo "$OPTARG" | awk '{print $2}'`
PHASE_ED=`echo "$OPTARG" | awk '{print $3}'`
SUBPH_ED=`echo "$OPTARG" | awk '{print $4}'`
;;
p)
NVNMD_PATH=`echo "$OPTARG" | awk '{print $1}'`
;;
*)
help
;;
esac
done
echo ""
echo "$PHASE_ST $SUBPH_ST $PHASE_ED $SUBPH_ED $NVNMD_PATH"
echo "$PHASE_ST $SUBPH_ST" >> $LOG_FN
sleep 2
title "install "
echo "(1) install_dependency"
echo "(2) install_cmake"
echo "(3) install_tensorflow"
echo "(4) install_nvnmd"
cd $INSTALL_PATH
nxt_phase=0
# dependency
install_dependency
# cmake
cfg_phase
if [ $ist_phase -eq $phase ]; then
install_cmake
finish
fi
# tensorflow
cfg_phase
if [ $ist_phase -eq $phase ]; then
install_tensorflow
finish
fi
# nvnmd
cfg_phase
if [ $ist_phase -eq $phase ]; then
install_nvnmd
finish
fi
# finish
cfg_phase
if [ $ist_phase -eq $phase ]; then
echo -e "$HEAD_INFO: Finish"
fi