1
1
#! /bin/bash
2
2
# #Setup & Upgrade Iotex MainNet / TestNet
3
3
# # User local: source/bash/sh $0 [$1=testnet]
4
+ # # User local: source/bash/sh $0 [$1=testnet $2=plugin=gateway]
5
+ # # User local: source/bash/sh $0 [$1=testnet $2=plugin=gateway $3=auto-update=on]
4
6
# # If remote: source/bash/sh <(curl -s https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/scripts/setup_fullnode.sh) [$1=testnet]
5
7
# # If remote: source/bash/sh <(curl -s https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/scripts/setup_fullnode.sh) [$1=testnet $2=plugin=gateway]
8
+ # # If remote: source/bash/sh <(curl -s https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/scripts/setup_fullnode.sh) [$1=testnet $2=plugin=gateway $3=auto-update=on]
6
9
7
10
# Colour codes
8
11
YELLOW=' \033[0;33m'
@@ -49,6 +52,7 @@ function setVar() {
49
52
50
53
function processParam() {
51
54
_ENV_=mainnet
55
+ _GREP_STRING_=MainNet
52
56
if [ $# -gt 0 ]; then
53
57
if [ " $1 " X = " testnet" X ]; then
54
58
_ENV_=testnet
@@ -66,6 +70,9 @@ function processParam() {
66
70
fi
67
71
fi
68
72
env=$_ENV_
73
+
74
+ # Use for auto-update
75
+ export _GREP_STRING_ _ENV_
69
76
}
70
77
71
78
function determinePluginIsChanged() {
@@ -113,7 +120,7 @@ function preDockerCompose() {
113
120
export IOTEX_HOME IOTEX_MONITOR_HOME IOTEX_IMAGE
114
121
115
122
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/docker-compose.yml.gateway > $IOTEX_MONITOR_HOME /docker-compose.yml.gateway
116
- curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/docker-compose.yml > $IOTEX_MONITOR_HOME /docker-compose.yml
123
+ curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/docker-compose.yml > $IOTEX_MONITOR_HOME /docker-compose.yml.default
117
124
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/.env > $IOTEX_MONITOR_HOME /.env
118
125
}
119
126
@@ -216,18 +223,23 @@ function downloadConfig() {
216
223
217
224
function enableGateway() {
218
225
cd $IOTEX_MONITOR_HOME
219
- \c p docker-compose.yml docker-compose.yml.bak
220
226
\c p docker-compose.yml.gateway docker-compose.yml
221
227
cd $CUR_PWD
222
228
}
223
229
230
+ function disableGateway() {
231
+ cd $IOTEX_MONITOR_HOME
232
+ \c p docker-compose.yml.default docker-compose.yml
233
+ cd $CUR_PWD
234
+ }
235
+
224
236
function startupWithMonitor() {
225
237
echo -e " Start iotex-server and monitor."
226
238
cd $IOTEX_MONITOR_HOME
227
239
docker-compose up -d --no-recreate
228
240
if [ $? -eq 0 ]; then
229
241
echo -e " ${YELLOW} If you first create monitor, you can access 'localhost:3000' to view node monitoring ${NC} "
230
- echo -e " ${YELLOW} Default User/Pass: admin/admin."
242
+ echo -e " ${YELLOW} Default User/Pass: admin/admin. ${NC} "
231
243
fi
232
244
cd $CUR_PWD
233
245
}
@@ -264,11 +276,27 @@ function startupNode() {
264
276
265
277
}
266
278
279
+ function startAutoUpdate() {
280
+ # Download auto-update command
281
+ mkdir -p $IOTEX_HOME /bin
282
+ if [ " $( uname) " X = " Darwin" X ]; then
283
+ curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/tools/auto-update/auto-update_darwin-amd64 > $IOTEX_HOME /bin/auto-update || exit 1
284
+ else
285
+ curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/tools/auto-update/auto-update_linux-amd64 > $IOTEX_HOME /bin/auto-update || exit 1
286
+ fi
287
+
288
+ curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/scripts/update_silence.sh > $IOTEX_HOME /bin/update_silence.sh || exit 1
289
+ chmod +x $IOTEX_HOME /bin/auto-update $IOTEX_HOME /bin/update_silence.sh
290
+
291
+ # Run background
292
+ nohup $IOTEX_HOME /bin/auto-update > $IOTEX_HOME /log/update.log 2>&1 &
293
+ echo -e " ${YELLOW} Auto-update is on. it will auto update every 3 days. ${NC} "
294
+ }
295
+
267
296
function main() {
268
297
checkDockerPermissions
269
298
checkDockerCompose
270
299
271
- _GREP_STRING_=MainNet
272
300
setVar $@
273
301
lastversion=$( curl -sS https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/README.md| grep " ^- $_GREP_STRING_ :" | awk ' {print $3}' )
274
302
@@ -287,10 +315,15 @@ function main() {
287
315
determinIotexHome
288
316
confirmEnvironmentVariable
289
317
318
+ read -p " Do you want to auto update the node [Y/N] (Default: Y)? " _AUTO_UPDATE_
319
+
290
320
deleteOldFile
291
321
292
322
if [ " $version " X = " $runversion " X ] && [ $_PLUGINS_CHANGE_ -eq 0 ]; then
293
323
procssNotUpdate
324
+ if [ " $_AUTO_UPDATE_ " X = " on" X ]; then
325
+ startAutoUpdate
326
+ fi
294
327
exit 0
295
328
fi
296
329
@@ -315,15 +348,21 @@ function main() {
315
348
preDockerCompose
316
349
if [ $_PLUGINS_ ] && [ " $_PLUGINS_ " X = " gateway" X ]; then
317
350
enableGateway
351
+ else
352
+ disableGateway
318
353
fi
319
354
320
355
startupNode
321
356
322
- # restore file docker-compose.yml
323
- if [ $_PLUGINS_ ] && [ " $_PLUGINS_ " X = " gateway" X ]; then
324
- cd $IOTEX_MONITOR_HOME
325
- mv docker-compose.yml.bak docker-compose.yml
326
- cd ${CUR_PWD}
357
+ # stop auto-updatem, if it is running.
358
+ ps -ef | grep " $IOTEX_HOME /bin/bauto-update" > /dev/null
359
+ if [ $? -eq 0 ]; then
360
+ pid=$( ps -ef | grep " $IOTEX_HOME /bin/auto-update" | grep -v grep | awk ' {print $2}' )
361
+ kill -9 $pid
362
+ fi
363
+
364
+ if [ " $_AUTO_UPDATE_ " X != " N" X ]; then
365
+ startAutoUpdate
327
366
fi
328
367
}
329
368
0 commit comments