-
Notifications
You must be signed in to change notification settings - Fork 13
/
1_prerequisite.bash
executable file
·256 lines (250 loc) · 8.65 KB
/
1_prerequisite.bash
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
#!/bin/bash
tryCatch()
{
FNARG=("$@")
echo ${FNARG[@]}
IFS=',' read -ra GO_array <<< "${FNARG[@]}"
for i in "${GO_array[@]}"
do
CMD=`$i`
CMD_check=$?
if [ $CMD_check -eq 0 ]
then
echo "$i: passed"
else
echo "$i: failed"
echo "Fix the failure and restart the script"
echo "Plugin installation: Abort"
exit 1
fi
done
}
echo `date` >>time.txt
START=$(date +%s);
#########################################OS check
echo "Setting up your local Plugin Node"
OS=`lsb_release -d | cut -f 2 | cut -d ' ' -f 1| grep -i 'ubuntu'`
OS_STATUS=$?
OS_VERSION=`lsb_release -r|cut -f 2|cut -d '.' -f 1`
if [ $OS_VERSION -ge 18 ] && [ $OS_STATUS -eq 0 ]
then
echo "OS Compatibilty check: passed"
else
echo "Your OS $OS $OS_VERSION is not compatible for Plugin installation\nOS compatibility check: failed\nRefer the doc provided"
exit 1
fi
#########################################
#########################################GO installation
GO=(
'curl -O https://dl.google.com/go/go1.17.3.linux-amd64.tar.gz',
#'curl -O https://go.dev/dl/go1.17.3.linux-amd64.tar.gz',
#'curl -O https://dl.google.com/go/go1.15.13.linux-amd64.tar.gz',
#'sha256sum go1.15.13.linux-amd64.tar.gz',
'sha256sum go1.17.3.linux-amd64.tar.gz',
'tar xvf go1.17.3.linux-amd64.tar.gz',
#'tar xvf go1.15.13.linux-amd64.tar.gz',
'sudo chown -R root:root ./go',
'sudo mv go /usr/local'
)
echo "<<<<<<<<<------------------Installing Go packages -- STEP 1/9 Started--------------------->>>>>>>>>"
tryCatch ${GO[@]}
echo "export GOROOT=/usr/local/go
export GOPATH=\$HOME/work
export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin" >> ~/.profile
GO_var_set=$?
if [ $GO_var_set -eq 0 ]
then
echo "Go env var set: passed"
else
echo "Go env var set: failed"
echo "Fix the error"
exit 1
fi
. ~/.profile
if [ $? -eq 0 ]
then
echo "Profile run set: passed"
else
echo "Profile run set: failed"
echo "Fix the error"
exit 1
fi
GO_VERSION=`go version`
echo "<<<<<<<<<------------------$GO_VERSION installed successfully -- STEP 1/9 Completed--------------------->>>>>>>>>"
#########################################
#########################################NodeJs installation
Nodejs=(
'curl https://deb.nodesource.com/setup_15.x -o setup_15.x',
'sudo chmod 775 setup_15.x',
'sudo -E ./setup_15.x',
'sudo apt-get install -y nodejs'
)
echo "Installing NodeJs -- STEP 2/9 Started"
tryCatch ${Nodejs[@]}
NODE_VERSION=`node -v`
NPM_VERSION=`npm -v`
echo "Node version $NODE_VERSION and Npm version $NPM_VERSION installed successfully -- STEP 2/9 Completed--------------------->>>>>>>>>"
#########################################
#########################################NVM installation
NVM=(
'curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh -o install.sh',
'sudo chmod 775 install.sh',
'./install.sh'
)
echo "<<<<<<<<<------------------Installing NVM -- STEP 3/9 Started"
tryCatch ${NVM[@]}
#Close and open fix and not taking from script
NVM_VERSION=`nvm -v`
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
echo "<<<<<<<<<------------------NVM version $NVM_VERSION installed successfully -- STEP 3/9 Completed--------------------->>>>>>>>>"
#########################################
#########################################Yarn installation
echo "<<<<<<<<<------------------Installing Yarn -- STEP 4/9 Started--------------------->>>>>>>>>"
YARN=`sudo npm install --global yarn`
if [ $? -eq 0 ]
then
echo "Yarn installation: passed"
else
echo "Yarn installation: failed"
echo "Fix the error"
exit 1
fi
YARN_VERSION=`yarn -v`
echo "<<<<<<<<<------------------Yarn version $YARN_VERSION installed successfully -- STEP 4/9 Completed--------------------->>>>>>>>>"
#########################################
#########################################Postgresql installation
PG=(
'sudo apt-get install -y postgresql-12',
'sudo systemctl start postgresql@12-main'
)
echo "<<<<<<<<<------------------Installing Postgres -- STEP 5/9 Started--------------------->>>>>>>>>"
PG1=`sudo apt-get install -y postgresql-12`
if [ $? -eq 0 ]
then
echo "postgresql-12: passed"
else
echo "postgresql-12: failed"
echo "Fix the error"
exit 1
fi
PG2=`sudo systemctl start postgresql@12-main`
if [ $? -eq 0 ]
then
echo "postgresql@12-main: passed"
else
echo "postgresql@12-main: failed"
echo "Fix the error"
exit 1
fi
POSTGRES_VERSION=`psql -V`
echo "<<<<<<<<<------------------Postgres version $POSTGRES_VERSION installed successfully -- STEP 5/9 Completed--------------------->>>>>>>>>"
#########################################
#########################################Plugin installation
echo "<<<<<<<<<------------------Downloading Plugin and setting it up - STEP 6/9 Started--------------------->>>>>>>>>"
PLI=(
'git clone https://github.com/GoPlugin/Plugin.git'
)
tryCatch ${PLI[@]}
cd Plugin
if [ $? -eq 0 ]
then
echo "cd Plugin: passed"
else
echo "cd Plugin: failed"
echo "Fix the error"
exit 1
fi
sudo apt install make
if [ $? -eq 0 ]
then
echo "apt install make: passed"
else
echo "apt install make: failed"
echo "Fix the error"
exit 1
fi
sudo apt-get install -y build-essential
if [ $? -eq 0 ]
then
echo "build-essential: passed"
else
echo "build-essential: failed"
echo "Fix the error"
exit 1
fi
make install
if [ $? -eq 0 ]
then
echo "make install: passed"
else
echo "make install: failed"
echo "Fix the error"
exit 1
fi
echo "<<<<<<<<<------------------Downloading Plugin and setting it up - STEP 7/9 Completed--------------------->>>>>>>>>"
#########################################
#########################################Database creation
echo "<<<<<<<<<------------------Creating database - STEP 8/9 Started--------------------->>>>>>>>>"
sudo -u postgres psql -c "create database plugin_mainnet_db"
if [ $? -eq 0 ]
then
echo "plugin_db creation: passed"
else
echo "plugin_db creation: failed"
exit 1
fi
sudo -u postgres psql -c "alter user postgres PASSWORD 'postgres'"
if [ $? -eq 0 ]
then
echo "Alter DB: passed"
else
echo "Alter DB: failed"
exit 1
fi
echo "<<<<<<<<<------------------Creating database - STEP 9/9 Completed--------------------->>>>>>>>>"
#########################################
#########################################npm installation
echo "<<<<<<<<<------------------pm2 installation Started--------------------->>>>>>>>>"
sudo npm install -g pm2
if [ $? -eq 0 ]
then
echo "pm2 installation: passed"
else
echo "pm2 installation: failed"
exit 1
fi
echo "<<<<<<<<<------------------pm2 installation Completed--------------------->>>>>>>>>"
#########################################Plugin Node kickstart
#cd Plugin
echo `date` >>time.txt
END=$(date +%s);
echo "Time taken for execution: $((END-START)) seconds"
#########################################
echo "<<<<<<<<<------------------SET UP COMPLETED--------------------->>>>>>>>>"
echo "
################################################################################
# IMPORTANT MESSAGE #
################################################################################
# Make sure you have the below mentioned 2 files are available and populated #
# as given below. Then start 'pm2 start 2_nodeStartPM2.sh' script to run your#
# node in the background. To view your node log use 'pm2 logs 0'. #
# #
# File 1: password.txt => contains your keystore password #
# *** KEYSTORE PASSWORD SHOULD FOLLOW THIS CONDITIONS *** #
# “must be longer than 12 characters”, #
# “must contain at least 3 lowercase characters”, #
# “must contain at least 3 uppercase characters”, #
# “must contain at least 3 numbers”, #
# “must contain at least 3 symbols”, #
# “must not contain more than 3 identical consecutive #
# characters”. #
# File 2: apicredentials.txt => first line of the file contians email id for UI#
# second line of the file contains password for UI#
# (This passwrod should be strong, but need not #
# follow keystore password condition). #
# #
# NOTE: This 2 files have default contents, please change the mail & passwords #
# before starting 'pm2 start 2_nodeStartPM2.sh'. #
################################################################################
################################################################################"