-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_catapult.sh
532 lines (490 loc) · 18.1 KB
/
install_catapult.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
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
#!/bin/bash
# Install and build Symbol catapult server and dependancies interactive script version v1.0
# Copyright (c) 2020 superhow, ministras, SUPER HOW UAB licensed under the GNU Lesser General Public License v3
set -e
SCRIPT_VER=1.S
SSH_PORT=22
CAT_VER=0.9.6.3
cmake_ver=3.17.0
boost_v=1_72_0
boost_ver=1.72.0
openssl_ver=1.1.1g
cd
[ -d $HOME/src ] && echo "Directory src Exists" || mkdir $HOME/src
# echo "Be sure to use screen before running. There will be several prompts for sudo password"
# echo "This script is prepared to be executed with user 'root' or any other user"
function print_menu() {
#clear
echo
echo
echo "+================================================================+"
echo "| Symbol CATAPULT install and build script by SUPER HOW? |"
echo "| - build and install Symbol CATAPULT dependancies |"
echo "| - build and install Symbol CATAPULT v${CAT_VER} |"
echo "|+ +|"
echo "| Prerequisites from github/nemtech for building on Ubuntu 18.04 |"
echo "| - OpenSSL dev library, at least 1.1.1 (libssl-dev) |"
echo "| - cmake (at least 3.17) |"
echo "| - python 3.x |"
echo "| - gcc 9.2 |"
echo "| - ninja-build |"
echo "| |"
echo "+================================================================+"
echo "| Script version: v${SCRIPT_VER} |"
echo "| Crafted with love by: ministras, linas and bruce_wayne |"
echo "| 2020 (C) https://SUPERHOW.io |"
echo "+================================================================+"
os_version_check
echo "+================================================================+"
echo "| MENU: |"
echo "| |"
echo "| 1) Step 1: Build System dependencies: GCC, Cmake, Boost, etc. |"
echo "| 2) Step 2: Build CAT dependencies: gtest, mongocxx, rocksdb.. |"
echo "| 3) Step 3: Build Symbol CATAPULT mijin from git |"
echo "| 4) Step 4: Build mongodb v4.2.8 |"
echo "| 5) Step 5: Build NODE.JS and CATAPULT REST |"
echo "| 6) Step 6: Generate keys and instialize CATAPULT seed |"
echo "| 9) Setup Firewall and change SSH port (TODO) |"
echo "| 0) Tool: Just do system update & upgrade |"
echo "| |"
echo "| 80) Hostname |"
echo "| 91) Reboot |"
echo "| 92) Shutdown |"
echo "| 100) Print menu |"
echo "| |"
echo "| q) Quit |"
echo "+================================================================+"
echo
}
function os_version_check() {
if [[ -r /etc/os-release ]]; then
. /etc/os-release
# echo -e "Version ${VERSION_ID}"
echo -e "OS & Version: ${PRETTY_NAME}"
if [[ "${VERSION_ID}" != "16.04" ]] && [[ "${VERSION_ID}" != "18.04" ]] ; then
echo "WARNING: Script is compatible with ONLY Ubuntu 16.04 or Ubuntu 18.04"
fi
fi
}
function build_base() {
clear
echo "+================================================================+"
echo "| UPDATE system, install base System dependancies? [y/n] |"
echo "| GCC-9, Boost v${boost_ver}, Cmake v${cmake_ver}"
echo "+================================================================+"
read DOINSTALL
if [[ $DOINSTALL =~ "y" ]] || [[ $DOINSTALL =~ "Y" ]] ; then
# change_ssh_port
# firewall_setup
set -x
do_system_update
install_dependancies
install_cmake
install_boost
#install_openssl
set +x
fi
}
function do_system_update() {
sudo apt-get update
sudo apt-get --yes upgrade
sudo apt-get --yes autoremove
}
function install_dependancies() {
sudo apt-get --yes install autoconf automake build-essential checkinstall curl gdb mc ninja-build pkg-config python python-dev
sudo apt-get --yes install libtool libssl-dev libatomic-ops-dev libunwind-dev libgflags-dev libsnappy-dev libxml2-dev libxslt-dev zlib1g-dev zsh xz-utils
#TODO check if these are needed: libatomic-ops-dev libunwind-dev libgflags-dev libsnappy-dev libxml2-dev libxslt-dev
#Install new version of GCC v9.2: https://linuxize.com/post/how-to-install-gcc-compiler-on-ubuntu-18-04/
sudo -E apt-get --yes install software-properties-common
sudo -E add-apt-repository --yes ppa:ubuntu-toolchain-r/test
sudo -E add-apt-repository --yes ppa:deadsnakes/ppa
sudo -E apt update
sudo -E apt-get --yes install gcc-9 g++-9 python3.8 python3-ply
sudo -E apt-get --yes autoremove
#register priority default GCC versions
sudo -E update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90
sudo -E update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90
}
function install_cmake() {
# v3.17.0
echo
echo "Installing Cmake ${cmake_ver}"
echo
cd $HOME/src/
sudo apt-get --yes purge cmake
sudo apt-get --yes autoremove
wget https://github.com/Kitware/CMake/releases/download/v${cmake_ver}/cmake-${cmake_ver}.tar.gz
tar -xzvf cmake-${cmake_ver}.tar.gz
rm cmake-${cmake_ver}.tar.gz
cd cmake-${cmake_ver}/
./bootstrap
make -j $(nproc)
sudo make install
echo
echo "Check CMAKE version:"
echo
cd && cmake --version
python --version
python3 --version
gcc --version
#rm -rf cmake-${cmake_ver}/
}
function install_boost() {
# Boost - c++ v1.72.0
echo
echo "Installing BOOST ${boost_ver}"
echo
sudo rm -rf /opt/boost/
mkdir $HOME/boost
sudo -E mv $HOME/boost /opt/boost
cd $HOME/src/
wget https://dl.bintray.com/boostorg/release/${boost_ver}/source/boost_${boost_v}.tar.gz
tar -xzf boost_${boost_v}.tar.gz
rm boost_${boost_v}.tar.gz
cd boost_${boost_v}/
./bootstrap.sh --prefix=/opt/boost
./b2 --prefix=/opt/boost --without-python -j $(nproc) stage release
./b2 --prefix=/opt/boost --without-python install
#rm -rf boost_${boost_v}/
}
function install_openssl() {
# OpenSSL v1.1.1g
echo
echo "Installing OpenSSL ${openssl_ver}"
echo
openssl version -a
cd $HOME/src/
wget https://www.openssl.org/source/openssl-${openssl_ver}.tar.gz
tar -xf openssl-${openssl_ver}.tar.gz
rm openssl-${openssl_ver}.tar.gz
cd openssl-${openssl_ver}
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
make
make test
sudo make install
#Configure OpenSSl shared libraries
echo "/usr/local/ssl/lib" | sudo tee /etc/ld.so.conf.d/openssl-${openssl_ver}.conf
# Reload dynamic link
sudo ldconfig -v
# Configure OpenSSL Binary
sudo mv /usr/bin/c_rehash /usr/bin/c_rehash.backup
sudo mv /usr/bin/openssl /usr/bin/openssl.backup
sudo nano /etc/environment
#PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/ssl/bin"
source /etc/environment
echo $PATH
which openssl
openssl version -a
}
function build_dependancies() {
clear
echo
echo "+================================================================+"
echo "| Build Catapult DEPENDANCIES, build TOOLS? [y/n] |"
echo "| gtest, benchmark, mongoc, zmq tools and drivers |"
echo "+================================================================+"
echo
read DOINSTALL
if [[ $DOINSTALL =~ "y" ]] || [[ $DOINSTALL =~ "Y" ]] ; then
set -x
sudo apt-get update
build_gtest
build_benchmark
build_mongoc
build_mongocxx
build_zmq
build_rocksdb
set +x
fi
}
function build_gtest() {
# Gtest
cd $HOME/src/ && git clone https://github.com/google/googletest.git
cd googletest/
git checkout release-1.8.1
mkdir _build && cd _build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON ..
make
sudo make install
}
function build_benchmark() {
# Google benchmark
cd $HOME/src/ && git clone https://github.com/google/benchmark.git
cd benchmark/
git checkout v1.5.0
mkdir _build && cd _build
cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_GTEST_TESTS=OFF ..
make
sudo make install
}
function build_mongoc() {
# Mongo driver mongo-c
cd $HOME/src/ && git clone https://github.com/mongodb/mongo-c-driver.git
cd mongo-c-driver/
git checkout 1.15.1
mkdir _build && cd _build
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
}
function build_mongocxx() {
# Mongo driver mongo-c++
cd $HOME/src/ && git clone https://github.com/nemtech/mongo-cxx-driver.git
cd mongo-cxx-driver/
git checkout r3.4.0-nem
#TODO: find out why do we need maxAwaitTimeMS patch...
#sed -i 's/kvp("maxAwaitTimeMS", count)/kvp("maxAwaitTimeMS", static_cast<int64_t>(count))/' src/mongocxx/options/change_stream.cpp
mkdir _build && cd _build
#cmake -DCMAKE_CXX_STANDARD=17 -DLIBBSON_DIR=/usr/local -DLIBMONGOC_DIR=/usr/local -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
}
function build_zmq() {
# ZMQ libzmq
cd $HOME/src/ && git clone https://github.com/zeromq/libzmq.git
cd libzmq/
git checkout v4.3.2
mkdir _build && cd _build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
# ZMQ cppzmq
cd $HOME/src/ && git clone https://github.com/zeromq/cppzmq.git
cd cppzmq/
git checkout v4.4.1
mkdir _build && cd _build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
}
function build_rocksdb() {
# RocksDB
cd $HOME/src/ && git clone https://github.com/nemtech/rocksdb.git
cd rocksdb/
git checkout v6.6.4-nem
mkdir _build
# && cd _build
# cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=OFF . -DCMAKE_INSTALL_PREFIX=/usr/local ..
# make
sudo make install-shared
}
function build_catapult() {
clear
echo
echo "+================================================================+"
echo "| Build catapult server v${CAT_VER} from git? [y/n]"
echo "+================================================================+"
echo
read DOINSTALL
if [[ $DOINSTALL =~ "y" ]] || [[ $DOINSTALL =~ "Y" ]] ; then
set -x
sudo apt-get update
build_catapult_server
set +x
fi
}
function build_catapult_server() {
# Build CATAPULT server
[ -d /opt/catapult ] && echo "Directory Exists" || mkdir $HOME/catapult
[ -d /opt/catapult ] && echo "Directory Exists" || sudo -E mv $HOME/catapult /opt/catapult
mkdir $HOME/catapult
mkdir /opt/catapult/tests
cd $HOME/src/ && git clone https://github.com/nemtech/catapult-server.git
cd catapult-server/
git checkout v${CAT_VER}
mkdir _build && cd _build
cmake -DBOOST_ROOT=/opt/boost -DCMAKE_BUILD_TYPE=Release -G Ninja ..
# bootstrapinam boost root i /opt/boost, install i /opt/catapult reikia pabandyti
ninja publish
ninja -j $(nproc)
mv $HOME/src/catapult-server/_build/bin /opt/catapult/bin
cp -r $HOME/src/catapult-server/scripts $HOME/catapult/scripts
cp -r $HOME/src/catapult-server/scripts /opt/catapult/scripts
mv /opt/catapult/bin/tests* /opt/catapult/tests/
}
function install_mongo() {
clear
echo
echo "+================================================================+"
echo "| Install MONGODB v4.2.8? [y/n]"
echo "| CATAPULT version: ${CAT_VER}"
echo "+================================================================+"
echo
read DOINSTALL
if [[ $DOINSTALL =~ "y" ]] || [[ $DOINSTALL =~ "Y" ]] ; then
set -x
install_mongodb
set +x
fi
}
function install_mongodb() {
# Remove old MongoDB
cd
#sudo systemctl stop mongodb
#sudo systemctl disable mongodb
#sudo apt-get -y remove mongodb
#sudo apt-get -y autoremove
#sudo rm -rf /var/log/mongodb
#sudo rm -rf /var/lib/mongodb
#sudo rm -rf /etc/systemd/system/mongo.service
#sudo systemctl daemon-reload
#sudo systemctl reset-failed
# Install MongoDB 4.2. MANDATORY only API
curl -sL https://www.mongodb.org/static/pgp/server-4.2.asc | sudo -E apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod
}
function install_rest() {
clear
echo
echo "+================================================================+"
echo "| Install NODE.JS v12, CATAPULT REST? [y/n]"
echo "| CATAPULT version: ${CAT_VER}"
echo "+================================================================+"
echo
read DOINSTALL
if [[ $DOINSTALL =~ "y" ]] || [[ $DOINSTALL =~ "Y" ]] ; then
set -x
#install_mongodb
install_node_js
install_catapult_rest
set +x
fi
}
function install_node_js() {
# Install Node.js v12 & yarn for REST API
cd
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get --yes install nodejs
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo -E apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get --yes install yarn
}
function install_catapult_rest() {
# Install REST API
cd && git clone https://github.com/nemtech/catapult-rest.git
cd catapult-rest/
git checkout v1.1.3
./yarn_setup.sh
cd rest/
yarn build
}
function init_seed() {
clear
echo
echo "+================================================================+"
echo "| Generate GENESIS keys and initialize CATAPULT seed? [y/n]"
echo "| CATAPULT version: ${CAT_VER}"
echo "+================================================================+"
echo
read DOINSTALL
if [[ $DOINSTALL =~ "y" ]] || [[ $DOINSTALL =~ "Y" ]] ; then
set -x
generate_accounts
initialize_seed
set +x
fi
}
function generate_accounts() {
clear
echo
echo "+================================================================+"
echo "| How many accounts you need? [3-10]"
echo "+================================================================+"
echo
read ACCOUNT_COUNT
# Generate 3 accounts for "nemesis_signer" , "node owner" and "REST owner"!!!
# Generate 3 additional accounts for "api owner", peer1 owner" and "peer2 owner"!!!
cd $HOME/catapult/
# catapult-node && mkdir data && mkdir nemesis && mkdir resources && mkdir scripts && mkdir seed
/opt/catapult/bin/catapult.tools.address -g ${ACCOUNT_COUNT} --network mijin | tee $HOME/catapult/nemesis_signer.txt
}
function initialize_seed() {
cd $HOME/catapult/scripts
git clone https://github.com/superhow/cat-config.git
# First private and public keys from the file ~/catapult/nemesis_signer.txt --local (local node) --dual (peer & api in one)
cd $HOME/catapult/
# zsh scripts/cat-config/reset.sh --local dual ~/catapult <private_key> <public_key>
}
# # === Firewall ===
# function firewall_setup() {
# echo "********** FIREWALL SETUP **************"
# sudo apt-get install -y ufw
# #sudo ufw allow OpenSSH
# sudo ufw default deny
# #sudo ufw allow ssh/tcp
# #sudo ufw limit ssh/tcp
# sudo ufw logging on
# #sudo ufw allow 22
# sudo ufw limit $SSH_PORT/tcp
# #sudo ufw limit OpenSSH
# echo "y" | sudo ufw enable
# #sudo ufw status
# }
#
# function change_ssh_port() {
# echo "Do you want to change SSH port? [y/n]"
# read DOSSHPORT
# if [[ $DOSSHPORT =~ "y" ]] || [[ $DOSSHPORT =~ "Y" ]] ; then
# sudo nano /etc/ssh/sshd_config
# # --- surasti #port.. ir nuimti # ir pakeisti porta i
# # --- port 4513
# sudo systemctl restart ssh
# fi
# }
while [[ $DOACTION != "q" ]]
do
print_menu
echo "*********************************"
read DOACTION
echo "*********************************"
if [[ $DOACTION == "1" ]] ; then
build_base
fi
if [[ $DOACTION == "2" ]] ; then
build_dependancies
fi
if [[ $DOACTION == "3" ]] ; then
build_catapult
fi
if [[ $DOACTION == "4" ]] ; then
install_mongo
fi
if [[ $DOACTION == "5" ]] ; then
install_rest
fi
if [[ $DOACTION == "6" ]] ; then
init_seed
fi
if [[ $DOACTION == "9" ]] ; then
do_firewall_and_ssh
fi
if [[ $DOACTION == "0" ]] ; then
do_system_update
fi
if [[ $DOACTION == "80" ]] ; then
hostname -a
hostname -i
hostname -I
fi
if [[ $DOACTION == "91" ]] ; then
sudo reboot
fi
if [[ $DOACTION == "92" ]] ; then
sudo shutdown -h now
fi
if [[ $DOACTION == "100" ]] ; then
print_menu
fi
done