-
Notifications
You must be signed in to change notification settings - Fork 0
/
rapidund
executable file
·590 lines (547 loc) · 19.7 KB
/
rapidund
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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
#!/bin/bash
# Pretty colors :D
RED='\033[0;31m'
BLUE='\033[0;34m'
GREEN='\033[0;32m'
PURP='\033[1;35m'
NOCOL='\033[0m'
CHAIN=NONE
MONIKER=NONE
PRUNING=default
PRUNING_PRESET=default
PRUNING_RECENT=100
PRUNING_EVERY=500
PRUNING_INTERVAL=10
remove_und() {
sudo systemctl daemon-reload
sudo systemctl stop und
sudo systemctl disable und
sudo rm -r $HOME/.und_mainchain
sudo rm -r $HOME/tempund
sudo rm -r $HOME/UNDBackup
sudo rm -r /usr/local/bin/und
sudo rm -r /usr/local/bin/cosmovisor
sudo rm -r /etc/systemd/system/und.service
}
install_und_cosmovisor() {
mkdir $HOME/UNDBackup
mkdir -p $HOME/tempund/und
mkdir $HOME/tempund/upgradeund
mkdir $HOME/tempund/cosmovisor
#Setting up UND
wget $UND -P $HOME/tempund/und
tar -zxvf $HOME/tempund/und/$(ls $HOME/tempund/und) -C $HOME/tempund/und
sudo cp $HOME/tempund/und/und /usr/local/bin
und init $MONIKER
curl $GENESIS > $HOME/.und_mainchain/config/genesis.json
cp $HOME/.und_mainchain/config/priv_validator_key.json $HOME/UNDBackup
cp $HOME/.und_mainchain/config/node_key.json $HOME/UNDBackup
sudo tee /etc/systemd/system/und.service > /dev/null <<EOF
[Unit]
Description=Unification Mainchain Node
[Service]
User=$(whoami)
Group=$(whoami)
WorkingDirectory=$HOME
EnvironmentFile=$HOME/.und_mainchain/cosmovisor/UND_COSMOVISOR_ENV
ExecStart=/usr/local/bin/cosmovisor run start
Restart=on-failure
RestartSec=10s
LimitNOFILE=4096
[Install]
WantedBy=default.target
EOF
#Setting up Cosmovisor
wget $COSMOVISOR -P $HOME/tempund/cosmovisor
tar -zxvf $HOME/tempund/cosmovisor/$(ls $HOME/tempund/cosmovisor) -C $HOME/tempund/cosmovisor
mkdir -p $HOME/.und_mainchain/cosmovisor/genesis/bin
mkdir $HOME/.und_mainchain/cosmovisor/upgrades
mv $HOME/tempund/und/und $HOME/.und_mainchain/cosmovisor/genesis/bin
sudo mv $HOME/tempund/cosmovisor/cosmovisor /usr/local/bin
tee $HOME/.und_mainchain/cosmovisor/UND_COSMOVISOR_ENV > /dev/null <<EOF
DAEMON_NAME=und
DAEMON_HOME=$HOME/.und_mainchain
DAEMON_RESTART_AFTER_UPGRADE=true
DAEMON_RESTART_DELAY=5s
EOF
rm -r $HOME/tempund
}
statesync_config() {
HANDH=$(curl -s "$HANDH_URL/latest")
HEIGHT=$(echo $HANDH | jq -r '.block.header.height')
HEIGHT=$((HEIGHT - 5000))
HANDH=$(curl -s "$HANDH_URL/$HEIGHT")
HASH=$(echo $HANDH | jq -r '.block_id.hash' | base64 -d | xxd -p -u -c 100)
sed -i "s/enable.*/enable = true/" $HOME/.und_mainchain/config/config.toml
sed -i "s/trust_height.*/trust_height = $HEIGHT/" $HOME/.und_mainchain/config/config.toml
sed -i 's/trust_hash.*/trust_hash = "'$HASH'"/' $HOME/.und_mainchain/config/config.toml
sed -i 's|rpc_servers.*|rpc_servers = "'$RPC'"|' $HOME/.und_mainchain/config/config.toml
sed -i 's/discovery_time.*/discovery_time = "30s"/' $HOME/.und_mainchain/config/config.toml
sed -i 's/chunk_request_timeout.*/chunk_request_timeout = "60s"/' $HOME/.und_mainchain/config/config.toml
sed -i 's/seeds.*/seeds = "'$SEEDS'"/' $HOME/.und_mainchain/config/config.toml
}
set_pruning() {
sed -i 's/pruning = "default"/pruning = "'$PRUNING'"/' $HOME/.und_mainchain/config/app.toml
sed -i 's/pruning-keep-recent = "0"/pruning-keep-recent = "'$PRUNING_RECENT'"/' $HOME/.und_mainchain/config/app.toml
sed -i 's/pruning-keep-every = "0"/pruning-keep-every = "'$PRUNING_EVERY'"/' $HOME/.und_mainchain/config/app.toml
sed -i 's/pruning-interval = "0"/pruning-interval = "'$PRUNING_INTERVAL'"/' $HOME/.und_mainchain/config/app.toml
}
start_und() {
sudo systemctl daemon-reload
sudo systemctl enable und
sudo systemctl start und
sudo journalctl -u und -f -o cat
}
set_mainnet() {
GENESIS=https://raw.githubusercontent.com/unification-com/mainnet/master/latest/genesis.json
UND=https://github.com/unification-com/mainchain/releases/download/v1.9.0/und_v1.9.0_linux_x86_64.tar.gz
COSMOVISOR=https://github.com/cosmos/cosmos-sdk/releases/download/cosmovisor%2Fv1.2.0/cosmovisor-v1.2.0-linux-amd64.tar.gz
UPGRADE=NONE
SEEDS=0c2b65bc604a18a490f5f55bb7b4140cfb512ced@seed1.unification.io:26656,[email protected]:26656
RPC="https://rpc1.unification.io:443,https://rpc.unification.chainmasters.ninja:443"
HANDH_URL=https://rest.unification.io/cosmos/base/tendermint/v1beta1/blocks
CHAIN=MainNet
}
set_testnet() {
GENESIS=https://raw.githubusercontent.com/unification-com/testnet/master/latest/genesis.json
UND=https://github.com/unification-com/mainchain/releases/download/v1.8.2/und_v1.8.2_linux_x86_64.tar.gz
UPGRADE=NONE
COSMOVISOR=https://github.com/cosmos/cosmos-sdk/releases/download/cosmovisor%2Fv1.2.0/cosmovisor-v1.2.0-linux-amd64.tar.gz
SEEDS=e428c5653865da4a55f5599d7ff3203789abadfd@seed-testnet.unification.io:26656
RPC=sync1-testnet.unification.io:26657,sync2-testnet.unification.io:26657
HANDH_URL=https://rest-testnet.unification.io/cosmos/base/tendermint/v1beta1/blocks/latest
CHAIN=TestNet
}
install_menu() {
cat << EOF
$(printf $BLUE)
██╗███╗ ██╗███████╗████████╗ █████╗ ██╗ ██╗
██║████╗ ██║██╔════╝╚══██╔══╝██╔══██╗██║ ██║
██║██╔██╗ ██║███████╗ ██║ ███████║██║ ██║
██║██║╚██╗██║╚════██║ ██║ ██╔══██║██║ ██║
██║██║ ╚████║███████║ ██║ ██║ ██║███████╗███████╗
╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝
$(printf $RED)
!!!!!!CAUTION!!!!!!!
This will DESTROY the following files if present:
$(printf $GREEN)
$HOME/.und_mainchain
$HOME/tempund
$HOME/UNDBackup
/usr/local/bin/und
/usr/local/bin/cosmovisor
/etc/systemd/system/und.service
$(printf $NOCOL)
|-------------------------|
| key | action |
|-----+-------------------|
| i | Install |
| | |
|-----+-------------------|
| key | menu |
|-----+-------------------|
| 1 | Main Menu |
| | |
|-------------------------|
$(printf $BLUE)
Current configuration:
Moniker: $MONIKER
Chain: $CHAIN
Pruning: $PRUNING_PRESET
$(printf $PURP)
EOF
while true
do
read -p "key > " -n 1 key
case $key in
i)
if [ $MONIKER = "NONE" ]
then
echo -e "${RED}\n\nMoniker not set, cannot install\n${NOCOL}"
elif [ $CHAIN = "NONE" ]
then
echo -e "${RED}\n\nChain not set, cannot install\n${NOCOL}"
else
echo -e "\n"
remove_und
install_und_cosmovisor
statesync_config
set_pruning
start_und
fi
;;
1)
clear
main
;;
*)
clear
install_menu
;;
esac
done
}
uninstall_menu() {
cat << EOF
$(printf $BLUE)
██╗ ██╗███╗ ██╗██╗███╗ ██╗███████╗████████╗ █████╗ ██╗ ██╗
██║ ██║████╗ ██║██║████╗ ██║██╔════╝╚══██╔══╝██╔══██╗██║ ██║
██║ ██║██╔██╗ ██║██║██╔██╗ ██║███████╗ ██║ ███████║██║ ██║
██║ ██║██║╚██╗██║██║██║╚██╗██║╚════██║ ██║ ██╔══██║██║ ██║
╚██████╔╝██║ ╚████║██║██║ ╚████║███████║ ██║ ██║ ██║███████╗███████╗
╚═════╝ ╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝
$(printf $RED)
!!!!!!CAUTION!!!!!!!
This will DESTROY the following files if present:
$(printf $GREEN)
$HOME/.und_mainchain
$HOME/tempund
$HOME/UNDBackup
/usr/local/bin/und
/usr/local/bin/cosmovisor
/etc/systemd/system/und.service
$(printf $NOCOL)
|-------------------------|
| key | action |
|-----+-------------------|
| u | Uninstall |
| | |
|-----+-------------------|
| key | menu |
|-----+-------------------|
| 1 | Main Menu |
| | |
|-------------------------|
$(printf $PURP)
EOF
while true
do
read -p "key > " -n 1 key
case $key in
u)
echo -e "\n"
remove_und
echo -e "\n\nAll Unification Files Removed\n"
exit
;;
1)
clear
main
;;
*)
clear
uninstall_menu
;;
esac
done
}
chain_menu() {
cat << EOF
$(printf $BLUE)
██████╗██╗ ██╗ █████╗ ██╗███╗ ██╗
██╔════╝██║ ██║██╔══██╗██║████╗ ██║
██║ ███████║███████║██║██╔██╗ ██║
██║ ██╔══██║██╔══██║██║██║╚██╗██║
╚██████╗██║ ██║██║ ██║██║██║ ╚████║
╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝
$(printf $RED)
Select the chain this node should operate on
$(printf $NOCOL)
|-------------------------|
| key | action |
|-----+-------------------|
| t | Set Testnet |
| m | Set Mainnet |
| | |
|-----+-------------------|
| key | menu |
|-----+-------------------|
| 1 | Main Menu |
| | |
|-------------------------|
$(printf $BLUE)
Current Chain: $CHAIN
$(printf $PURP)
EOF
while true
do
read -p "key > " -n 1 key
case $key in
t)
echo -e "\n"
set_testnet
clear
chain_menu
;;
m)
echo -e "\n"
set_mainnet
clear
chain_menu
;;
1)
clear
main
;;
*)
clear
chain_menu
;;
esac
done
}
moniker_menu() {
cat << EOF
$(printf $BLUE)
███╗ ███╗ ██████╗ ███╗ ██╗██╗██╗ ██╗███████╗██████╗
████╗ ████║██╔═══██╗████╗ ██║██║██║ ██╔╝██╔════╝██╔══██╗
██╔████╔██║██║ ██║██╔██╗ ██║██║█████╔╝ █████╗ ██████╔╝
██║╚██╔╝██║██║ ██║██║╚██╗██║██║██╔═██╗ ██╔══╝ ██╔══██╗
██║ ╚═╝ ██║╚██████╔╝██║ ╚████║██║██║ ██╗███████╗██║ ██║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
$(printf $RED)
Set the moniker for this node
$(printf $NOCOL)
|-------------------------|
| key | action |
|-----+-------------------|
| m | Set New Moniker |
| | |
|-----+-------------------|
| key | menu |
|-----+-------------------|
| 1 | Main Menu |
| | |
|-------------------------|
$(printf $BLUE)
Current Moniker: $MONIKER
$(printf $PURP)
EOF
while true
do
read -p "key > " -n 1 key
case $key in
m)
echo -e "\n"
read -p "Enter New Moniker > " MONIKER
clear
moniker_menu
;;
1)
clear
main
;;
*)
clear
moniker_menu
;;
esac
done
}
pruning_menu() {
cat << EOF
$(printf $BLUE)
██████╗ ██████╗ ██╗ ██╗███╗ ██╗██╗███╗ ██╗ ██████╗
██╔══██╗██╔══██╗██║ ██║████╗ ██║██║████╗ ██║██╔════╝
██████╔╝██████╔╝██║ ██║██╔██╗ ██║██║██╔██╗ ██║██║ ███╗
██╔═══╝ ██╔══██╗██║ ██║██║╚██╗██║██║██║╚██╗██║██║ ██║
██║ ██║ ██║╚██████╔╝██║ ╚████║██║██║ ╚████║╚██████╔╝
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝
$(printf $RED)
Set custom pruning options for your node, or select a preset
$(printf $NOCOL)
|-------------------------|
| key | action |
|-----+-------------------|
| c | Custom Pruning |
| | |
|-----+-------------------|
| key | presets |
|-----+-------------------|
| d | Default |
| l | Low Storage |
| n | Nothing |
| e | Everything |
| | |
|-----+-------------------|
| key | menu |
|-----+-------------------|
| 1 | Main Menu |
| | |
|-------------------------|
$(printf $BLUE)
Current pruning config:
Preset: $PRUNING_PRESET
Keep-Recent: $PRUNING_RECENT
Keep-Every: $PRUNING_EVERY
Pruning-Interval: $PRUNING_INTERVAL
$(printf $PURP)
EOF
while true
do
read -p "key > " -n 1 key
case $key in
c)
PRUNING_PRESET=custom
PRUNING=custom
echo -e "\n"
read -p "Enter pruning-keep-recent: > " CHOICE
PRUNING_RECENT=$CHOICE
echo -e "\n"
read -p "Enter pruning-keep-every: > " CHOICE
PRUNING_EVERY=$CHOICE
echo -e "\n"
read -p "Enter pruning-interval: > " CHOICE
PRUNING_INTERVAL=$CHOICE
clear
pruning_menu
;;
d)
PRUNING_PRESET=default
PRUNING=default
PRUNING_RECENT=100
PRUNING_EVERY=500
PRUNING_INTERVAL=10
clear
pruning_menu
;;
l)
PRUNING_PRESET="low storage"
PRUNING=custom
PRUNING_RECENT=100
PRUNING_EVERY=0
PRUNING_INTERVAL=10
clear
pruning_menu
;;
n)
PRUNING_PRESET=nothing
PRUNING=nothing
PRUNING_RECENT=100
PRUNING_EVERY=500
PRUNING_INTERVAL=10
clear
pruning_menu
;;
e)
PRUNING_PRESET=everything
PRUNING=everything
PRUNING_RECENT=100
PRUNING_EVERY=500
PRUNING_INTERVAL=10
clear
pruning_menu
;;
1)
clear
main
;;
*)
clear
pruning_menu
;;
esac
done
}
main() {
clear
cat << EOF
$(printf $BLUE)
██████╗ █████╗ ██████╗ ██╗██████╗ ██╗ ██╗███╗ ██╗██████╗
██╔══██╗██╔══██╗██╔══██╗██║██╔══██╗██║ ██║████╗ ██║██╔══██╗
██████╔╝███████║██████╔╝██║██║ ██║██║ ██║██╔██╗ ██║██║ ██║
██╔══██╗██╔══██║██╔═══╝ ██║██║ ██║██║ ██║██║╚██╗██║██║ ██║
██║ ██║██║ ██║██║ ██║██████╔╝╚██████╔╝██║ ╚████║██████╔╝
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═════╝
$(printf $RED)
This script is made to rapidly deploy a Unification Node, for Testnet or Mainnet.
Intended for expirienced operators.
If there are any issues please report them on github.
$(printf $NOCOL)
|-------------------------|
| key | action |
|-----+-------------------|
| q | Quit |
| u | Uninstall |
| i | Install |
| | |
|-----+-------------------|
| key | menu |
|-----+-------------------|
| 1 | Main Menu |
| 2 | Chain |
| 3 | Moniker |
| 4 | Pruning |
| | |
|-------------------------|
$(printf $PURP)
EOF
while true
do
read -p "key > " -n 1 key
case $key in
q)
exit
;;
u)
clear
uninstall_menu
;;
i)
clear
install_menu
;;
1)
clear
main
;;
2)
clear
chain_menu
;;
3)
clear
moniker_menu
;;
4)
clear
pruning_menu
;;
*)
main
;;
esac
done
}
startup_check() {
# Ensure root user is not running the script
if [ "$EUID" = 0 ]; then
clear
cat << EOF
*** You are attempting to run this script as root user ***
This is poor practice,
please try again as a created user with sudo privledges
EOF
exit
fi
# Ensure needed programs are installed
if ! command -v jq &> /dev/null; then
clear
echo "jq is not installed, please refer to README for dependency list"
exit
elif ! command -v curl &> /dev/null; then
clear
echo "curl is not installed, please refer to README for dependency list"
exit
elif ! command -v wget &> /dev/null; then
clear
echo "wget is not installed, please refer to README for dependency list"
exit
elif ! command -v xxd &> /dev/null; then
clear
echo "xxd is not installed, please refer to README for dependency list"
exit
fi
}
startup_check
main