/
install.sh
300 lines (258 loc) · 12.4 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
#!/bin/bash
#created by mrgr. Please consider to vote for mrgr delegate
RED='\033[1;31m'
YELLOW='\033[1;33m'
GREEN='\033[1;32m'
CYAN='\033[1;36m'
OFF='\033[0m' # No Color
NOW=$(date +"%H:%M")
LOCAL_TIME=0
OK=1
echo "----------------------------------------"
echo "Welcome to the antifork installation"
echo -e "Don't forget to vote for ${YELLOW}mrgr${OFF} delegate"
echo "----------------------------------------"
echo "We need to configure some variables."
echo " "
if [ -f "$1" ]; then
case $1 in
"main")
echo "You are installing this script for mainnet"
VERSION="lisk-main"
;;
"test")
echo "You are installing this script for testnet"
VERSION="lisk-test"
;;
"--alerts-off")
echo "You are installing this script for mainnet"
VERSION="lisk-main"
ALERTS_OFF="true"
;;
*)
echo "You are installing this script for mainnet"
VERSION="lisk-main"
;;
esac
else
echo "You are installing this script for mainnet"
echo "If you want to change this script to testnet please stop this installation and start again with:"
echo "bash install.sh test"
VERSION="lisk-main"
fi
if [ -f "configtoolisk.sh" ]; then
read -p "**A previous installation was detected, do you want to proceed anyway (y/n)?" -n 1 -r
if [[ $REPLY =~ ^[Nn]$ ]]
then
OK=0
fi
fi
if [[ $OK -eq 1 ]]
then
if [ "$ALERTS_OFF" != "true" ]; then
echo "The following is needed if you want alerts in your email"
echo "Please enter the following information:"
echo -n "Api key: "
read API_KEY
echo -n "Default SMTP Login: "
read MG_FROM
echo -n "API Base URL: "
read MAILGUN
echo -n "Email to: "
read MG_TO
read -p "Is this information correct (y/n)?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo " "
echo -e "Email information set. Alerts will sent to: $MG_TO"
else
echo " "
echo "Please run the installer again"
exit 1
fi
fi
read -p "How many servers are you using (1 or 2)?" -n 1 -r
if [[ $REPLY =~ ^[12]$ ]]
then
echo
if [ "$REPLY" -eq "2" ]; then
echo "Now we are going to configure the failover settings."
echo "Please enter the folling information (of your backup server): "
echo -n "IP: "
read IP_SERVER
echo -n "Port: "
read PORT
HTTP="0"
read -p "Is https enabled (y/n)?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
HTTP="https"
else
HTTP="http"
fi
echo
else
echo
echo -e "${YELLOW}WARNING!${OFF} This scripts works better with 2 servers. You can continue installing it and this script will do his best for you with one server"
echo
fi
else
echo " "
echo "Please run the installer again and select only the numer 1 or numer 2"
exit 1
fi
read -p "Is https enabled in your localhost (y/n)?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
HTTP_LOCAL="https"
else
HTTP_LOCAL="http"
fi
echo
echo -n "In which port are you running $VERSION $HTTP_LOCAL: "
read LOCAL_PORT
echo " "
echo " "
echo "Now enter the information of your delegate."
echo -n "Delegate name: "
read DELEGATE_NAME
echo -n "Delegate address: "
read DELEGATE_ADDRESS
RESPONSE=$(curl -s http://localhost:8000/api/accounts/delegates?address=$DELEGATE_ADDRESS | jq '.delegates[] | select(.username=="'$DELEGATE_NAME'")')
v1=$(echo $RESPONSE | jq '.publicKey')
PUBLICKEY="${v1//\"/}"
echo -n "Delegate passphrase: "
read SECRET
echo -n "How you identify this server? (e.g. Main Server/Backup1): "
read SERVER_NAME
init=configtoolisk.sh
echo " "
echo "#Config file" > $init
echo "#toolisk variables" >> $init
echo "RED='\033[1;31m'" >> $init
echo "YELLOW='\033[1;33m'">> $init
echo "GREEN='\033[1;32m'" >> $init
echo "CYAN='\033[1;36m'" >> $init
echo "OFF='\033[0m' # No Color" >> $init
echo "VERSION=\"$VERSION\"" >> $init
echo "API_KEY=\"$API_KEY\" #your mailgun API key" >> $init
echo "MG_FROM=\"$MG_FROM\" #Default SMTP Login" >> $init
echo "MAILGUN=\"$MAILGUN/messages\" #API Base URL" >> $init
echo "MG_TO=\"$MG_TO\" #Email to" >> $init
echo "MG_SUBJECT=\"$DELEGATE_NAME in Fork - failover activated successfully\"" >> $init
echo "MG_TEXT=\"Description of the alert\"" >> $init
echo "DELEGATE_NAME=\"$DELEGATE_NAME\"" >> $init
echo "DELEGATE_ADDRESS=\"$DELEGATE_ADDRESS\"" >> $init
echo "OFFSET=\"$scale\"" >> $init
echo "IP_SERVER=\"$IP_SERVER\" #IP of the extra syncronized server" >> $init
echo "HTTP=\"$HTTP\" #http or https if is activated" >> $init
echo "PORT=\"$PORT\"" >> $init
echo "HTTP_LOCAL=\"$HTTP_LOCAL\"" >> $init
echo "LOCAL_PORT=\"$LOCAL_PORT\"" >> $init
echo "SECRET=\"$SECRET\" #Passphrase of DELEGATE_NAME" >> $init
echo "URL_REMOTE=\"\$HTTP://\$IP_SERVER:\$PORT/api/delegates/forging/enable\" #URL according variables HTTP, PORT and IP_SERVER" >> $init
echo "URL_REMOTE_DISABLE=\"\$HTTP://\$IP_SERVER:\$PORT/api/delegates/forging/disable\"" >> $init
echo "URL_LOCAL=\"\$HTTP_LOCAL://127.0.0.1:\$LOCAL_PORT/api/delegates/forging/enable\"" >> $init
echo "URL_LOCAL_DISABLE=\"\$HTTP_LOCAL://127.0.0.1:\$LOCAL_PORT/api/delegates/forging/disable\"" >> $init
echo "BLOCKHEIGHT_LOG=~/toolisk/logs/sync_manager.log" >> $init
echo "MANAGER_LOG=~/toolisk/logs/forging_manager.log" >> $init
echo "LOCAL_SNAPSHOTS=~/toolisk/snapshots/" >> $init
echo "PUBLICKEY=\"$PUBLICKEY\"" >> $init
echo "URL_LOCAL_FORGING_STATUS=\"http://localhost:8000/api/delegates/forging/status?publicKey=\$PUBLICKEY\"" >> $init
echo "URL_REMOTE_FORGING_STATUS=\"http://\$IP_SERVER:8000/api/delegates/forging/status?publicKey=\$PUBLICKEY\"" >> $init
echo "USERTOOL=\"$USER\"" >> $init
echo "SERVER_NAME=\"$SERVER_NAME\""
echo "ALERTS_OFF=\"$ALERTS_OFF\"" >> $init
echo "cd /home/$USER/$VERSION/" >> $init
chmod u+x sync_manager.sh
chmod u+x forging_manager.sh
mkdir -p logs/
echo " "
echo -e "${CYAN}ALL VARIABLES SET${OFF}"
echo " "
fi
#REBOOT DETECT/STARTUP SCRIPT
echo
echo "=============================================================="
echo "Anti-Reboot configuration"
echo "=============================================================="
echo " "
echo -e "Is important to keep ${CYAN}node app.js${OFF} running, that is why we need to prevent possible reboots or system outages."
echo "This script will send you an email alert when reboot is detected. And will start lisk at your system startup."
echo -e "Before proceeding, be sure to read the information located here: ${CYAN}https://github.com/mrgrshift/restart-script${OFF}"
echo "The following configuration will change your rc.local and create K04custom_shutdown script."
echo "If you are not sure about this please avoid the next question an press 'n'."
echo " "
read -p "Do you want to proceed (y/n)?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo " "
#custom_shutdown
echo "echo \"#!/bin/sh -e\" > /etc/init.d/custom_shutdown | sudo tee -a /etc/init.d/custom_shutdown > /dev/null" > temp.sh
echo "echo \"cd $(pwd)\" >> /etc/init.d/custom_shutdown | sudo tee -a /etc/init.d/custom_shutdown > /dev/null" >> temp.sh
echo "echo \"bash $(pwd)/reboot.sh >> $(pwd)/logs/reboot.log\" >> /etc/init.d/custom_shutdown | sudo tee -a /etc/init.d/custom_shutdown > /dev/null" >> temp.sh
echo "echo \"exit 0\" >> /etc/init.d/custom_shutdown | sudo tee -a /etc/init.d/custom_shutdown > /dev/null" >> temp.sh
sudo bash temp.sh
rm temp.sh
sudo chmod a+x /etc/init.d/custom_shutdown > logs/install.log > /dev/null
sudo ln -sf /etc/init.d/custom_shutdown /etc/rc0.d/K04custom_shutdown >> logs/install.log > /dev/null
sudo ln -sf /etc/init.d/custom_shutdown /etc/rc6.d/K04custom_shutdown >> logs/install.log > /dev/null
sudo chmod a+x /etc/rc0.d/K04custom_shutdown /etc/rc6.d/K04custom_shutdown >> logs/install.log > /dev/null
echo -n "Configuring... "
#reboot.sh
echo "#!/bin/sh -e" > reboot.sh
echo "source configtoolisk.sh" >> reboot.sh
echo "MG_SUBJECT=\"\$SERVER_NAME rebooting.\"" >> reboot.sh
echo "MG_TEXT=\"\$SERVER_NAME rebooting.\"" >> reboot.sh
echo "curl -s --user \"api:\$API_KEY\" \$MAILGUN -F from=\"\$MG_FROM\" -F to=\"\$MG_TO\" -F subject=\"\$MG_SUBJECT\" -F text=\"\$MG_TEXT\"" >> reboot.sh
sudo chmod a+x reboot.sh
#startup script
echo "#!/bin/bash" > startup.sh
echo "export HOME=/home/$USER/lisk-main/" >> startup.sh
echo "cd /home/$USER/lisk-main/" >> startup.sh
echo "echo \"Starting lisk.sh reload\" > /home/$USER/toolisk/logs/startup.log" >> startup.sh
echo "bash /home/$USER/lisk-main/lisk.sh reload >> /home/$USER/toolisk/logs/startup.log" >> startup.sh
sudo chmod u+x startup.sh
echo "#!/bin/bash" > temp.sh
echo "sudo rm /etc/rc.local" >> temp.sh
echo "echo \"#!/bin/sh -e\" > /etc/rc.local | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \"/bin/su $USER -c \\\"cd $(pwd); /usr/bin/screen -dmS startup_lisk bash -c $(pwd)/startup.sh'; exec bash'\\\" > $(pwd)/logs/rc.log.log\" | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \"sleep 15\" >> /etc/rc.local | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
#echo "echo \"/bin/su $USER -c \\\"cd $(pwd); bash -c $(pwd)/sync_manager.sh'; exec bash'\\\" > $(pwd)/logs/rc.local.log\" | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \"exit 0\" >> /etc/rc.local | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
sudo bash temp.sh
echo -e "done.";
rm temp.sh
echo "done"
DISTR=$(cat /etc/lsb-release | grep "DISTRIB_RELEASE")
if [ "$DISTR" != "DISTRIB_RELEASE=14.04" ]
then
echo -n "Configuring newer version... "
echo "echo \"[Unit]\" > /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" > temp.sh
echo "echo \" Description=/etc/rc.local Compatibility\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \" ConditionPathExists=/etc/rc.local\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \"[Service]\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \" Type=forking\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \" ExecStart=/etc/rc.local start\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \" ExecStop=/etc/init.d/custom_shutdown\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \" TimeoutSec=0\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \" StandardOutput=tty\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \" RemainAfterExit=yes\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \" SysVStartPriority=99\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \"[Install]\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
echo "echo \" WantedBy=multi-user.target\" >> /etc/systemd/system/rc-local.service | sudo tee -a /etc/rc.local > /dev/null" >> temp.sh
sudo bash temp.sh
sudo chmod +x /etc/rc.local 2>&1
sudo systemctl enable rc-local >> logs/install.log > /dev/null 2>&1
sudo systemctl start rc-local.service >> logs/install.log > /dev/null 2>&1
echo "done"
rm temp.sh
fi
echo " "
echo "You have completed the installation."
else
echo " "
echo "The installation is terminated."
exit 1
fi
#created by mrgr. Please consider to vote for mrgr delegates