-
Notifications
You must be signed in to change notification settings - Fork 13
/
pli_node_scripts.sh
716 lines (553 loc) · 23.1 KB
/
pli_node_scripts.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
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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#!/bin/bash
# Get current user id and store as var
USER_ID=$(getent passwd $EUID | cut -d: -f1)
# Authenticate sudo perms before script execution to avoid timeouts or errors
sudo -l > /dev/null 2>&1
# Set the sudo timeout for USER_ID to expire on reboot instead of default 5mins
echo "Defaults:$USER_ID timestamp_timeout=-1" > /tmp/plisudotmp
sudo sh -c 'cat /tmp/plisudotmp > /etc/sudoers.d/plinode_deploy'
# Set Colour Vars
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
FDATE=$(date +"%Y_%m_%d_%H_%M")
FUNC_VARS(){
## VARIABLE / PARAMETER DEFINITIONS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PLI_VARS_FILE="plinode_$(hostname -f)".vars
if [ ! -e ~/$PLI_VARS_FILE ]; then
#clear
echo
echo -e "${RED} #### NOTICE: No VARIABLES file found. ####${NC}"
echo -e "${RED} ..creating local vars file '$HOME/$PLI_VARS_FILE' ${NC}"
cp sample.vars ~/$PLI_VARS_FILE
chmod 600 ~/$PLI_VARS_FILE
echo
echo -e "${GREEN}nano ~/$PLI_VARS_FILE ${NC}"
#sleep 2s
fi
source ~/$PLI_VARS_FILE
if [[ "$CHECK_PASSWD" == "true" ]]; then
FUNC_PASSWD_CHECKS
fi
}
FUNC_PKG_CHECK(){
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## CHECK NECESSARY PACKAGES HAVE BEEN INSTALLED...${NC}"
for i in "${REQ_PACKAGES[@]}"
do
hash $i &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "package "$i" not found. installing...."
sudo apt install -y "$i"
fi
echo "packages "$i" exist. proceeding...."
done
}
FUNC_VALUE_CHECK(){
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## CONFIRM SCRIPTS VARIABLES FILE HAS BEEN UPDATED...${NC}"
# Ask the user acc for login details (comment out to disable)
CHECK_PASSWD=false
while true; do
read -t7 -r -p "please confirm that you have updated the vars file with your values ? (Y/n) " _input
if [ $? -gt 128 ]; then
#clear
echo
echo "timed out waiting for user response - proceeding as normal..."
CHECK_PASSWD=true
FUNC_NODE_DEPLOY;
fi
case $_input in
[Yy][Ee][Ss]|[Yy]* )
CHECK_PASSWD=true
FUNC_NODE_DEPLOY
break
;;
[Nn][Oo]|[Nn]* )
FUNC_EXIT
;;
* ) echo "Please answer (y)es or (n)o.";;
esac
done
}
FUNC_PASSWD_CHECKS(){
# check all credentials has been updated - if not auto gen
SAMPLE_KEYSTORE='$oM3$tr*nGp4$$w0Rd$'
# PASS_KEYSTORE value to compare against
SAMPLE_DB_PWD="testdbpwd1234"
# DB_PWD_NEW value to compare against
SAMPLE_API_EMAIL="[email protected]"
# API EMAIL value to compare against
SAMPLE_API_PASS='passW0rd123'
# API PASSWORD value to compare against
if ([ -z "$PASS_KEYSTORE" ] || [ "$PASS_KEYSTORE" == "$SAMPLE_KEYSTORE" ]); then
echo
echo -e "${GREEN} VARIABLE 'PASS_KEYSTORE' NOT UPDATED MANUALLY - AUTO GENERATING VALUE NOW"
#echo -e "${GREEN} YOUR NODE VARS FILE WILL BE UPDATED WITH THE GENERATED CREDENTIALS${NC}"
sleep 2s
#_AUTOGEN_KEYSTORE="'$(cat /dev/urandom | tr -dc 'a-zA-Z0-9%:+*!;.?=' | head -c32)'"
_AUTOGEN_KEYSTORE="'$(./gen_passwd.sh -keys)'"
sed -i 's/^PASS_KEYSTORE.*/PASS_KEYSTORE='"$_AUTOGEN_KEYSTORE"'/g' ~/"plinode_$(hostname -f)".vars
PASS_KEYSTORE=$_AUTOGEN_KEYSTORE
fi
if ([ -z "$DB_PWD_NEW" ] || [ "$DB_PWD_NEW" == "$SAMPLE_DB_PWD" ]); then
echo
echo -e "${GREEN} VARIABLE 'DB_PWD_NEW' NOT UPDATED MANUALLY - AUTO GENERATING VALUE NOW"
#echo -e "${GREEN} YOUR NODE VARS FILE WILL BE UPDATED WITH THE GENERATED CREDENTIALS${NC}"
sleep 2s
#_AUTOGEN_DB_PWD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w20 | head -n1)
_AUTOGEN_DB_PWD="$(./gen_passwd.sh -db)"
sed -i 's/^DB_PWD_NEW.*/DB_PWD_NEW=\"'"${_AUTOGEN_DB_PWD}"'\"/g' ~/"plinode_$(hostname -f)".vars
DB_PWD_NEW=$_AUTOGEN_DB_PWD
fi
if ([ -z "$API_EMAIL" ] || [ "$API_EMAIL" == "$SAMPLE_API_EMAIL" ]); then
echo
echo -e "${GREEN} VARIABLE 'API_EMAIL' NOT UPDATED MANUALLY - AUTO GENERATING VALUE NOW"
#echo -e "${GREEN} YOUR NODE VARS FILE WILL BE UPDATED WITH THE GENERATED CREDENTIALS${NC}"
sleep 2s
_AUTOGEN_API_USER=$(tr -cd A-Za-z < /dev/urandom | fold -w10 | head -n1)
API_EMAIL_NEW="[email protected]"
sed -i 's/^API_EMAIL.*/API_EMAIL=\"'"${API_EMAIL_NEW}"'\"/g' ~/"plinode_$(hostname -f)".vars
API_EMAIL=$API_EMAIL_NEW
fi
if ([ -z "$API_PASS" ] || [ "$API_PASS" == "$SAMPLE_API_PASS" ]); then
echo
echo -e "${GREEN} VARIABLE 'API_PASS' NOT UPDATED MANUALLY - AUTO GENERATING VALUE NOW"
#echo -e "${GREEN} YOUR NODE VARS FILE WILL BE UPDATED WITH THE GENERATED CREDENTIALS${NC}"
echo
sleep 2s
#_AUTOGEN_API_PWD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w18 | head -n1)
_AUTOGEN_API_PWD="'$(./gen_passwd.sh -api)'"
sed -i 's/^API_PASS.*/API_PASS='"${_AUTOGEN_API_PWD}"'/g' ~/"plinode_$(hostname -f)".vars
API_PASS=$_AUTOGEN_DB_PWD
fi
# Update the system memory with the newly updated variables
source ~/"plinode_$(hostname -f)".vars
}
FUNC_NODE_DEPLOY(){
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}"
echo -e "${GREEN} Modular Deployment Script Method"
echo -e "${GREEN}"
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}#########################################################################${NC}"
# loads variables
FUNC_VARS;
# call base_sys_setup script to perform basic system updates etc.
bash base_sys_setup.sh -D
echo
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## Install: check credentials are updated against default sample values...${NC}"
FUNC_PASSWD_CHECKS;
# installs default packages listed in vars file
FUNC_PKG_CHECK;
echo
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## Install: Clone repo to local install folder...${NC}"
#if [ ! -d "/$PLI_BASE_DIR" ]; then
# sudo mkdir "/$PLI_BASE_DIR"
# #USER_ID=$(getent passwd $EUID | cut -d: -f1)
# sudo chown $USER_ID\:$USER_ID -R "/$PLI_BASE_DIR"
#fi
#cd /$PLI_BASE_DIR
#git clone https://github.com/GoPlugin/plugin-deployment.git && cd plugin-deployment
#rm -f {apicredentials.txt,password.txt}
sleep 2s
cd ~/$PLI_DEPLOY_DIR
touch {$FILE_KEYSTORE,$FILE_API}
chmod 666 {$FILE_KEYSTORE,$FILE_API}
echo $API_EMAIL > $FILE_API
echo $API_PASS >> $FILE_API
echo $PASS_KEYSTORE > $FILE_KEYSTORE
chmod 600 {$FILE_KEYSTORE,$FILE_API}
# Remove the file if necessary; sudo rm -f {.env.apicred,.env.password}
echo
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## Install: UPDATE bash file $BASH_FILE1 with user values...${NC}"
sed -i "s/$DB_PWD_FIND/'$DB_PWD_NEW'/g" ~/$PLI_DEPLOY_DIR/$BASH_FILE1
#cat $BASH_FILE1 | grep 'postgres PASSWORD'
sleep 3s
echo
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## Install: PRE-CHECKS for bash file $BASH_FILE1...${NC}"
sudo apt remove --autoremove golang -y
sudo rm -rf /usr/local/go
echo
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## Install: EXECUTE bash file $BASH_FILE1...${NC}"
bash /$PLI_BASE_DIR/$PLI_DEPLOY_DIR/$BASH_FILE1
echo
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## Install: Update bash file $BASH_FILE2 with user CREDENTIALS values...${NC}"
#cd ~/$PLI_DEPLOY_DIR/
sed -i.bak "s/password.txt/$FILE_KEYSTORE/g" $BASH_FILE2
sed -i.bak "s/apicredentials.txt/$FILE_API/g" $BASH_FILE2
sed -i.bak "s/:postgres/:$DB_PWD_NEW/g" $BASH_FILE2
sed -i.bak '/SECURE_COOKIES=false/d' $BASH_FILE2
cat $BASH_FILE2 | grep node
sleep 1s
echo
echo -e "${GREEN}## Install: Update bash file $BASH_FILE2 with user TLS values...${NC}"
sed -i.bak "s/PLUGIN_TLS_PORT=0/PLUGIN_TLS_PORT=$PLI_HTTPS_PORT/g" $BASH_FILE2
sed -i.bak "/^export PLUGIN_TLS_PORT=.*/a export TLS_CERT_PATH=$TLS_CERT_PATH/server.crt\nexport TLS_KEY_PATH=$TLS_CERT_PATH/server.key" $BASH_FILE2
cat $BASH_FILE2 | grep TLS
sleep 1s
echo
echo -e "${GREEN}## Install: Create TLS CA / Certificate & files / folders...${NC}"
mkdir $TLS_CERT_PATH && cd $TLS_CERT_PATH
openssl req -x509 -out server.crt -keyout server.key -newkey rsa:4096 \
-sha256 -days 3650 -nodes -extensions EXT -config \
<(echo "[dn]"; echo CN=localhost; echo "[req]"; echo distinguished_name=dn; echo "[EXT]"; echo subjectAltName=DNS:localhost; echo keyUsage=digitalSignature; echo \
extendedKeyUsage=serverAuth) -subj "/CN=localhost"
sleep 1s
echo
echo -e "${GREEN}## Install: Update bash file $BASH_FILE2 with INITIATORS values...${NC}"
sed -i.bak "/^ export DATABASE_TIMEOUT=.*/a export FEATURE_EXTERNAL_INITIATORS=true" $BASH_FILE2
cat $BASH_FILE2 | grep INITIATORS
sleep 1s
echo
echo -e "${GREEN}## Install: Update '.profile' with string 'FEATURE_EXTERNAL_INITIATORS'...${NC}"
isInFile=$(cat ~/.profile | grep -c "FEATURE_EXTERNAL_INITIATORS")
if [ $isInFile -eq 0 ]; then
echo "export FEATURE_EXTERNAL_INITIATORS=true" >> ~/.profile
echo -e "${GREEN}## Success: '.profile' updated with string 'FEATURE_EXTERNAL_INITIATORS'...${NC}"
else
echo -e "${GREEN}## Skipping: '.profile' contains string 'FEATURE_EXTERNAL_INITIATORS'...${NC}"
fi
echo -e "${GREEN}## Install: Check Golang version & bash profile path...${NC}"
source ~/.profile
GO_VER=$(go version)
go version; GO_EC=$?
case $GO_EC in
0) echo -e "${GREEN}## Command exited with NO error...${NC}"
echo $GO_VER
echo
echo -e "${GREEN}## Install proceeding as normal...${NC}"
;;
1) echo -e "${RED}## Command exited with ERROR - updating bash profile...${NC}"
source ~/.profile;
sudo sh -c 'echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile'
echo "cat "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile"
echo -e "${RED}## Check GO Version manually...${NC}"
sleep 2s
#FUNC_EXIT_ERROR
#exit 1
;;
*) echo -e "${RED}## Command exited with OTHER ERROR...${NC}"
echo -e "${RED}## 'go version' returned : $GO_EC ${NC}"
FUNC_EXIT_ERROR
#exit 1
;;
esac
sleep 1s
echo -e "${GREEN}## Install: Start PM2 $BASH_FILE2 & set auto start on reboot...${NC}"
cd /$PLI_DEPLOY_PATH
pm2 start $BASH_FILE2
sleep 1s
pm2 list
sleep 2s
pm2 list
pm2 startup systemd
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u $USER_ID --hp /home/$USER_ID
pm2 save
# INTERACTIVE: Calls function to check if user wants to proceed to next stage of setup.
#FUNC_DO_INIT_CHECK;
# NON-INTERACTIVE: Proceed with next stage of setup.
FUNC_EXPORT_NODE_KEYS;
FUNC_INITIATOR;
}
FUNC_EXPORT_NODE_KEYS(){
echo
echo -e "${GREEN}#########################################################################${NC}"
echo -e "${GREEN} export node keys - add current user to 'postgres' group"
sudo usermod -aG postgres $(getent passwd $EUID | cut -d: -f1)
sleep 2s
#echo
#echo -e "${GREEN}#########################################################################${NC}"
echo
echo -e "${RED}###### IMPORTANT FILE - NODE ADDRESS EXPORT FOR WALLET ACCESS #####${NC}"
echo -e "${RED}###### IMPORTANT FILE - PLEASE SECURE APPROPRIATELY #####${NC}"
echo
echo -e "${GREEN} export node keys - exporting keys to file: ~/"plinode_$(hostname -f)_keys_${FDATE}".json${NC}"
echo $(sudo -u postgres -i psql -d plugin_mainnet_db -t -c"select json from keys where id=1;") > ~/"plinode_$(hostname -f)_keys_${FDATE}".json
echo -e "${GREEN} export node keys - securing file permissions${NC}"
chmod 400 ~/"plinode_$(hostname -f)_keys_${FDATE}".json
sleep 4s
}
FUNC_INITIATOR(){
FUNC_VARS;
source ~/.profile
if [ ! -d "/$PLI_DEPLOY_PATH/$PLI_INITOR_DIR" ]; then
echo
echo -e "${GREEN}#########################################################################${NC}"
echo -e "${GREEN}## CLONE & INSTALL LOCAL INITIATOR...${NC}"
echo
# Added to resolve error running 'plugin help'
source ~/.profile
cd /$PLI_DEPLOY_PATH
git clone https://github.com/GoPlugin/external-Initiator
cd $PLI_INITOR_DIR
git checkout main
go install
fi
echo
echo -e "${GREEN}#########################################################################${NC}"
echo -e "${GREEN}## CREATE / REPAIR EXTERNAL INITIATOR...${NC}"
sleep 3s
export FEATURE_EXTERNAL_INITIATORS=true
plugin admin login -f "/$PLI_DEPLOY_PATH/$FILE_API"
if [ $? != 0 ]; then
echo
echo "ERROR :: Unable to Authenticate to Initiator API"
echo "ERROR :: Re-run initiators function to resole - continuting deployment"
sleep 5s
#FUNC_EXIT_ERROR;
else
echo "INFO :: Successfully Authenticated to Initiator API"
fi
### Check if intitator with name xdc already exists
sleep 0.5s
plugin initiators create $PLI_L_INIT_NAME http://localhost:8080/jobs > $PLI_INIT_RAWFILE
#&> /dev/null 2>&1
if [ $? != 0 ]; then
echo "ERROR :: Name $PLI_L_INIT_NAME already exists"
plugin initiators destroy $PLI_L_INIT_NAME
EI_FILE=$(echo "$BASH_FILE3" | sed -e 's/\.[^.]*$//') # cuts the file extension to get the namespace for pm2
pm2 stop $EI_FILE && pm2 delete $EI_FILE && pm2 reset all && pm2 save # deletes existing EI process
sleep 1s
plugin initiators create $PLI_L_INIT_NAME http://localhost:8080/jobs > $PLI_INIT_RAWFILE
else
echo "INFO :: Successfully created Initiator"
fi
echo
echo -e "${GREEN}#########################################################################${NC}"
echo -e "${GREEN}## CAPTURE INITIATOR CREDENTIALS & FILE MANIPULATION...${NC}"
sed -i 's/ ║ /,/g;s/╬//g;s/═//g;s/║//g' $PLI_INIT_RAWFILE
sed -n '/'"$PLI_L_INIT_NAME"'/,//p' $PLI_INIT_RAWFILE > $PLI_INIT_DATFILE
sed -i 's/,/\n/g;s/^.'"$PLI_L_INIT_NAME"'//g' $PLI_INIT_DATFILE
sed -i 's/^http.*//g' $PLI_INIT_DATFILE
sed -i.bak '/^$/d;/^\s*$/d;s/[ \t]\+$//' $PLI_INIT_DATFILE
cp -n $PLI_INIT_DATFILE ~/$PLI_INIT_DATFILE.bak && chmod 600 ~/$PLI_INIT_DATFILE.bak
cat $PLI_INIT_DATFILE
sleep 1s
echo
echo -e "${GREEN}#########################################################################${NC}"
echo -e "${GREEN}## READ INITIATOR CREDENTIALS AS VARIABLES...${NC}"
echo
read -r -d '' EXT_ACCESSKEY EXT_SECRET EXT_OUTGOINGTOKEN EXT_OUTGOINGSECRET <$PLI_INIT_DATFILE
sleep 2s
echo
echo -e "${GREEN}#########################################################################${NC}"
echo -e "${GREEN}## CREATE INITIATOR PM2 SERVICE FILE: $BASH_FILE3 & file perms ${NC}"
cd /$PLI_DEPLOY_PATH
cat <<EOF > $BASH_FILE3
#!/bin/bash
export EI_DATABASEURL=postgresql://postgres:${DB_PWD_NEW}@127.0.0.1:5432/plugin_mainnet_db?sslmode=disable
export EI_CHAINLINKURL=http://localhost:6688
export EI_IC_ACCESSKEY=${EXT_ACCESSKEY}
export EI_IC_SECRET=${EXT_SECRET}
export EI_CI_ACCESSKEY=${EXT_OUTGOINGTOKEN}
export EI_CI_SECRET=${EXT_OUTGOINGSECRET}
echo *** Starting EXTERNAL INITIATOR ***
external-initiator "{\"name\":\"$PLI_E_INIT_NAME\",\"type\":\"xinfin\",\"url\":\"https://plixdcrpc.icotokens.net\"}" --chainlinkurl "http://localhost:6688/"
EOF
#sleep 1s
#cat $BASH_FILE3
chmod u+x $BASH_FILE3
echo
echo -e "${GREEN}#########################################################################${NC}"
echo -e "${GREEN}## START INITIATOR PM2 SERVICE $BASH_FILE3 ${NC}"
pm2 start $BASH_FILE3
sleep 1s
pm2 status
sleep 3s
pm2 startup systemd
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u $USER_ID --hp /home/$USER_ID
pm2 save
if [ "$_OPTION" == "initiator" ]; then
echo "CREATE / REPAIR EXTERNAL INITIATOR COMPLETED"
FUNC_EXIT;
fi
FUNC_LOGROTATE;
if [ "$_OPTION" == "fullnode" ]; then
echo "...INITIAL SETUP FOR BACKUP FOLDER & PERMS"
bash ~/$PLI_DEPLOY_DIR/_plinode_setup_bkup.sh
fi
echo
echo -e "${GREEN}#########################################################################${NC}"
echo -e "${GREEN}#########################################################################${NC}"
echo
echo -e "${RED}## IMPORTANT INFORMATION - PLEASE RECORD TO YOUR PASSWORD SAFE${NC}"
echo
echo -e "${GREEN}#########################################################################${NC}"
echo
echo
echo -e "${RED}## KEY STORE SECRET: $PASS_KEYSTORE${NC}"
echo
echo -e "${RED}## POSTGRES DB PASSWORD: $DB_PWD_NEW${NC}"
echo
echo -e "${RED}## API USERNAME: $API_EMAIL${NC}"
echo -e "${RED}## API PASSWORD: $API_PASS${NC}"
echo
echo -e "${GREEN}#########################################################################${NC}"
echo -e "${GREEN}#########################################################################${NC}"
#source ~/.profile
#set -x
source ~/.profile
export GOROOT=/usr/local/go
export GOPATH=$HOME/work
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export FEATURE_EXTERNAL_INITIATORS=true
. ~/.profile
FUNC_NODE_ADDR;
FUNC_NODE_GUI_IPADDR;
FUNC_EXIT;
}
FUNC_DO_INIT_CHECK(){
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## CONFIRM SCRIPTS EXPORT VALUES HAVE BEEN UPDATED...${NC}"
while true; do
read -t10 -r -p "Do you wish to proceed to INITIATOR SETUP ? (Y/n) " _input
if [ $? -gt 128 ]; then
echo "timed out waiting for user response - proceeding as normal..."
FUNC_INITIATOR;
fi
case $_input in
[Yy][Ee][Ss]|[Yy]* )
FUNC_INITIATOR
break
;;
[Nn][Oo]|[Nn]* )
FUNC_EXIT
;;
* ) echo "Please answer (y)es or (n)o."
echo "NOTE: timeout value is (y)es";;
esac
done
}
FUNC_LOGROTATE(){
# add the logrotate conf file
# check logrotate status = cat /var/lib/logrotate/status
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## ADDING LOGROTATE CONF FILE...${NC}"
sleep 2s
USER_ID=$(getent passwd $EUID | cut -d: -f1)
if [ "$USER_ID" == "root" ]; then
cat <<EOF > /tmp/tmpplugin-logs
/$USER_ID/.pm2/logs/*.log
/$USER_ID/.plugin/*.jsonl
/$USER_ID/.cache/*.logf
{
su $USER_ID $USER_ID
rotate 10
copytruncate
daily
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate >/dev/null 2>&1 || true
endscript
}
EOF
else
cat <<EOF > /tmp/tmpplugin-logs
/home/$USER_ID/.pm2/logs/*.log
/home/$USER_ID/.plugin/*.jsonl
/home/$USER_ID/.cache/*.logf
{
su $USER_ID $USER_ID
rotate 10
copytruncate
daily
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate >/dev/null 2>&1 || true
endscript
}
EOF
fi
sudo sh -c 'cat /tmp/tmpplugin-logs > /etc/logrotate.d/plugin-logs'
}
FUNC_NODE_ADDR(){
cd ~/plugin-deployment
plugin admin login -f .env.apicred
node_keys_arr=()
IFS=$'\n' read -r -d '' -a node_keys_arr < <( plugin keys eth list | grep Address && printf '\0' )
node_key_primary=$(echo ${node_keys_arr[0]} | sed s/Address:[[:space:]]/''/)
echo
echo -e "${GREEN}Your Plugin node regular address is:${NC} ${RED}$node_key_primary ${NC}"
echo
echo -e "${GREEN}#########################################################################${NC}"
}
FUNC_NODE_GUI_IPADDR(){
echo
echo -e "${GREEN}Your Plugin node GUI IP address is as follows:${NC}"
echo
echo -e " ${RED}https://$(hostname -I | awk '{print $1}'):6689${NC}"
echo
echo -e "${GREEN}#########################################################################${NC}"
}
FUNC_EXIT(){
# remove the sudo timeout for USER_ID
sudo sh -c 'rm -f /etc/sudoers.d/plinode_deploy'
source ~/.profile
exit 0
}
FUNC_EXIT_ERROR(){
exit 1
}
#clear
case "$1" in
fullnode)
_OPTION="fullnode"
FUNC_NODE_DEPLOY
#FUNC_VALUE_CHECK
;;
initiator)
_OPTION="initiator"
FUNC_INITIATOR
;;
keys)
FUNC_EXPORT_NODE_KEYS
;;
logrotate)
FUNC_LOGROTATE
;;
address)
FUNC_NODE_ADDR
;;
node-gui)
FUNC_NODE_GUI_IPADDR
;;
*)
echo
echo
echo "Usage: $0 {function}"
echo
echo " example: " $0 fullnode""
echo
echo
echo "where {function} is one of the following;"
echo
echo " fullnode == deploys the full node incl. external initiator & exports the node keys"
echo
echo " initiator == creates / rebuilds the external initiator only"
echo
echo " keys == extracts the node keys from DB and exports to json file for import to MetaMask"
echo
echo " logrotate == implements the logrotate conf file "
echo
echo " address == displays the local nodes address (after fullnode deploy) - required for the 'Fulfillment Request' remix step"
echo
echo " node-gui == displays the local nodes full GUI URL to copy and paste to browser"
echo
esac