-
Notifications
You must be signed in to change notification settings - Fork 6
/
nym_install.sh
638 lines (576 loc) · 29.8 KB
/
nym_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
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
#!/bin/bash
############################################################################
## This is an unofficial nym-mixnode installer, which downloads, configures
## and runs the Nym mixnode in less than 1 minute.
## It creates a nym user which runs the node with a little help of
## a systemd. It automates even the systemd.service creation, so
## everytime you change your node config, simply just do it with this script
## to make sure your Nym-mixnode is running and mixin' packets!
## -------------------------------------------------------------------------
## All credits go to the Nym team, creators of BASH, other FOSS used
## and some random people on stackoverflow.com.
## There might be some bugs in this script ... !
## So you'd better run this piece with caution.
## I will be not responsible if you fuck up your own machine with this.
##
## turn_on_tune_in_drop_out
############################################################################
function display_usage() {
#printf "%b\n\n\n" "${WHITE}This script must be run with super-user privileges."
#echo -e "\nUsage:\n__g5_token5eefd24a11c4a [arguments] \n"
cat 1>&2 <<EOF
nym_install.sh 0.10.0 (2021-22-04)
The installer and launcher for Nym mixnode v0.10.0
USAGE:
./nym_install.sh [FLAGS]
FLAGS:
-t --testnet Display testnet help and steps
-i --install Full installation and setup
-c --config Run only the init command without installation
-r, --run Start the node without installation
-m --claim Display the claim output of your node
-g --sign Sign your node
-h, --help Prints help information
-V, --version Prints version information
-s --status Prints status of the running node
-f --firewall Firewall setup
-p --print Create nym-mixnode.service for systemd
-l --print-local Create nym-mixnode.service for systemd LOCALLY in the current directory
-u --update Update the node to the latest release and choose an address for the incetives.
EOF
}
## Colours variables for the installation script
RED='\033[1;91m' # WARNINGS
YELLOW='\033[1;93m' # HIGHLIGHTS
WHITE='\033[1;97m' # LARGER FONT
LBLUE='\033[1;96m' # HIGHLIGHTS / NUMBERS ...
LGREEN='\033[1;92m' # SUCCESS
NOCOLOR='\033[0m' # DEFAULT FONT
## required packages list
install_essentials='curl ufw sudo git pkg-config build-essential libssl-dev'
## Checks if all required packages are installed
## If not then it installs them with apt-get
if
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------${NOCOLOR}"
printf "%b\n\n\n" "${WHITE} Checking requirements ..."
dpkg-query -l 'curl' 'ufw' 'sudo' 'git' 'pkg-config' 'build-essential' 'libssl-dev' > /dev/null 2>&1
then
printf "%b\n\n\n" "${WHITE} You have all the required packages for this installation ..."
printf "%b\n\n\n" "${LGREEN} Continuing ..."
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------${NOCOLOR}"
else
printf "%b\n\n\n" "${WHITE} Some required packages for this script are not installed"
printf "%b\n\n\n" "${WHITE} Installing them for you"
apt-get update > /dev/null 2>&1 && apt-get install ${install_essentials} -y > /dev/null 2>&1
printf "%b\n\n\n" "${WHITE} Now you have all the required packages for this installation ..."
printf "%b\n\n\n" "${LGREEN} Continuing ... "
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------${NOCOLOR}"
fi
#while true; do
#printf "${RED}LOVE\n\n${YELLOW}IS\n\n${LBLUE}ALL\n\n${WHITE}YOU\n\n${LGREEN}\nNEED\n\n ${RED}========${YELLOW}========${LBLUE}========${WHITE}========${LGREEN}========\n\n"
#sleep 1
#done
## Prints the Nym banner to stdout from hex
#printf "%b\n" "0a2020202020205f205f5f20205f2020205f205f205f5f205f5f5f0a20202020207c20275f205c7c207c207c207c20275f205c205f205c0a20202020207c207c207c207c207c5f7c207c207c207c207c207c207c0a20202020207c5f7c207c5f7c5c5f5f2c207c5f7c207c5f7c207c5f7c0a2020202020202020202020207c5f5f5f2f0a0a20202020202020202020202020286d69786e6f6465202d2076657273696f6e20302e392e3129" | xxd -p -r
## Checks if essential packages are installed
## if not then it installs them
#dpkg-query -l 'curl' 'ufw' 'sudo' 'git' 'pkg-config' 'build-essential' 'libssl-dev' 'asdasd' > /dev/null 2>&1 || apt
# creates a user nym with home directory
function nym_usercreation() {
printf "%b\n\n\n"
printf "%b\n\n\n" "${YELLOW} Creating ${WHITE} nym user\n\n"
if [ ! -d /home/nym ]
then
useradd -U -m -s /sbin/nologin nym
printf "%b\n\n\n" "${WHITE} User ${YELLOW} nym ${LGREEN} created ${WHITE} with a home directory at ${YELLOW} /home/nym/"
else
printf "%b\n\n\n" "${WHITE} Something went ${RED} wrong ${WHITE} and the user ${YELLOW} nym ${WHITE}was ${RED} not created."
fi
}
## Checks if nym user exists and then download the latest nym-mixnode binaries to nym home directory
function nym_download() {
VERSION=$(curl https://github.com/nymtech/nym/releases/latest --cacert /etc/ssl/certs/ca-certificates.crt 2>/dev/null | egrep -o "[0-9|\.]{6}(-\w+)?")
URL="https://github.com/nymtech/nym/releases/download/v$VERSION/nym-mixnode_linux_x86_64"
if
cat /etc/passwd | grep nym > /dev/null 2>&1
then
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${YELLOW} Downloading ${WHITE} nym-mixnode binaries for the nym user ..."
cd /home/nym && curl -L -s "$URL" -o "nym-mixnode" --cacert /etc/ssl/certs/ca-certificates.crt && echo "Fetching the latest version"
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} nym-mixnode binaries ${LGREEN} successfully downloaded ${WHITE}!"
else
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Download ${RED} failed...${NOCOLOR}"
fi
}
## checks for the binaries and then makes them executable
function nym_chmod() {
if ls -la /home/nym/ | grep nym-mixnode > /dev/null 2>&1
then
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${WHITE} Making the nym binary ${YELLOW} executable ..."
chmod 755 /home/nym/nym-mixnode
printf "%b\n\n\n" "${LGREEN} Successfully ${WHITE} made the file ${YELLOW} executable !${NOCOLOR}"
else
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${WHITE} Something went ${RED} wrong, wrong path..?${NOCOLOR}"
fi
}
## change ownerships of all files within nym home directory / they were downloaded as root so now we return them back to nym
function nym_chown() {
chown -R nym:nym /home/nym/
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${WHITE} Changed ownership of all conentes in ${YELLOW}/home/nym/ ${WHITE} to ${YELLOW}nym:nym"
}
## Get server ipv4
#ip_addr=`curl -sS v4.icanhazip.com`
## Check if ufw is enabled or not and allows 1789/tcp and 22/tcp
function nym_ufw {
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${WHITE} Setting up the ${YELLOW} firewall ${WHITE}: "
ufw status | grep -i in && inactive="1" || is_active="1" > /dev/null 2>&1
if [ "${inactive}" == 1 ]
then
printf '\n\n\n'
printf "%b\n\n\n" "${YELLOW} ufw ${WHITE} (Firewall) is ${RED} inactive"
sleep 1
printf '\n\n\n'
printf "%b\n\n\n" "${LGREEN} Enable it ${WHITE} and ${LGREEN} allow rules ${WHITE}for Nym-mixnode?\n"
while true ; do
read -p $'\e[1;92m[\e[0m\e[1;77m*\e[0m\e[1;37m] Do you want to continue \e[1;92mYes - (Yy) \e[1;37m or \e[1;91mNo - (Nn) ?? : \e[0m' yn
printf '\n\n\n'
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac
done
ufw allow 1789/tcp > /dev/null 2>&1 && printf "%b\n\n\n" "${YELLOW} port ${LBLUE} 1789 ${WHITE} was ${LGREEN}allowed ${WHITE} in ufw settings"
## Allow ssh just in case
## To avoid locking the user from the server
ufw allow 22/tcp && ufw limit 22/tcp
ufw enable
ufw status
else [ "$is_active" == 1 ]
printf '\n\n\n'
printf "%b\n\n\n" "${YELLOW} ufw ${WHITE} (Firewall) is ${LGREEN} active"
sleep 1
printf '\n\n\n'
printf "%b\n\n\n" "${LGREEN} allow rules ${WHITE} for Nym-mixnode?"
printf "%b\n\n\n"
while true ; do
read -p $'\e[1;92m[\e[0m\e[1;77m*\e[0m\e[1;37m] Do you want to continue \e[1;92mYes - (Yy) \e[1;37m or \e[1;91mNo - (Nn) ?? : \e[0m' yn
printf '\n\n\n'
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac
done
ufw allow 1789/tcp > /dev/null 2>&1 && printf "%b\n\n\n" "${YELLOW} port ${LBLUE} 1789 ${WHITE} was ${LGREEN}allowed ${WHITE} in ufw settings"
ufw status
fi
}
## This creates systemd.service script
## It looks for multiple files in the /home/nym/.nym/mixnodes directory
## and prompts user for input
## which it then uses to properly print the ExecStart part in the file.
## Useful if you have multiple configs and want to quickly change the node for systemd
function nym_systemd_print() {
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${YELLOW} Creating ${WHITE} a systemd service file to run nym-mixnode in the background: "
printf "%b\n\n\n" "${WHITE} Please select a ${YELLOW} mixnode"
select d in /home/nym/.nym/mixnodes/* ; do test -n "$d" && break; printf "%b\n\n\n" "${WHITE} >>> Invalid Selection"; done
directory=$(echo "$d" | rev | cut -d/ -f1 | rev)
printf "%b\n\n\n"
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} You selected ${YELLOW} $directory"
#echo "You selected $directory"
printf "%b\n\n\n"
echo
printf "%b\n\n\n" "${WHITE} Do you want to create a systemd file for this node?\n\n\n\e[0;31m WARNING: IF YOU ALREADY HAVE ANOTHER NODE CONFIGURED THIS WILL OVERWRITE IT\e[0m\n"
printf "%b\n\n\n"
while true ; do
read -p $'\e[1;92m[\e[0m\e[1;77m*\e[0m\e[1;37m] Do you want to continue \e[1;92mYes - (Yy) \e[1;37m or \e[1;91mNo - (Nn) ?? : \e[0m' yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac
done
#id=$(echo "$i" | rev | cut -d/ -f1 | rev)
printf '%s\n' "[Unit]" > /etc/systemd/system/nym-mixnode.service
printf '%s\n' "Description=nym mixnode service" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "After=network.target" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "[Service]" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "Type=simple" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "User=nym" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "LimitNOFILE=65536" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "ExecStart=/home/nym/nym-mixnode_linux_x86_64 run --id $directory" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "KillSignal=SIGINT" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "Restart=on-failure" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "RestartSec=30" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "Restart=on-abort" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "" >> /etc/systemd/system/enym-mixnode.service
printf '%s\n' "[Install]" >> /etc/systemd/system/nym-mixnode.service
printf '%s\n' "WantedBy=multi-user.target" >> /etc/systemd/system/nym-mixnode.service
if [ -e /etc/systemd/system/nym-mixnode.service ]
then
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${WHITE} Your node with id ${YELLOW} $directory ${WHITE} was ${LGREEN} successfully written ${WHITE} to the systemd.service file \n\n\n"
printf "%b\n\n\n" " ${LGREEN} Enabling ${WHITE} it for you"
systemctl enable nym-mixnode
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${WHITE} nym-mixnode.service ${LGREEN} enabled!"
else
printf "%b\n\n\n" "${WHITE} something went wrong"
exit 2
fi
}
## For printing the systemd.service to the current folder
## and not to /etc/systemd/system/ directory
function nym_systemd_print_local() {
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "\e[1;33mPlease select a mixnode:\n"
select d in /home/nym/.nym/mixnodes/* ; do test -n "$d" && break; printf "%b\n\n\n" "${WHITE} >>> Invalid Selection"; done
directory=$(echo "$d" | rev | cut -d/ -f1 | rev)
printf "%b\n\n\n" "${WHITE} You selected ${YELLOW} $directory"
echo
printf "%b\n\n\n"
while true ; do
read -p $'\e[1;92m[\e[0m\e[1;77m*\e[0m\e[1;37m] Do you want to continue \e[1;92mYes - (Yy) \e[1;37m or \e[1;91mNo - (Nn) ?? : \e[0m' yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac
done
#id=$(echo "$i" | rev | cut -d/ -f1 | rev)
printf '%s\n' "[Unit]" > nym-mixnode.service
printf '%s\n' "Description=nym mixnode service" >> nym-mixnode.service
printf '%s\n' "After=network.target" >> nym-mixnode.service
printf '%s\n' "" >> nym-mixnode.service
printf '%s\n' "[Service]" >> nym-mixnode.service
printf '%s\n' "Type=simple" >> nym-mixnode.service
printf '%s\n' "User=nym" >> nym-mixnode.service
printf '%s\n' "LimitNOFILE=65536" >> nym-mixnode.service
printf '%s\n' "ExecStart=/home/nym/nym-mixnode_linux_x86_64 run --id $directory" >> nym-mixnode.service
printf '%s\n' "KillSignal=SIGINT" >> nym-mixnode.Service
printf '%s\n' "Restart=on-failure" >> nym-mixnode.service
printf '%s\n' "RestartSec=30" >> nym-mixnode.service
printf '%s\n' "" >> nym-mixnode.service
printf '%s\n' "[Install]" >> nym-mixnode.service
printf '%s\n' "WantedBy=multi-user.target" >> nym-mixnode.service
current_path=$(pwd)
if
[ -e ${current_path}/nym-mixnode.service ]
then
printf "%b\n\n\n" "${WHITE} Your systemd script with id $directory was ${LGREEN} successfully written ${WHITE} to the current directory"
printf "%b\n" "${YELLOW} $(pwd)"
else
printf "%b\n\n\n" "${WHITE} Printing of the systemd script to the current folder ${RED} failed. ${WHITE} Do you have ${YELLOW} permissions ${WHITE} to ${YELLOW} write ${WHITE} in ${pwd} ${YELLOW} directory ??? "
fi
}
## Checks if the path is correct and then prompts user for input to get $id and optional $location.
## Then runs the binary with the given input from user and builds config.
function nym_init() {
#get server's ipv4 address
#set -x
ip_addr=`curl -sS ipinfo.io/ip`
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${YELLOW} Configuration ${WHITE} file and keys: "
if
[[ $PWD/ != /home/nym ]] | cd /home/nym && echo $PWD
then
printf "%b\n\n\n" "${WHITE} What name do you want for your node ${YELLOW} id? "
printf "%b\n\n\n" "${WHITE} This is only for your own purposes and creates a directory with that name in ${YELLOW}/home/nym/.nym/mixnodes/<YOURID>. ${YELLOW} Config ${WHITE} and ${YELLOW} keys ${WHITE}are stored there "
printf "%b\n\n\n"
read id
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Your node name will be ${YELLOW} $id. ${WHITE} Use it nextime if you restart your server or the node is not running"
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Enter your Telegram handle beginning with @"
printf "%b\n\n\n"
read telegram
printf "%b\n\n\n" "${WHITE} Your Telegram handle for the faucet will be ${YELLOW} ${telegram} "
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
# borrows a shell for nym user to initialize the node config.
sudo -u nym -H /home/nym/nym-mixnode init --id $id --host $ip_addr && sleep 2 && sudo -u nym -H /home/nym/nym-mixnode sign --id $id --text ${telegram} 2>&1 | tee -a ${id}_claim.txt && chown nym:nym ${id}_claim.txt
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Your node has id ${YELLOW} $id ${WHITE} and has to be signed with ${LBLUE} $telegram ${WHITE} with ip ${YELLOW} $ip_addr ${WHITE}... "
printf "%b\n\n\n" "${WHITE} Config was ${LGREEN} built successfully ${WHITE}!"
else
printf "%b\n\n\n" "${WHITE} Something went ${RED} wrong {WHITE}..."
exit 2
#set +x
fi
}
function nym_systemd_run() {
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n\n\n" "${YELLOW} Launching ${WHITE} the node: "
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Please select a ${YELLOW} mixnode"
printf "%b\n\n\n"
select d in /home/nym/.nym/mixnodes/* ; do test -n "$d" && break; printf "%b\n\n\n" "${WHITE} >>> Invalid Selection"; done
directory=$(printf "%b\n\n\n" "${WHITE}$d" | rev | cut -d/ -f1 | rev)
printf "\e[1;82mYou selected\e[0m\e[3;11m ${WHITE} $directory\e[0m\n"
printf "%b\n\n\n"
service_id=$(cat /etc/systemd/system/nym-mixnode.service | grep id | cut -c 55-)
function nym_sign () {
#get server's ipv4 address printf "%b\n\n\n" "${WHITE} >>> Invalid Selection"; done
directory=$(printf "%b\n\n\n" "${WHITE}$d" | rev | cut -d/ -f1 | rev)
printf "\e[1;82mYou selected\e[0m\e[3;11m ${WHITE} $directory\e[0m\n"
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Your node name will be ${YELLOW} $id. ${WHITE} Use it nextime if you restart your server or the node is not running"
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Enter your Telegram handle beginning with @"
printf "%b\n\n\n"
read telegram
printf "%b\n\n\n" "${WHITE} Your Telegram handle for the faucet will be ${YELLOW} ${telegram} "
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
# borrows a shell for nym user to initialize the node config.
sudo -u nym -H /home/nym/nym-mixnode sign --id $directory --text ${telegram} 2>&1 | tee -a claim.txt && chown nym:nym claim.txt
printf "%b\n\n\n"
}
## Check if user chose a valid node written in the systemd.service file
if [ "$service_id" == "$directory" ]
then
printf "%b\n\n\n"
printf "%b\n\n\n" "${YELLOW} Launching ${service_id} ..."
systemctl start nym-mixnode.service
else
printf "%b\n\n\n" "${WHITE} The node you selected is ${RED} not ${WHITE} in the ${YELLOW} nym-mixnode.service ${WHITE} file. Create a new systemd.service file with ${LBLUE} sudo ./nym-install.sh -p"
exit 1
fi
## Check if the node is running successfully
if
systemctl status nym-mixnode | grep -e "active (running)" > /dev/null 2>&1
then
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Your node ${YELLOW} ${service_id} ${WHITE} is ${LGREEN} up ${WHITE} and ${LGREEN} running!!!!${NOCOLOR}"
else
printf "%b\n\n\n" "${WHITE} Node is ${RED} not running ${WHITE} for some reason ...check it ${LBLUE} ./nym-install.sh -s [--status]"
fi
}
## Print the status nym-mixnode.service
function nym_status() {
systemctl status nym-mixnode | more
if
systemctl status nym-mixnode | grep -e "active (running)" > /dev/null 2>&1
then
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Your ${YELLOW} node ${WHITE} is ${LGREEN} up ${WHITE} and ${LGREEN} running ${NOCOLOR}!"
printf "%b\n\n\n"
elif
systemctl status nym-mixnode | more | grep -i inactive > /dev/null 2>&1
then
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Your ${YELLOW} node ${RED}is not running ${WHITE}. Run the script with -r option${NOCOLOR}"
printf "%b\n\n\n"
fi
}
## Download the latest version of the binaries
function downloader () {
#set -x
if [ ! -d /home/nym/.nym/mixnodes ]
then
# todo: add option to set the user and PATH for the mixnode but eventually decided not to this at the moment...seems unneccessary
echo "Looking for nym config in /home/nym but could not find any! Enter the path of the nym-mixnode executable"
exit 1
else
cd /home/nym
fi
# set vars for version checking and url to download the latest release of nym-mixnode
current_version=$(./nym-mixnode --version | grep Nym | cut -c 13- )
VERSION=$(curl https://github.com/nymtech/nym/releases/latest --cacert /etc/ssl/certs/ca-certificates.crt 2>/dev/null | egrep -o "[0-9|\.]{6}(-\w+)?")
URL="https://github.com/nymtech/nym/releases/download/v$VERSION/nym-mixnode"
# Check if the version is up to date. If not, fetch the latest release.
if [ ! -f nym-mixnode] || [ "$(./nym-mixnode_linux | grep Nym | cut -c 13- )" != "$VERSION" ]
then
if systemctl list-units --state=running | grep nym-mixnode
then echo "stopping nym-mixnode.service to update the node ..." && systemctl kill --signal=SIGINT nym-mixnode
curl -L -s "$URL" -o "nym-mixnode" --cacert /etc/ssl/certs/ca-certificates.crt && echo "Fetching the latest version" && pwd
else echo " nym-mixnode.service is inactive or not existing. Downloading new binaries ..." && pwd
curl -L -s "$URL" -o "nym-mixnode" --cacert /etc/ssl/certs/ca-certificates.crt && echo "Fetching the latest version" && pwd
# Make it executable
chmod +x ./nym-mixnode && chown nym:nym ./nym-mixnode
fi
else
echo "You have the latest version of Nym-mixnode $VERSION"
exit 1
fi
}
function upgrade_nym () {
#set -x
cd /home/nym
select d in /home/nym/.nym/mixnodes/* ; do test -n "$d" && break; printf "%b\n\n\n" "${WHITE} >>> Invalid Selection"; done
directory=$(echo "$d" | rev | cut -d/ -f1 | rev)
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} You selected ${YELLOW} $directory"
sleep 2
printf "%b\n\n\n" "${WHITE} Enter your Telegram handle beginning with @"
printf "%b\n\n\n"
read telegram
printf "%b\n\n\n" "${WHITE} Your Telegram handle for the faucet will be ${YELLOW} ${telegram} "
sudo -u nym -H ./nym-mixnode upgrade --id $directory
sleep 2
sudo -u nym -H ./nym-mixnode sign --id $directory --text ${telegram}
}
#set -x
function mixnode_update () {
downloader && echo "ok" && sleep 2 || exit 1
upgrade_nym && sleep 5 && systemctl start nym-mixnode.service && printf "%b\n\n\n" "${WHITE} Check if the update was successful - ./nym_install.sh -s ${NOCOLOR}"
}
## display usage if the script is not run as root user
if [[ $USER != "root" ]]
then
printf "%b\n\n\n" "${WHITE} This script must be run as ${YELLOW} root ${WHITE} or with ${YELLOW} sudo!${NOCOLOR}"
exit 1
fi
## Full install, config and launch of the nym-mixnode
if [ "$1" = "-i" ]; then
while [ ! -d /home/nym ] ; do nym_usercreation ; done
cd /home/nym/ || printf "%b\n\n\n" "${WHITE}failed sorry"
if [ ! -e /home/nym/nym-mixnode_linux_x86_64 ] ; then nym_download ; fi
nym_chmod
nym_chown
nym_init
nym_systemd_print
nym_ufw
nym_systemd_run
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n" "${WHITE} 1. Make sure to also check the official docs for the next steps ! "
printf "%b\n\n\n"
printf "%b\n" "${LGREEN} https://nymtech.net/docs/"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 2. go to telegram and claim your mixnode"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 3. Create a wallet https://web-wallet-finney.nymtech.net/"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 4. SAVE the mnemonics, copy your address and on telegram do: /faucet hal1xxxxx "
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 5. Go back to your wallet and bond your mixnode"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 6. Check if your node is all good https://testnet-explorer.nymtech.net/"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} to see how many packets"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} You have ${YELLOW} mixed ${WHITE} so far ! "
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
fi
## Configure the node
if [[ ("$1" = "--init") || "$1" = "-c" ]]
then
cd /home/nym/ > /dev/null 2>&1 && nym_init || printf "%b\n" "\n\n\n${YELLOW} /home/nym/ ${RED} does not exist. ${WHITE} Create it with the ${YELLOW} -i ${WHITE} or ${YELLOW} --install ${WHITE} flag first.\n\n\n"
fi
## Create the systemd.service file
if [[ ("$1" = "--print") || "$1" = "-p" ]]
then
cd /home/nym/ > /dev/null 2>&1 && nym_systemd_print || printf "%b\n" "\n\n\n${YELLOW} /home/nym/ ${RED} does not exist. ${WHITE} Create it with the ${YELLOW} -i ${WHITE} or ${YELLOW} --install ${WHITE} flag first.\n\n\n"
fi
## Create the systemd.service file locally
if [[ ("$1" = "--print-local") || "$1" = "-l" ]]
then
cd /home/nym/ > /dev/null 2>&1 && nym_systemd_print_local || printf "%b\n" "\n\n\n${YELLOW} /home/nym/ ${RED} does not exist. ${WHITE} Create it with the ${YELLOW} -i ${WHITE} or ${YELLOW} --install ${WHITE} flag first.\n\n\n"
nym_systemd_print_local
fi
## Run the node
if [[ ("$1" = "--run") || "$1" = "-r" ]]
then
cd /home/nym/.nym/mixnodes/ > /dev/null 2>&1 && nym_systemd_run || printf "%b\n" "\n\n\n${RED}no${YELLOW} config ${RED} found ${WHITE} Create it with the ${YELLOW} -c ${WHITE} or ${YELLOW} --init ${WHITE} flag first.\n\n\n"
fi
## Get status from the systemdaemon file
if [[ ("$1" = "--status") || "$1" = "-s" ]]
then
nym_status
fi
## Sign with user input
if [[ ("$1" = "--sign") || "$1" = "-g" ]]
then
printf "%b\n\n\n" "${WHITE} Please select a ${YELLOW} mixnode"
printf "%b\n\n\n"
select d in /home/nym/.nym/mixnodes/* ; do test -n "$d" && break; printf "%b\n\n\n" "${WHITE} >>> Invalid Selection"; done
directory=$(printf "%b\n\n\n" "${WHITE}$d" | rev | cut -d/ -f1 | rev)
cd /home/nym || exit 2
printf "\e[1;82mYou selected\e[0m\e[3;11m ${WHITE} $directory\e[0m\n"
printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} Enter your Telegram handle beginning with @"
printf "%b\n\n\n"
read telegram
printf "%b\n\n\n" "${WHITE} Your Telegram handle for the faucet will be ${YELLOW} ${telegram} "
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
# borrows a shell for nym user to initialize the node config.
#set -x
sudo -u nym -H /home/nym/nym-mixnode_linux_x86_64 sign --id $directory --text ${telegram} 2>&1 | tee -a ${directory}_claim.txt && chown nym:nym ${directory}_claim.txt
printf "%b\n\n\n"
fi
## Setup the firewall
if [[ ("$1" = "--firewall") || "$1" = "-f" ]]
then
nym_ufw
fi
## If no arguments supplied, display usage
if [ -z "$1" ]
then
display_usage
fi
## Check whether user had supplied -h or --help . If yes display usage
if [[ ("$1" = "--help") || "$1" = "-h" ]]
then
display_usage
exit 0
fi
## Prints the version of Nym used
if [[ ("$1" = "--version") || "$1" = "-V" ]]
then
display_usage
exit 0
fi
## Update the node -
## 1. See if nym-mixnode.service is running - if yes stop it
## 2. fetch the latest binaries
## 3. ./nym-mixnode upgrade and let user choose id and incentives Address
## 4. run the nym-mixnode.service again
if [[ ("$1" = "--update") || "$1" = "-u" ]]
then
mixnode_update || printf "%b\n" "\n\n\n${WHITE} Something went ${RED} wrong. ${NOCOLOR}"
fi
if [[ ("$1" = "--testnet") || "$1" = "-t" ]]
then
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------"
printf "%b\n" "${WHITE} 1. ${YELLOW}Make sure to check the ${LGREEN} official docs${WHITE} for the next steps ${YELLOW}after installation ! "
printf "%b\n\n\n"
printf "%b\n" "${LGREEN} https://nymtech.net/docs/"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 2. go to ${LBLUE}Telegram help chat ${WHITE} and ${YELLOW}claim your mixnode"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 3.${YELLOW} Create a wallet ${LGREEN}https://web-wallet-finney.nymtech.net/${WHITE}"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 4. ${YELLOW}SAVE the mnemonics, copy your address ${WHITE}and on ${LBLUE}Telegram${WHITE} do: /faucet hal1xxxxx "
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 5. Go back to your ${YELLOW}wallet${WHITE} and ${YELLOW}bond your mixnode"
printf "%b\n\n\n"
printf "%b\n" "${WHITE} 6. Check if your node is all good ${LGREEN}https://testnet-finney-explorer.nymtech.net/${WHITE}"
printf "%b\n\n\n"
#printf "%b\n" "${WHITE} to see how many packets"
#printf "%b\n\n\n"
#printf "%b\n" "${WHITE} You have ${YELLOW} mixed ${WHITE} so far ! "
#printf "%b\n\n\n"
printf "%b\n\n\n" "${WHITE} --------------------------------------------------------------------------------${NOCOLOR}"
exit 0
fi
if [[ ("$1" = "--claim") || "$1" = "-m" ]]
then
printf "%b\n\n\n" "${WHITE} Please select a ${YELLOW} mixnode"
printf "%b\n\n\n"
select d in /home/nym/.nym/mixnodes/* ; do test -n "$d" && break; printf "%b\n\n\n" "${WHITE} >>> Invalid Selection"; done
directory=$(printf "%b\n\n\n" "${WHITE}$d" | rev | cut -d/ -f1 | rev)
cd /home/nym || exit 2
printf "\e[1;82mYou selected\e[0m\e[3;11m ${WHITE} $directory\e[0m\n"
cat /home/nym/${directory}_claim.txt || echo "claim file not found. Are you sure you ran init?"
fi
#nym_usercreation
#nym_download
#nym_chmod
#nym_chown
#nym_init
#nym_run