-
Notifications
You must be signed in to change notification settings - Fork 3
/
MatrixInstaller.sh
executable file
·592 lines (575 loc) · 30.7 KB
/
MatrixInstaller.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
#!/bin/bash
# check if user has sudo/root privileges
if [ $(whoami) != root ]; then
echo "Please run as root or use sudo"
exit
fi
#set script to exit on any errors
set -e
# install dependencies
apt install whiptail curl wget -y
# some colors
RES=$(echo -en '\001\033[0m\002')
LBLUE=$(echo -en '\001\033[01;34m\002')
# This is a long list of functions
pause(){
read -p "$*"
}
banner(){
echo ${LBLUE}
curl https://raw.githubusercontent.com/disarmm/MatrixSetup/master/banner
echo ${RES}
}
lb(){
printf "\n"
}
confirm(){
if (whiptail --title "Confirmation" --yesno "Please confirm you wish to continue" 8 75); then
:
else
echo >&2 "INSTALLATION ABORTED!!"
exit 1
fi
}
nameContainer(){
containerName=$(whiptail --title "Matrix AI Network Installer" --inputbox "Please choose a name for your container" 12 80 3>&1 1>&2 2>&3)
}
destContainerPath(){
t=0
Q=()
while read -r nline; do
let t=$t+1
Q+=($t "$nline")
done < <( df | grep /dev/ | grep -v "100%" | grep -v "tmpfs" | awk '0+$4 >= 75000000 {print}' | awk '{print $6}' )
InstTYPE=$(whiptail --title "Choose an install path" --menu "Please choose an install path. These options all provide at least 75GB of free space for your masternode." 22 80 12 "${Q[@]}" 3>&1 1>&2 2>&3)
exitStatus=$?
if [ ${exitStatus} = 0 ]; then
newMatrixPath=$(readlink -f $(df | grep /dev/ | grep -v "100%" | grep -v "tmpfs" | awk '0+$4 >= 75000000 {print}' | awk '{print $6}' | sed -n "`echo "$InstTYPE p" | sed 's/ //'`") )
if (whiptail --title "Confirmation" --yesno "You have chosen to install to \n\n${newMatrixPath}/matrixDocker\n\nLocated on the following device:\n\n$(df -h ${newMatrixPath})\n\nAre you sure?" 18 90 20); then
:
else
whiptail --title "Matrix AI Network Installer" --msgbox "Please choose another option..." 12 80 && destContainerPath
fi
fi
}
addMaint(){
wget -O /usr/local/bin/nodeMaint https://raw.githubusercontent.com/disarmm/MatrixScripts/master/nodeMaint.sh
chmod a+x /usr/local/bin/nodeMaint
}
storageCheck(){
freeSpaceOptionCount=$(df | grep /dev/ | grep -v "100%" | grep -v "tmpfs" | awk '0+$4 >= 75000000 {print}' | awk '{print $6}' | wc -l)
if [ ${freeSpaceOptionCount} = 0 ]; then
whiptail --title "Matrix AI Network Installer" --msgbox "You do not have at least 75GG free space available on a single device" 12 80
echo >&2 "INSTALLATION ABORTED!! Please check your available disk space."
exit 1
else
:
fi
}
checkForContainerUpdate(){
if [ "$(docker pull disarmm/matrix | grep "Status: Image is up to date for disarmm/matrix:latest" | wc -l)" -eq 1 ]; then
if (whiptail --title "Confirmation Dialog" --yesno "You already have the newest version, would you like to update/repair anyway?" 8 78); then
:
else
exit 1
fi
# echo >&2 "Your docker container is already up-to-date"
# exit 1
else
echo "Container image successfully updated"
fi
}
isDockerInstalled(){
if [ -x "$(command -v docker)" ]; then
:
else
echo >&2 "Docker not installer, please choose new docker setup first"
exit 1
fi
}
addLogCleanUpScript(){
if [ "$(crontab -l | grep logCleanUp | wc -l)" -eq 0 ]; then
wget -O /usr/local/bin/logCleanUp https://raw.githubusercontent.com/disarmm/MatrixScripts/master/logCleanUp.sh
chmod a+x /usr/local/bin/logCleanUp
cronadd="0 1 * * * /usr/local/bin/logCleanUp"
(crontab -u root -l; echo "$cronadd" ) | crontab -u root -
fi
}
lb
# intro stuff
whiptail --title "Matrix AI Network Installer" --msgbox "This installer will help you install your Matrix Node to any hard drive partition that has at least 100 GB of free space." 8 65
whiptail --title "Matrix AI Network Installer" --msgbox "PLEASE READ EVERY PROMPT CAREFULLY TO AVOID DATA LOSS" 8 57
whiptail --title "Matrix AI Network Installer" --msgbox "This installer will walk you through a few different types of installations. There are several steps that require confirmation before any files or data will be modified. Pressing [Esc] will halt the install and you will have several prompts that allow you to abort the install. If you have any questions or concerns, reach out to the community in telegram before proceeding. This installer is meant to replace the linux guides and should make things easier. Feedback is always welcome @pencekey on telegram." 14 100
# define functions for different install types
newStandalone(){
whiptail --title "Matrix AI Network - Installer" --msgbox "This installation type will install your matrix mining node as a standalone node starting with the snapshot at block 1784250. With this installation type, you will not be able to run multiple nodes on this machine. If you would like to run multiple nodes now, or think you might in the future, it is best to start over and choose the new docker node setup." 14 100
confirm
storageCheck
i=0
W=()
while read -r line; do
let i=$i+1
W+=($i "$line")
done < <( df | grep /dev/ | grep -v "100%" | grep -v "tmpfs" | awk '0+$4 >= 75000000 {print}' | awk '{print $6}' )
ITYPE=$(whiptail --title "Choose an install path" --menu "Please choose an install path. These options all provide at least 75GB of free space for your masternode." 22 80 12 "${W[@]}" 3>&1 1>&2 2>&3)
exitStatus=$?
if [ ${exitStatus} = 0 ]; then
matrixPath=$(readlink -f $(df | grep /dev/ | grep -v "100%" | grep -v "tmpfs" | awk '0+$4 >= 75000000 {print}' | awk '{print $6}' | sed -n "`echo "$ITYPE p" | sed 's/ //'`") )
if (whiptail --title "Confirmation" --yesno "You have chosen to install to \n\n${matrixPath}/matrix\n\n$(df -h ${matrixPath}) \n\nAre you sure?" 18 90 20); then
:
else
whiptail --title "Matrix AI Network Installer" --msgbox "Installation is restarting..." 12 80 && newStandalone
fi
fi
if [ -d ${matrixPath}/matrix ]; then
whiptail --title "WARNING" --msgbox "${matrixPath}/matrix path already exists, please choose different path or installation type" 12 80 && newStandalone
fi
# create signAccount file
manWallet=$(whiptail --title "Creating signAccount.json file..." --inputbox "Please enter your wallet B address" 12 80 3>&1 1>&2 2>&3)
whiptail --title "Creating signAccount.json file..." --msgbox "You are about to enter your Wallet B password. This is the password used to unlock your wallet.\n\nYOUR WALLET B PASSWORD SHOULD BE DIFFERENT THAN YOUR WALLET A PASSWORD" 12 80
manPasswd=$(whiptail --title "Creating signAccount.json file..." --inputbox "This password is stored only in your signAccount.json file, which is deleted after your entrust file is created.\n\nPlease enter your wallet B password" 12 80 3>&1 1>&2 2>&3)
mkdir -p $matrixPath/matrix/
echo -e '[\n{\n"Address":"'$manWallet'",\n"Password":"'$manPasswd'"\n}\n]' > $matrixPath/matrix/signAccount.json
clear
# another obvious section.. downloading the files...
banner
lb
echo "Downloading and installing files..."
sleep 2
lb
wget www2.matrixainetwork.eu/snapshots/1784250.tar.gz -O $matrixPath/matrix/1784250.tar.gz && mkdir $matrixPath/matrix/snapdir && tar -zxvf $matrixPath/matrix/1784250.tar.gz -C $matrixPath/matrix/snapdir
lb
wget https://github.com/MatrixAINetwork/GMAN_CLIENT/raw/master/MAINNET/1022/linux/gman -O $matrixPath/matrix/gman && chmod a+x /$matrixPath/matrix/gman
lb
wget https://raw.githubusercontent.com/MatrixAINetwork/GMAN_CLIENT/master/MAINNET/1022/MANGenesis.json -O $matrixPath/matrix/MANGenesis.json
lb
mkdir $matrixPath/matrix/chaindata/keystore
rm $matrixPath/matrix/1784250.tar.gz
# create encrypted entrust file
whiptail --title "Creating entrust.json file..." --msgbox "On the next page you will be creating the password used to start your node. It should be different than the password you use to unlock your wallet in the wallet app. Please choose a password that is different than the password used to unlock your wallet A or wallet B in the wallet app." 12 80
# running gman command to create entrust file
clear
banner
echo "Creating entrust.json file..."
lb
$matrixPath/matrix/gman --datadir $matrixPath/matrix/chaindata aes --aesin $matrixPath/matrix/signAccount.json --aesout $matrixPath/matrix/entrust.json
# removing plain text signAccount.json
rm $matrixPath/matrix/signAccount.json
# create keystore wallet file
matrixKeystore=$(whiptail --title "Creating wallet B keystore file..." --inputbox "Open your downloaded UTC wallet file with wordpad or notepad++ and copy/paste the contents below" 12 80 3>&1 1>&2 2>&3)
echo "$matrixKeystore" > $matrixPath/matrix/chaindata/keystore/${manWallet}
# creating easy startup script
echo -e "#!/bin/bash\ncd $matrixPath/matrix\nif [ ! -f "$matrixPath/matrix/firstRun" ]; then\n touch $matrixPath/matrix/firstRun && $matrixPath/matrix/gman --datadir $matrixPath/matrix/chaindata --networkid 1 --debug --verbosity 1 --port 50505 --manAddress $manWallet --entrust /$matrixPath/matrix/entrust.json --gcmode archive --outputinfo 1 --syncmode full --loadsnapfile "TrieData1784250"\nelse\n $matrixPath/matrix/gman --datadir $matrixPath/matrix/chaindata --networkid 1 --debug --verbosity 1 --port 50505 --manAddress $manWallet --entrust $matrixPath/matrix/entrust.json --gcmode archive --outputinfo 1 --syncmode full\nfi" > $matrixPath/matrix/gmanClient.sh
chmod 775 $matrixPath/matrix/gmanClient.sh
# copy start script
cp $matrixPath/matrix/gmanClient.sh /usr/local/bin/gmanClient
# finished!
whiptail --title "Matrix AI Network - Installer" --msgbox " Installation Complete!\n\nYou can type gmanClient from any path and your Matrix node will start magically" 12 80
}
updateStandaloneSnapshot()
{
whiptail --title "Matrix AI Network Installer" --msgbox "This installation type will locate wherever you currently have your node installed and update the gman files necessary to continue mining. This option will also replace your chaindata with the snapshot from block 1784250. This option is not meant to be used with the docker installation. If you need to update your docker files, or would like to keep your existing chaindata, please restart this installer and choose the correct option." 14 100
confirm
# perform pre-check for previous installations
if [ $(find / -name gman ! -type d | wc -l) -eq 0 ]; then
whiptail --title "ERROR" --msgbox "The installer cannot find any previous installations. Please install using option 1 or contact @pencekey for help on telegram"
exit 1
fi
echo "Searching for previous installations. Please wait..."
i=0
W=()
while read -r line; do
let i=$i+1
W+=($i "$line")
done < <( find / -name gman ! -type d )
clear
IPATH=$(whiptail --title "Matrix AI Network - Installer" --menu "The following paths have been identified as previous installations.\n\nPlease select the Matrix path you would like to update" 22 80 12 "${W[@]}" 3>&1 1>&2 2>&3)
exitStatus=$?
if [ ${exitStatus} = 0 ]; then
installedPath=$(readlink -f $(find / -name gman ! -type d | sed -n "`echo "$IPATH p" | sed 's/ //'`") )
if (whiptail --title "Confirmation" --yesno "You have chosen to update \n\n${installedPath} \n\nAre you sure?" 18 90 20); then
:
else
updateStandaloneSnapshot
fi
fi
gmanPath=( $(echo "$(dirname -- "$installedPath")" ) )
# warn that this kills gman
if (whiptail --title "Matrix AI Network - Installer" --yesno "This will also stop your node if it is still running\n\nWould you like to proceed?" 12 80); then
:
else
echo >&2 "INSTALLATION ABORTED!!"
exit 1
fi
# confirm
if (whiptail --title "Confirmation" --yesno "Are you sure you would like to delete your chaindata and continue with the snapshot?" 8 75); then
:
else
echo >&2 "INSTALLATION ABORTED!!"
exit 1
fi
# confirm again
if (whiptail --title "Confirmation" --yesno "Seriously, this deletes your current chaindata. Are you 100% sure you would like to continue?" 8 75); then
:
else
echo >&2 "INSTALLATION ABORTED!!"
exit 1
fi
# check if gman is stopped
if [ -z "$(pgrep gman)" ]; then
echo "gman is stopped"
else
echo "gman is still running" && lb && echo "Killing gman" && kill -9 $(pgrep gman)
fi
sleep 2
clear
banner
lb
echo "Cleaning up old files..."
sleep 2
lb
# clean up old files if they exist
if [ -f "${gmanPath}"/gman ]; then
echo "Removing gman..." && sleep 1 && rm $gmanPath/gman
fi
if [ -f "${gmanPath}"/MANGenesis.json ]; then
echo "Removing MANGenesis.json..." && sleep 1 && rm $gmanPath/MANGenesis.json
fi
if [ -f "${gmanPath}"/firstRun ]; then
echo "Removing firstRun..." && sleep 1 && rm $gmanPath/firstRun
fi
lb
echo "Backing up keystore..."
mv $gmanPath/chaindata/keystore $gmanPath/keystore
lb
echo "Removing old chaindata..."
rm -rf $gmanPath/chaindata $gmanPath/snapdir
# download new files
lb
echo "Downloading new files..."
sleep 2
lb
wget www2.matrixainetwork.eu/snapshots/1784250.tar.gz -O $gmanPath/1784250.tar.gz && mkdir $gmanPath/snapdir && tar -zxvf $gmanPath/1784250.tar.gz -C $gmanPath/snapdir/
lb
wget https://github.com/MatrixAINetwork/GMAN_CLIENT/raw/master/MAINNET/1022/linux/gman -O $gmanPath/gman && chmod a+x $gmanPath/gman
lb
wget https://raw.githubusercontent.com/MatrixAINetwork/GMAN_CLIENT/master/MAINNET/1022/MANGenesis.json -O $gmanPath/MANGenesis.json
mv $gmanPath/keystore $gmanPath/chaindata/keystore
rm $gmanPath/1784250.tar.gz
manWallet=$(whiptail --title "Creating gman startup script..." --inputbox "Please enter your wallet B address to create startup script" 12 80 3>&1 1>&2 2>&3)
# Create start script and set an alias so it will run from any path
echo -e "#!/bin/bash\ncd $gmanPath\nif [ ! -f "$gmanPath/firstRun" ]; then\n touch $gmanPath/firstRun && $gmanPath/gman --datadir $gmanPath/chaindata --networkid 1 --debug --verbosity 1 --port 50505 --manAddress $manWallet --entrust $gmanPath/entrust.json --gcmode archive --outputinfo 1 --syncmode full --loadsnapfile "TrieData1784250"\nelse\n $gmanPath/gman --datadir $gmanPath/chaindata --networkid 1 --debug --verbosity 1 --port 50505 --manAddress $manWallet --entrust $gmanPath/entrust.json --gcmode archive --outputinfo 1 --syncmode full\nfi" > $gmanPath/gmanClient.sh
chmod 755 $gmanPath/gmanClient.sh
# copy start script
cp $gmanPath/gmanClient.sh /usr/local/bin/gmanClient
# finished!
whiptail --title "Matrix AI Network - Installer" --msgbox " Installation Complete!\n\nYou can type gmanClient from any path and your Matrix node will start magically" 12 80
}
# Fucntion for updating standalone installations WITHOUT using the snapshot
updateStandaloneOnlyGman()
{
clear
whiptail --title "Matrix AI Network - Installer" --msgbox "This installation type will locate wherever you currently have your node installed and update the gman files necessary to continue mining. This verion will not replace your chaindata with the snapshot. This option is not meant to be used with the docker installation. If you need to update your docker files, or would like to use the snapshot, please restart this installer and choose the correct option." 14 100
confirm
# perform pre-check for previous installations
if [ $(find / -name gman ! -type d | wc -l) -eq 0 ]; then
whiptail --title "ERROR" --msgbox "The installer cannot find any previous installations. Please install using option 1 or contact @pencekey for help on telegram"
exit 1
fi
echo "Searching for previous installations. Please wait..."
i=0
W=()
while read -r line; do
let i=$i+1
W+=($i "$line")
done < <( find / -name gman ! -type d )
clear
IPATH=$(whiptail --title "Matrix AI Network - Installer" --menu "The following paths have been identified as previous installations.\n\nPlease select the Matrix path you would like to update" 22 80 12 "${W[@]}" 3>&1 1>&2 2>&3)
exitStatus=$?
if [ ${exitStatus} = 0 ]; then
installedPath=$(readlink -f $(find / -name gman ! -type d | sed -n "`echo "$IPATH p" | sed 's/ //'`") )
if (whiptail --title "Confirmation" --yesno "You have chosen to update \n\n${installedPath} \n\nAre you sure?" 18 90 20); then
:
else
updateStandaloneOnlyGman
fi
fi
gmanPath=( $(echo "$(dirname -- "$installedPath")" ) )
# warn that it kills gman
if (whiptail --title "Matrix AI Network - Installer" --yesno "This will also stop your node if it is still running\n\nWould you like to proceed?" 12 80); then
:
else
echo >&@ "INSTALLATION ABORTED!!"
exit 1
fi
# check if gman is stopped
if [ -z "$(pgrep gman)" ]; then
echo "gman is stopped"
else
echo "gman is still running" && lb && echo "Killing gman" && kill -9 $(pgrep gman)
fi
sleep 2
clear
banner
lb
echo "Cleaning up old files..."
sleep 2
lb
# clean up old files if they exist
if [ -f "${gmanPath}"/gman ]; then
echo "removing gman..." && sleep 1 && rm $gmanPath/gman
fi
if [ -f "${gmanPath}"/MANGenesis.json ]; then
echo "removing MANGenesis.json..." && sleep 1 && rm $gmanPath/MANGenesis.json
fi
lb
echo "Downloading new files..."
# download new files
lb
wget https://github.com/MatrixAINetwork/GMAN_CLIENT/raw/master/MAINNET/1022/linux/gman -O $gmanPath/gman && chmod a+x $gmanPath/gman
lb
wget https://raw.githubusercontent.com/MatrixAINetwork/GMAN_CLIENT/master/MAINNET/1022/MANGenesis.json -O $gmanPath/MANGenesis.json
# get address for startup script
manWallet=$(whiptail --title "Creating gman startup script..." --inputbox "Please enter your wallet B address to create startup script" 12 80 3>&1 1>&2 2>&3)
echo -e "#!/bin/bash\ncd $gmanPath\nif [ ! -f "$gmanPath/firstRun" ]; then\n touch $gmanPath/firstRun && $gmanPath/gman --datadir $gmanPath/chaindata --networkid 1 --debug --verbosity 1 --port 50505 --manAddress $manWallet --entrust $gmanPath/entrust.json --gcmode archive --outputinfo 1 --syncmode full --loadsnapfile "TrieData1784250"\nelse\n $gmanPath/gman --datadir $gmanPath/chaindata --networkid 1 --debug --verbosity 1 --port 50505 --manAddress $manWallet --entrust $gmanPath/entrust.json --gcmode archive --outputinfo 1 --syncmode full\nfi" > $gmanPath/gmanClient.sh
chmod 755 $gmanPath/gmanClient.sh
# copy start script
cp $gmanPath/gmanClient.sh /usr/local/bin/gmanClient
# finished!
whiptail --title "Matrix AI Network - Installer" --msgbox " Installation Complete!\n\nYou can type gmanClient from any path and your Matrix node will start magically" 12 80
}
newDocker(){
whiptail --title "Matrix AI Network - Installer" --msgbox "This installation type will install your matrix mining node as a new docker container with the snapshot at block 1784250. With this installation type, you will be able to run multiple nodes on this machine. If you need to install multiple docker nodes, it is recommended to fully sync with one node and then use the Docker Copy option at the main menu." 14 100
whiptail --title "Matrix AI Network - Installer" --msgbox "When naming your containers and selecting port numbers for each, it would be smart to organize them by name and port number. For example: matrix50501 for a container name and port 50501 for the port number. That way you will always know which container is associate with which port." 14 100
confirm
storageCheck
i=0
W=()
while read -r line; do
let i=$i+1
W+=($i "$line")
done < <( df | grep /dev/ | grep -v "100%" | grep -v "tmpfs" | awk '0+$4 >= 75000000 {print}' | awk '{print $6}' )
ITYPE=$(whiptail --title "Choose an install path" --menu "Please choose an install path. These options all provide at least 75GB of free space for your masternode." 22 80 12 "${W[@]}" 3>&1 1>&2 2>&3)
exitStatus=$?
if [ ${exitStatus} = 0 ]; then
matrixPath=$(readlink -f $(df | grep /dev/ | grep -v "100%" | grep -v "tmpfs" | awk '0+$4 >= 75000000 {print}' | awk '{print $6}' | sed -n "`echo "$ITYPE p" | sed 's/ //'`") )
if (whiptail --title "Confirmation" --yesno "You have chosen to install to \n\n${matrixPath}/matrixDocker\n\n$(df -h ${matrixPath}) \n\nAre you sure?" 18 90 20); then
:
else
whiptail --title "Matrix AI Network Installer" --msgbox "Installation is restarting..." 12 80 && newDocker
fi
fi
if [ -d ${matrixPath}/matrixDocker ]; then
whiptail --title "WARNING" --msgbox "${matrixPath}/matrixDocker path already exists. If you need to create another node, please use the Docker Copy installation type." 12 80 && newDocker
fi
# create container name
nameContainer
while ! [[ "$containerName" =~ ^[a-zA-Z0-9]+$ || $? -eq 1 ]]; do
whiptail --title "ERROR" --msgbox "Please choose a container name using letters and numbers only" 8 57 && nameContainer
done
# create container directory
mkdir -p $matrixPath/matrixDocker/$containerName
# choose port number to use for this container
portSelection=$(whiptail --title "Matrix AI Network - Installer" --inputbox "You will need to configure port forwarding in your router and each continaer must use a different port. It is suggested to use ports 50500-50600.\n\nPlease enter a port number" 12 80 3>&1 1>&2 2>&3)
# create signAccount file
manWallet=$(whiptail --title "Creating signAccount.json file..." --inputbox "Please enter your wallet B address" 12 80 3>&1 1>&2 2>&3)
whiptail --title "Creating signAccount.json file..." --msgbox "You are about to enter your Wallet B password. This is the password used to unlock your wallet." 12 80
manPasswd=$(whiptail --title "Creating signAccount.json file..." --inputbox "This password is stored in your signAccount.json file and is used to automatically create your entrust.json file each time your container is started.\n\nPlease enter your wallet B password" 12 80 3>&1 1>&2 2>&3)
echo -e '[\n{\n"Address":"'$manWallet'",\n"Password":"'$manPasswd'"\n}\n]' > $matrixPath/matrixDocker/$containerName/signAccount.json
clear
# another obvious section.. downloading the files...
banner
lb
if [ -x "$(command -v docker)" ]; then
echo "Docker already installed"
echo "Moving on..."
else
echo "Docker not installed"
echo "Installing docker..."
bash < <(curl https://get.docker.com)
fi
lb
echo "Downloading and installing matrix files..."
lb
mkdir $matrixPath/matrixDocker/$containerName/keystore
mkdir $matrixPath/matrixDocker/$containerName/snapdir
wget www2.matrixainetwork.eu/snapshots/1784250.tar.gz -O $matrixPath/matrixDocker/$containerName/1784250.tar.gz && tar -zxvf $matrixPath/matrixDocker/$containerName/1784250.tar.gz -C $matrixPath/matrixDocker/$containerName/snapdir --no-same-owner
lb
rm $matrixPath/matrixDocker/$containerName/1784250.tar.gz
# create keystore wallet file
matrixKeystore=$(whiptail --title "Creating wallet B keystore file..." --inputbox "Open your downloaded UTC wallet file with wordpad or notepad++ and copy/paste the contents below" 12 80 3>&1 1>&2 2>&3)
echo "$matrixKeystore" > $matrixPath/matrixDocker/$containerName/keystore/${manWallet}
docker pull disarmm/matrix
lb
docker run -d --restart unless-stopped -e MAN_PORT=${portSelection} -p ${portSelection}:${portSelection} -v $matrixPath/matrixDocker/$containerName:/matrix/chaindata --name $containerName disarmm/matrix
# add nodeMaint script
addMaint
# finished!
whiptail --title "Matrix AI Network - Installer" --msgbox " Docker Installation Complete!\n\n" 12 80
}
updateContainerOnly(){
if [ -x "$(command -v docker)" ]; then
:
else
echo >&2 "Docker not installed, please choose new docker setup first"
exit 1
fi
whiptail --title "Matrix AI Network - Updater" --msgbox "This option will update your container image without modifying any of your chaindata. It will remove your existing containers, update the container image, then recreate your containers using the same ports and chaindata as before. This will not affect other non-matrix containers on your system. \n\n(Confirm on next screen)" 14 100
confirm
# check if docker is installed
isDockerInstalled
# Check if update is needed
checkForContainerUpdate
lb
# Pull current container info and recreate with new image
for cont in $(docker ps -a --format '{{.Names}}') ; do
if [ $(docker inspect -f '{{eq "/matrix/nodeConfig.sh" .Path}}' $cont) = "true" ]; then
echo "Updating container..."
contPort=$(docker inspect -f '{{.HostConfig.PortBindings}}' $cont | cut -d "[" -f 2 | cut -d "/" -f 1)
hostVol=$(docker inspect -f '{{ .Mounts }}' $cont | cut -d " " -f 3)
docker stop $cont && docker rm $cont
docker run -d --restart unless-stopped -e MAN_PORT=${contPort} -p ${contPort}:${contPort} -v ${hostVol}:/matrix/chaindata --name $cont disarmm/matrix
lb
fi
done
# add latest version of nodeMaint
addMaint
# add latest version of logCleanUp
addLogCleanUpScript
# finished!
whiptail --title "Matrix AI Network - Updater" --msgbox " Container Images updated!\n\n" 12 80
}
copyDocker(){
if [ -x "$(command -v docker)" ]; then
:
else
echo >&2 "Docker not yet installed, please choose the 'Docker - New install with latest snapshot' setup first"
exit 1
fi
whiptail --title "Matrix AI Network - Installer" --msgbox "This installer option will help you copy your chaindata from an existing container to a new container. You should fully sync your existing node before copying. If you haven't finished syncing, please select no on the next screen and finish syncing first. For more advanced options please choose the advanced docker copy option." 14 100
confirm
storageCheck
whiptail --title "Matrix AI Network - Installer" --msgbox "FYI - When naming your containers and selecting port numbers for each, it would be smart to organize them by name and port number. For example: matrix50501 as a container name using port 50501 for the port number. That way you will always know which container is associate with which port. You CAN use any port, but stick to ports 50500-50600." 14 100
# select which container to copy docker
i=0
W=()
while read -r line; do
let i=$i+1
W+=($i "$line")
done < <( docker ps -a --format '{{.Names}}' )
ITYPE=$(whiptail --title "Select docker to copy" --menu "Please choose a current docker container where you would like to copy data from." 22 80 12 "${W[@]}" 3>&1 1>&2 2>&3)
exitStatus=$?
if [ ${exitStatus} = 0 ]; then
currentDocker=$(docker ps -a --format '{{.Names}}' | sed -n "`echo "$ITYPE p" | sed 's/ //'`")
dockerMount=$(df -h $(docker inspect -f '{{ .Mounts }}' ${currentDocker} | awk {'print $2'}) | sed -n '2 p')
if (whiptail --title "Confirmation" --yesno "You have chosen to copy from container: ${currentDocker} \n\nLocated on the following device:\n${dockerMount} \n\nAre you sure?" 18 90 20); then
:
else
whiptail --title "Matrix AI Network Installer" --msgbox "Installation is restarting..." 12 80 && copyDocker
fi
fi
# set path for later use
copyFrom=$(docker inspect -f '{{ .Mounts }}' ${currentDocker} | awk {'print $2'})
# choose a destination path
tempMatrixPath=$(dirname -- "$(docker inspect -f "{{ .Mounts }}" ${currentDocker} | cut -d " " -f 3)" )
optionP=$(whiptail --title "Matrix AI Network - Installer" --menu "Would you like to install your new node in the same path as your existing node? \n\n${tempMatrixPath} \n\nLocated on the following device:\n\n$(df -h ${tempMatrixPath} | sed -n '2 p')" 18 100 2 "1" "yes" "2" "no" 3>&1 1>&2 2>&3)
if [[ "${optionP}" == "2" ]]; then
destContainerPath
matrixPath=${newMatrixPath}/matrixDocker
elif [[ "${optionP}" == "1" ]]; then
matrixPath=${tempMatrixPath}
fi
# create container name
nameContainer
while ! [[ "$containerName" =~ ^[a-zA-Z0-9]+$ || $? -eq 1 ]]; do
whiptail --title "ERROR" --msgbox "Please choose a container name using letters and numbers only" 8 57 && nameContainer
done
# create container directory
mkdir -p $matrixPath/$containerName
# set path for later use
copyTo=${matrixPath}/${containerName}
# choose port number to use for this container
portSelection=$(whiptail --title "Matrix AI Network - Installer" --inputbox "You will need to configure port forwarding in your router and each continaer must use a different port. It is suggested to use ports 50500-50600.\n\nPlease enter a port number" 12 80 3>&1 1>&2 2>&3)
# create signAccount file
manWallet=$(whiptail --title "Creating signAccount.json file..." --inputbox "Please enter your wallet B address" 12 80 3>&1 1>&2 2>&3)
whiptail --title "Creating signAccount.json file..." --msgbox "You are about to enter your Wallet B password. This is the password used to unlock your wallet." 12 80
manPasswd=$(whiptail --title "Creating signAccount.json file..." --inputbox "This password is stored in your signAccount.json file and is used to automatically create your entrust.json file each time your container is started.\n\nPlease enter your wallet B password" 12 80 3>&1 1>&2 2>&3)
echo -e '[\n{\n"Address":"'$manWallet'",\n"Password":"'$manPasswd'"\n}\n]' > $matrixPath/$containerName/signAccount.json
clear
# Copying the chaindata...
banner
lb
echo "Stopping container..."
docker stop ${currentDocker}
echo "Preparing to copy chaindata..."
sleep 3
mkdir $matrixPath/$containerName/keystore
mkdir $matrixPath/$containerName/snapdir
lb
echo "Copying chaindata from ${currentDocker} to ${containerName}"
lb
rsync -av --info=progress2 ${copyFrom}/gman ${copyTo}/
rsync -av --info=progress2 ${copyFrom}/picstore ${copyTo}/
touch ${copyTo}/firstRun
lb
rm ${copyTo}/gman/LOCK ${copyTo}/gman/nodekey ${copyTo}/gman/chaindata/LOCK
lb
echo "Starting original docker container..."
docker start ${currentDocker}
sleep 1
# create keystore wallet file
matrixKeystore=$(whiptail --title "Creating wallet B keystore file..." --inputbox "Open your downloaded UTC wallet file with wordpad or notepad++ and copy/paste the contents below" 12 80 3>&1 1>&2 2>&3)
echo "$matrixKeystore" > $matrixPath/$containerName/keystore/${manWallet}
# check for container updates
echo "Checking for container updates..."
docker pull disarmm/matrix
lb
docker run -d --restart unless-stopped -e MAN_PORT=${portSelection} -p ${portSelection}:${portSelection} -v $matrixPath/$containerName:/matrix/chaindata --name $containerName disarmm/matrix
# add nodeMaint script
addMaint
# finished!
whiptail --title "Matrix AI Network - Installer" --msgbox " Docker Installation Complete!\n\n" 12 80
}
manChoice=$(
whiptail --title "Matrix AI Network Installer" --menu "How do you like your MAN?" 25 90 9 \
'1)' "Standalone - New intall with latest snapshot" \
'2)' "Standalone - Update current install with snapshot" \
'3)' "Standalone - Update current install without snapshot" \
'4)' "Docker - New install with latest snapshot" \
'5)' "Docker - Replace chaindata with latest snapshot block 1784250(coming soon)" \
'6)' "Docker - Update container image" \
'7)' "Docker - Copy node" \
'8)' "Docker - Copy node - Advanced options(coming soon)" \
'9)' "exit" 3>&2 2>&1 1>&3
)
case $manChoice in
"1)")
newStandalone
;;
"2)")
updateStandaloneSnapshot
;;
"3)")
updateStandaloneOnlyGman
;;
"4)")
newDocker
;;
"5)")
echo "Install Option Coming Soon"
exit
;;
"6)")
updateContainerOnly
;;
"7)")
copyDocker
;;
"8)")
echo "Install Option Coming Soon"
exit
;;
"9)")
exit
;;
esac