This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
forked from nuriel77/goshimmer-playbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goshimmer_install.sh
831 lines (690 loc) · 24.9 KB
/
goshimmer_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
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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
#!/usr/bin/env bash
# This script will auto-detect the OS and Version
# It will update system packages and install Ansible and git
# Then it will clone the goshimmer-playbook and run it.
# Goshimmer playbook: https://github.com/nuriel77/goshimmer-playbook
# By Nuriel Shem-Tov (https://github.com/nuriel77), December 2019
# Copyright (c) 2020 Nuriel Shem-Tov
# Some options can be passed via environment variables:
# SET_DEFAULTS="true" ..... set default option selections
# SKIP_PASSWORD="true" ..... skip user and password selection (sets defaults)
# SKIP_REBOOT="true" ..... skip require reboot (except on selinux/centos)
# SKIP_CONFIRM="true" ..... skip installer confirmation
# INSTALL_OPTIONS ..... additional command line arguments to pass to ansible-playbook
set -o pipefail
set -e
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as user root"
echo "Please change to root using: 'sudo su -' and re-run the script"
exit 1
fi
# Default value for goshimmer-playbook repository URL
: "${GIT_REPO_URL:=https://github.com/nuriel77/goshimmer-playbook.git}"
export NEWT_COLORS='
window=,
'
declare -g GOSHIMMER_PLAYBOOK_DIR="/opt/goshimmer-playbook"
declare -g INSTALLER_OVERRIDE_FILE="${GOSHIMMER_PLAYBOOK_DIR}/group_vars/all/z-installer-override.yml"
declare -g PLAYBOOK_LIGHT="false"
# Configurable install options passed to ansible-playbook command
: "${INSTALL_OPTIONS:=}"
# Set minimum ram, used to set profile.
: "${MIN_RAM_KB:=1572864}"
if test -e /etc/motd && grep -q 'GoShimmer PLAYBOOK' /etc/motd; then
:>/etc/motd
else
if [ -f "$INSTALLER_OVERRIDE_FILE" ] && [[ "$1" != "rerun" ]] && [[ "$SKIP_CONFIRM" != true ]]
then
if ! (whiptail --title "Confirmation" \
--yesno "
It looks like a previous installation already exists.
Running the installer on an already working node is not recommended.
If you want to re-run only the playbook check the documentation or ask for assistance on Discord #fullnodes channel.
Please confirm you want to proceed with the installation?" \
--defaultno \
16 78); then
exit 1
fi
SKIP_CONFIRM="true"
fi
fi
clear
cat <<'EOF'
██████╗ ██████╗ ███████╗██╗ ██╗██╗███╗ ███╗███╗ ███╗███████╗██████╗
██╔════╝ ██╔═══██╗██╔════╝██║ ██║██║████╗ ████║████╗ ████║██╔════╝██╔══██╗
██║ ███╗██║ ██║███████╗███████║██║██╔████╔██║██╔████╔██║█████╗ ██████╔╝
██║ ██║██║ ██║╚════██║██╔══██║██║██║╚██╔╝██║██║╚██╔╝██║██╔══╝ ██╔══██╗
╚██████╔╝╚██████╔╝███████║██║ ██║██║██║ ╚═╝ ██║██║ ╚═╝ ██║███████╗██║ ██║
╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
_| _| _|
_|_|_| _| _|_|_| _| _| _|_|_| _|_| _|_| _| _|
_| _| _| _| _| _| _| _| _| _| _| _| _| _|_|
_| _| _| _| _| _| _| _| _| _| _| _| _| _| _|
_|_|_| _| _|_|_| _|_|_| _|_|_| _|_| _|_| _| _|
_| _|
_| _|_|
EOF
cat <<EOF
Welcome to IOTA's GoShimmer (unofficial) installer!
1. By pressing 'y' you agree to install GoShimmer node on your system.
2. By pressing 'y' you aknowledge that this installer requires a CLEAN operating system
and may otherwise !!!BREAK!!! existing software on your server.
3. If you already have a configured server, re-running this script might overwrite previous configuration.
EOF
if [[ "$SKIP_CONFIRM" != true ]]
then
read -p "Do you wish to proceed? [y/N] " yn
if echo "$yn" | grep -v -iq "^y"; then
echo Canceled
exit
fi
fi
#################
### Functions ###
#################
function set_dist() {
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
# Older SuSE/etc.
echo "Unsupported OS."
exit 1
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
echo "Old OS version. Minimum required is 7."
exit 1
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
}
function wait_apt(){
local i=0
tput sc
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
case $(($i % 4)) in
0 ) j="-" ;;
1 ) j="\\" ;;
2 ) j="|" ;;
3 ) j="/" ;;
esac
tput rc
echo -en "\r[$j] Waiting for other software managers to finish..."
sleep 0.5
((i=i+1))
done
echo
}
function init_centos_7(){
echo "Updating system packages..."
yum update -y
echo "Install epel-release..."
yum install epel-release -y
echo "Update epel packages..."
yum update -y
echo "Install yum utils..."
yum install -y yum-utils
set +e
set +o pipefail
if $(needs-restarting -r 2>&1 | grep -q "Reboot is required"); then
[[ "$SKIP_REBOOT" != true ]] && { inform_reboot; exit 0; }
fi
set -o pipefail
set -e
echo "Installing Ansible and git..."
yum install -y\
ansible\
redhat-lsb-core\
git\
expect-devel\
cracklib\
newt\
python3\
python-pip\
python-pip3
if [ -e /usr/bin/pip ]; then
/usr/bin/pip install jmespath
fi
if [ -e /usr/bin/pip3 ]; then
/usr/bin/pip3 install jmespath
fi
}
function init_centos_8(){
echo "Updating system packages..."
dnf update -y --nobest
echo "Install epel-release..."
dnf install epel-release -y
echo "Update epel packages..."
dnf update -y --nobest
echo "Install yum utils..."
dnf install -y yum-utils
local OUTPUT=$(needs-restarting)
if [[ "$OUTPUT" != "" ]]; then
[[ "$SKIP_REBOOT" != true ]] && { inform_reboot; exit 0; }
fi
echo "Installing Ansible, git and other requirements..."
dnf install -y\
git\
expect\
newt\
python3-pip\
cracklib\
redhat-lsb-core
pip3 --disable-pip-version-check install ansible jmespath
echo "$PATH" | grep -q '/usr/local/bin' || export PATH=$PATH:/usr/local/bin
grep PATH /root/.bashrc | grep -q '/usr/local/bin' || echo 'export PATH=$PATH:/usr/local/bin' >> /root/.bashrc
}
function init_ubuntu(){
wait_apt && echo "Ensure no package managers ..." && sleep 5 && wait_apt
echo "Updating system packages..."
apt update -qqy --fix-missing
apt-get upgrade -y
apt-get clean
apt-get autoremove -y --purge
echo "Check reboot required..."
if [ -f /var/run/reboot-required ]; then
[[ "$SKIP_REBOOT" != true ]] && { inform_reboot; exit 0; }
fi
echo "Installing Ansible and git..."
apt-get install software-properties-common -y
# PPA not ready for ubuntu focal yet (20.04)
[[ ! "$VER" =~ ^20 ]] && apt-add-repository ppa:ansible/ansible -y
add-apt-repository universe -y
apt-get update -y
apt-get install ansible\
git\
expect-dev\
tcl\
libcrack2\
cracklib-runtime\
whiptail\
python3-pip -y
[[ ! "$VER" =~ ^20 ]] && apt-get install python-pip -y
if [ -e /usr/bin/pip ]; then
/usr/bin/pip install jmespath
fi
if [ -e /usr/bin/pip3 ]; then
/usr/bin/pip3 install jmespath
fi
}
function init_debian(){
wait_apt && echo "Ensure no package managers ..." && sleep 5 && wait_apt
echo "Updating system packages..."
apt update -qqy --fix-missing
apt-get upgrade -y
apt-get clean
apt-get autoremove -y --purge
echo "Check reboot required..."
if [ -f /var/run/reboot-required ]; then
[[ "$SKIP_REBOOT" != true ]] && { inform_reboot; exit 0; }
fi
echo "Installing Ansible and git..."
local ANSIBLE_SOURCE="deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main"
grep -q "$ANSIBLE_SOURCE" /etc/apt/sources.list || echo "$ANSIBLE_SOURCE" >> /etc/apt/sources.list
apt-get install dirmngr --install-recommends -y
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
apt-get update -y
apt-get install ansible\
git\
less\
expect-dev\
tcl\
libcrack2\
cracklib-runtime\
whiptail\
lsb-release\
python3-pip\
python-pip \
python-backports.functools-lru-cache -y
if [ -e /usr/bin/pip ]; then
/usr/bin/pip install jmespath
fi
if [ -e /usr/bin/pip3 ]; then
/usr/bin/pip3 install jmespath
fi
}
function inform_reboot() {
cat <<EOF >/etc/motd
======================== GoShimmer PLAYBOOK ========================
To proceed with the installation, please re-run:
bash <(curl -s https://raw.githubusercontent.com/nuriel77/goshimmer-playbook/main/goshimmer_install.sh)
(make sure to run it as user root)
EOF
cat <<EOF
======================== PLEASE REBOOT AND RE-RUN THIS SCRIPT =========================
Some system packages have been updated which require a reboot
and allow the node installer to proceed with the installation.
*** Please reboot this machine and re-run this script ***
>>> To reboot run: 'reboot', and when back online:
bash <(curl -s https://raw.githubusercontent.com/nuriel77/goshimmer-playbook/main/goshimmer_install.sh)
!! Remember to re-run this script as root !!
EOF
}
function set_admin_password_a() {
whiptail --title "Admin Password" \
--passwordbox "
Please enter the password with which you will connect to services (IOTA Peer manager, Grafana, etc).
Use a stong password!!! Not 'hello123' or 'iota8181', you get the point ;).
Only valid ASCII characters are allowed." \
10 78 3>&1 1>&2 2>&3
if [[ $? -ne 0 ]]; then
echo "Installation cancelled"
fi
}
function set_admin_password_b() {
whiptail --passwordbox "please repeat" 8 78 --title "Admin Password" 3>&1 1>&2 2>&3
if [[ $? -ne 0 ]]; then
echo "Installation cancelled"
fi
}
function get_admin_password() {
# Get first password and validate ascii characters only
local PASSWORD_A=$(set_admin_password_a)
if [[ "$PASSWORD_A" == "Installation cancelled" ]]; then
echo "$PASSWORD_A"
exit 1
fi
local LC_CTYPE=C
case "${PASSWORD_A}" in
*[![:cntrl:][:print:]]*)
whiptail --title "Invalid characters!!" \
--msgbox "
Only ASCII characters are allowed:
!\"#\$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~" \
12 78
get_admin_password
return
;;
esac
# Get password again and check passwords match
local PASSWORD_B=$(set_admin_password_b)
if [[ "$PASSWORD_B" == "Installation cancelled" ]]; then
echo "$PASSWORD_B"
exit 1
fi
if [ "$PASSWORD_A" != "$PASSWORD_B" ]; then
whiptail --title "Passwords Mismatch!" \
--msgbox "Passwords do not match, please try again." \
8 78
get_admin_password
return
fi
PASSWD_CHECK=$(echo -n "$PASSWORD_A" | cracklib-check)
if [[ $(echo "$PASSWD_CHECK" | awk {'print $2'}) != "OK" ]]; then
whiptail --title "Weak Password!" \
--msgbox "Please choose a better password:$(echo ${PASSWD_CHECK}|cut -d: -f2-)" \
8 78
get_admin_password
return
fi
# Ensure we escape single quotes (using single quotes) because we need to
# encapsulate the password with single quotes for the Ansible variable file
PASSWORD_A=$(echo "${PASSWORD_A}" | sed "s/'/''/g")
echo "fullnode_user_password: '${PASSWORD_A}'" >> "$INSTALLER_OVERRIDE_FILE"
chmod 600 "$INSTALLER_OVERRIDE_FILE"
}
function set_admin_username() {
ADMIN_USER=$(whiptail --inputbox "
Choose an administrator's username.
Only valid ASCII characters are allowed:" \
10 $WIDTH "$ADMIN_USER" \
--title "Choose Admin Username" 3>&1 1>&2 2>&3)
if [[ $? -ne 0 ]]; then
echo "Installation cancelled"
fi
local LC_CTYPE=C
case "${ADMIN_USER}" in
*[![:cntrl:][:print:]]*)
whiptail --title "Invalid characters!!" \
--msgbox "
Only ASCII characters are allowed:
!\"#\$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~" \
12 78
set_admin_username
return
;;
esac
echo "fullnode_user: '${ADMIN_USER}'" >> "$INSTALLER_OVERRIDE_FILE"
if [[ "$PLAYBOOK_LIGHT" = true ]] || [[ "$OS" =~ ^Raspbian ]]
then
echo "disable_monitoring: true" >>"$INSTALLER_OVERRIDE_FILE"
fi
}
# Installation selection menu
function set_selections() {
local RC RESULTS RESULTS_ARRAY CHOICE SKIP_TAGS
SKIP_TAGS="--skip-tags=_"
DISABLE_MONITORING_DEFAULT="ON"
DISABLE_MONITORING_MSG=" (recommended)"
if [[ "$PLAYBOOK_LIGHT" = true ]]
then
echo "goshimmer_profile: light" >>"$INSTALLER_OVERRIDE_FILE"
elif [[ ! "$OS" =~ ^Raspbian ]]
then
DISABLE_MONITORING_DEFAULT="OFF"
DISABLE_MONITORING_MSG=""
fi
RESULTS=$(whiptail --title "Installation Options" --checklist \
--cancel-button "Exit" \
"
Please choose additional installation options.
Note that defaults have been set according to your system's configuration.
Select/unselect options using space and click Enter to proceed.
" 24 78 3 \
"INSTALL_NGINX" "Install nginx webserver (recommended)" ON \
"DISABLE_MONITORING" "Disable node monitoring${DISABLE_MONITORING_MSG}" "$DISABLE_MONITORING_DEFAULT" \
"SKIP_FIREWALL_CONFIG" "Skip configuring firewall" OFF \
3>&1 1>&2 2>&3)
# use the following block as soon as all options have been upgraded from the HORNET repository
#Select/unselect options using space and click Enter to proceed.
# " 24 78 5 \
# "INSTALL_DOCKER" "Install Docker runtime (recommended)" ON \
# "INSTALL_NGINX" "Install nginx webserver (recommended)" ON \
# "SKIP_FIREWALL_CONFIG" "Skip configuring firewall" OFF \
# "ENABLE_HAPROXY" "Enable HAProxy (recommended)" ON \
# 3>&1 1>&2 2>&3)
RC=$?
if [[ $RC -ne 0 ]]; then
echo "Installation cancelled"
exit 1
fi
read -a RESULTS_ARRAY <<< "$RESULTS"
for CHOICE in "${RESULTS_ARRAY[@]}"
do
case $CHOICE in
# '"INSTALL_DOCKER"')
# echo "install_docker: true" >>"$INSTALLER_OVERRIDE_FILE"
# ;;
'"INSTALL_NGINX"')
echo "install_nginx: true" >>"$INSTALLER_OVERRIDE_FILE"
;;
'"SKIP_FIREWALL_CONFIG"')
echo "configure_firewall: false" >>"$INSTALLER_OVERRIDE_FILE"
;;
'"DISABLE_MONITORING"')
SKIP_TAGS+=",monitoring_role"
echo "disable_monitoring: true" >>"$INSTALLER_OVERRIDE_FILE"
;;
# '"ENABLE_HAPROXY"')
# echo "lb_bind_addresses: ['0.0.0.0']" >>"$INSTALLER_OVERRIDE_FILE"
# ;;
*)
;;
esac
done
if [[ -n "$RESULTS" ]]; then
RESULTS_MSG=$(echo "$RESULTS"|sed 's/ /\n/g')
if ! (whiptail --title "Confirmation" \
--yesno "
You chose:
$RESULTS_MSG
Please confirm you want to proceed with the installation?" \
--defaultno \
16 78); then
exit 1
fi
fi
INSTALL_OPTIONS+=" $SKIP_TAGS"
}
function set_defaults() {
cat <<EOF >>"$INSTALLER_OVERRIDE_FILE"
install_docker: true
install_nginx: true
configure_firewall: false
lb_bind_addresses: ['0.0.0.0']
EOF
if [[ "$PLAYBOOK_LIGHT" = true ]] || [[ "$OS" =~ ^Raspbian ]]
then
echo "disable_monitoring: true" >>"$INSTALLER_OVERRIDE_FILE"
fi
}
# Get primary IP from ICanHazIP, if it does not validate, fallback to local hostname
function set_primary_ip()
{
echo "Getting external IP address..."
local ip=$(curl -s -f --max-time 10 --retry 2 -4 'https://icanhazip.com')
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "Got IP $ip"
PRIMARY_IP=$ip
else
PRIMARY_IP=$(hostname -I|tr ' ' '\n'|head -1)
echo "Failed to get external IP... using local IP $PRIMARY_IP instead"
fi
}
function display_requirements_url() {
echo "Only Debian, Ubuntu 20, 19 and 18 (LTS), Raspbian, CentOS 7 and 8 are supported (and only 64bit)."
}
function check_arch() {
# Check architecture
ARCH=$(uname -m)
local REGEXP="x86_64|armv8l|aarch64"
if [[ ! "$ARCH" =~ $REGEXP ]]; then
echo "ERROR: $ARCH architecture not supported"
display_requirements_url
exit 1
fi
}
function check_total_ram_min_kb() {
MIN_RAM=$1
MEM_TOTAL=$(grep ^MemTotal /proc/meminfo | awk {'print $2'})
if [[ "$MEM_TOTAL" -gt "$MIN_RAM" ]]
then
return 1
fi
}
function set_playbook_light() {
PLAYBOOK_LIGHT="true"
}
function set_ssh_port() {
SSH_PORT=$(whiptail --inputbox "
Please verify this is your active SSH port:" \
8 78 \
"$SSH_PORT" \
--title "Verify SSH Port" 3>&1 1>&2 2>&3)
if [[ $? -ne 0 ]] || [[ "$SSH_PORT" == "" ]]; then
set_ssh_port
elif [[ "$SSH_PORT" =~ [^0-9] ]] || [[ $SSH_PORT -gt 65535 ]] || [[ $SSH_PORT -lt 1 ]]; then
whiptail --title "Invalid Input" \
--msgbox "Invalid input provided. Only numbers are allowed (1-65535)." \
8 78
set_ssh_port
fi
}
function skip_all_updates() {
readarray -t TO_RUN_UPDATES < <(find "${GOSHIMMER_PLAYBOOK_DIR}/custom_updates/" -maxdepth 1 -type f -name '*_updates.sh')
# Return if nothing to update
((${#TO_RUN_UPDATES[@]} == 0)) && { clear; return; }
for FILE in "${TO_RUN_UPDATES[@]}"
do
touch "${FILE}.completed"
done
}
function run_playbook(){
# Get default SSH port
set +o pipefail
SSH_PORT=$(grep ^Port /etc/ssh/sshd_config | awk {'print $2'})
set -o pipefail
if [[ "$SSH_PORT" != "" ]] && [[ "$SSH_PORT" != "22" ]]; then
set_ssh_port
else
SSH_PORT=22
fi
echo "SSH port to use: $SSH_PORT"
# Ansible output log file
LOGFILE=/var/log/goshimmer-playbook-$(date +%Y%m%d%H%M).log
# Override ssh_port
[[ $SSH_PORT -ne 22 ]] && echo "ssh_port: \"${SSH_PORT}\"" > "${GOSHIMMER_PLAYBOOK_DIR}/group_vars/all/z-ssh-port.yml"
# Run the playbook
echo "*** Running playbook command: ansible-playbook -i inventory -v site.yml $INSTALL_OPTIONS" | tee -a "$LOGFILE"
set +e
unbuffer ansible-playbook -i inventory -v site.yml $INSTALL_OPTIONS | tee -a "$LOGFILE"
RC=$?
if [ $RC -ne 0 ]; then
echo "ERROR! The playbook exited with failure(s). A log has been save here '$LOGFILE'"
exit $RC
fi
set -e
# Check playbook needs reboot
if [ -f "/var/run/playbook_reboot" ]; then
cat <<EOF >/etc/motd
-------------------- GoShimmer PLAYBOOK --------------------
It seems you have rebooted the node. You can proceed with
the installation by running the command:
${GOSHIMMER_PLAYBOOK_DIR}/rerun.sh
(make sure you are user root!)
-------------------- GoShimmer PLAYBOOK --------------------
EOF
cat <<EOF
-------------------- NOTE --------------------
The installer detected that the server requires a reboot,
most probably to enable a functionality required by the playbook.
You can reboot the server using the command 'reboot'.
Once the server is back online you can use the following command
to proceed with the installation (become user root first):
${GOSHIMMER_PLAYBOOK_DIR}/rerun.sh
-------------------- NOTE --------------------
EOF
rm -f "/var/run/playbook_reboot"
exit
fi
# Calling set_primary_ip
set_primary_ip
# Get configured username if missing.
# This could happen on script re-run
# due to reboot, therefore the variable is empty
if [ -z "$ADMIN_USER" ]; then
ADMIN_USER=$(grep "^fullnode_user:" "$INSTALLER_OVERRIDE_FILE" | awk {'print $2'})
fi
if ! grep -q "^disable_monitoring: true" "$INSTALLER_OVERRIDE_FILE"; then
MONITORING_MSG=" and Grafana"
MONITORING_URL=" and https://${PRIMARY_IP}/grafana"
fi
OUTPUT=$(cat <<EOF
* A log of this installation has been saved to: $LOGFILE
* You should be able to connect to GoShimmer Dashboard${MONITORING_MSG}:
https://${PRIMARY_IP}${MONITORING_URL}
* Note that your IP might be different as this one has been auto-detected in best-effort.
* Log in with username ${ADMIN_USER} and the password you have entered during the installation.
Thank you for installing an IOTA node with the GoShimmer-playbook!
EOF
)
HEIGHT=$(expr $(echo "$OUTPUT"|wc -l) + 10)
whiptail --title "Installation Done" \
--msgbox "$OUTPUT" \
$HEIGHT 78
}
#####################
### End Functions ###
#####################
# Incase we call a re-run
if [[ -n "$1" ]] && [[ "$1" == "rerun" ]]; then
run_playbook
exit
fi
### Get OS and version
set_dist
# Check OS version compatibility
if [[ "$OS" =~ ^(CentOS|Red) ]]; then
if [[ ! "$VER" =~ ^(7|8) ]]; then
echo "ERROR: $OS version $VER not supported"
display_requirements_url
exit 1
fi
check_arch
init_centos_$VER
elif [[ "$OS" =~ ^Ubuntu ]]; then
if [[ ! "$VER" =~ ^(16|17|18|19|20) ]]; then
echo "ERROR: $OS version $VER not supported"
display_requirements_url
exit 1
fi
check_arch
init_ubuntu
elif [[ "$OS" =~ ^Debian ]]; then
if [[ ! "$VER" =~ ^(9|10) ]]; then
echo "ERROR: $OS version $VER not supported"
display_requirements_url
exit 1
fi
check_arch
init_debian
elif [[ "$OS" =~ ^Raspbian ]]; then
if [[ ! "$VER" =~ ^(9|10) ]]; then
echo "ERROR: $OS version $VER not supported"
display_requirements_url
exit 1
fi
check_arch
# Workaround to make sure we detect
# if reboot is needed
apt install unattended-upgrades -y
# Same setup for respbian as debian
init_debian
# remove workaround
apt remove unattended-upgrades -y
else
echo "$OS not supported"
exit 1
fi
echo "Verifying Ansible version..."
ANSIBLE_VERSION=$(ansible --version|head -1|awk {'print $2'}|cut -d. -f1-2)
if (( $(awk 'BEGIN {print ("'2.8'" > "'$ANSIBLE_VERSION'")}') )); then
cat <<EOF
Error: Ansible minimum version 2.8 required.
Please remove Ansible: (yum remove ansible -y for CentOS, or apt-get remove -y ansible for Ubuntu).
Then refer to the documentation on how to get latest Ansible installed.
http://docs.ansible.com/ansible/latest/intro_installation.html
Note that for CentOS you may need to install Ansible from Epel to get version 2.8 or higher.
EOF
exit 1
fi
echo "Git cloning goshimmer-playbook repository..."
cd /opt
# Backup any existing goshimmer-playbook directory
if [ -d "/opt/goshimmer-playbook" ]; then
echo "Backing up older goshimmer-playbook directory..."
rm -rf goshimmer-playbook.backup
mv -- goshimmer-playbook "goshimmer-playbook.backup.$(date +%s)"
fi
# Clone the repository (optional branch)
git clone $GIT_OPTIONS "$GIT_REPO_URL"
cd "$GOSHIMMER_PLAYBOOK_DIR"
# first installation? Skip all upgrades
skip_all_updates
if check_total_ram_min_kb "$MIN_RAM_KB"
then
set_playbook_light
fi
# Let user choose installation add-ons or set defaults
if [[ "$SET_DEFAULTS" = true ]]
then
set_defaults
else
set_selections
fi
if [[ "$SKIP_PASSWORD" != true ]]
then
# Get the administrators username
set_admin_username
# web access
get_admin_password
fi
echo -e "\nRunning playbook..."
run_playbook