-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstaller.sh
More file actions
executable file
·1393 lines (1235 loc) · 42.8 KB
/
Copy pathinstaller.sh
File metadata and controls
executable file
·1393 lines (1235 loc) · 42.8 KB
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
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# A tool to install XLX, your own D-Star Reflector.
# For more information, please visit https://xlxbbs.epf.lu/
# Created by Daniel K., PP5PK.
# Enable strict error handling
# -e : exit immediately on any command returning non-zero
# -o pipefail : pipeline exit code reflects the first failed command
set -euo pipefail
IFS=$'\n\t'
# INITIAL CHECKS
# 1. Check if running as root, with automatic relaunch
if [ "$(id -u)" -ne 0 ]; then
echo "This script is not being run as root."
read -r -p "Do you want to relaunch with sudo? (y/n) " answer
answer=${answer:-y}
case "$answer" in
y|Y|yes|YES)
echo "Relaunching with sudo..."
exec sudo bash "$0" "$@"
;;
*)
echo "Operation cancelled by user."
exit 1
;;
esac
fi
# 2. Redirect all output to the log and keep it in the terminal
if ! mkdir -p "$PWD/log"; then
echo "ERROR: Failed to create log directory at $PWD/log"
exit 1
fi
LOGFILE="$PWD/log/log_xlx_install_$(date +%F_%H-%M-%S).log"
exec > >(tee -a "$LOGFILE") 2>&1
# 3. Internet check (retry up to 3 times for reliability)
PING_SUCCESS=0
for i in {1..3}; do
if ping -c 1 -W 2 google.com &>/dev/null; then
PING_SUCCESS=1
break
fi
sleep 1
done
if [ "$PING_SUCCESS" -eq 0 ]; then
echo "Unable to proceed, no internet connection detected. Please check your network."
exit 1
fi
# 4. Bash version check
if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
echo "ERROR: Bash 4.0 or higher is required."
exit 1
fi
# 5. Distro check
if [ ! -e "/etc/debian_version" ]; then
echo "This script has only been tested on Debian-based distributions."
read -r -p "Do you want to continue anyway? (Y/N) " answer
[[ "$answer" =~ ^[yY](es)?$ ]] || { echo "Execution cancelled."; exit 1; }
fi
# 6. Set the fixed character limit
MAX_WIDTH=100
cols=$(tput cols 2>/dev/null || echo "$MAX_WIDTH")
width=$(( cols < MAX_WIDTH ? cols : MAX_WIDTH ))
# 7. Function to create different types of lines adjusted to length
line_type1() {
printf '%*s\n' "$width" '' | tr ' ' '_'
}
line_type2() {
printf '%*s\n' "$width" '' | tr ' ' '='
}
line_type3() {
printf '%*s\n' "$width" '' | tr ' ' ':'
}
# 8. Function to display text with adjusted line breaks
print_wrapped() {
echo "$1" | fold -s -w "$width"
}
SEPQUE="_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_"
# 9. Parameter definition
XLXINS=$(pwd)
USRSRC="/usr/src"
HOMEIP=$(hostname -I 2>/dev/null | awk '{print $1}')
# If the first address is the loopback, the real LAN/WAN address (if any)
# is usually the second one reported by hostname -I
if [ "$HOMEIP" == "127.0.0.1" ]; then
HOMEIP=$(hostname -I 2>/dev/null | awk '{print $2}')
fi
HOMEIP=${HOMEIP:-127.0.0.1}
PUBLIP=$(curl -m 5 -s -f https://v4.ident.me || curl -m 5 -s -f https://api4.ipify.org || true)
if [ -z "$PUBLIP" ]; then
echo "Warning: Could not determine public IP address"
PUBLIP="0.0.0.0"
fi
NETACT=$(ip -o addr show up | awk '{print $2}' | grep -v lo | head -n1 || true)
INFREF="https://xlxbbs.epf.lu/"
XLXREP="https://github.com/PP5PK/xlxd.git"
XLXECO="https://github.com/PP5PK/XLXEcho.git"
XLXDSH="https://github.com/PP5PK/XLX_Dark_Dashboard.git"
DMRURL="http://xlxapi.rlx.lu/api/exportdmr.php"
WEBDIR="/var/www/html/xlxd"
XLXDIR="/xlxd"
ACCEPT="| [ENTER] to accept..."
SSL_OK=0
DEPAPP=(
git
git-core
make
gcc
g++
pv
sqlite3
apache2
php
libapache2-mod-php
php-cli
php-xml
php-mbstring
php-curl
php-sqlite3
build-essential
vnstat
certbot
python3-certbot-apache
)
# 10. Color palette
NC='\033[0m'
BLUE='\033[38;5;39m'
BLUE_BRIGHT='\033[1;34m'
GREEN='\033[38;5;46m'
YELLOW='\033[38;5;226m'
ORANGE='\033[38;5;208m'
RED='\033[38;5;196m'
RED_DARK='\033[38;5;124m'
GRAY='\033[38;5;250m'
# 11. Unicode icons
ICON_OK="✔"
ICON_ERR="✖"
ICON_WARN="(⚠)"
ICON_INFO="(ℹ)"
ICON_FATAL="(‼)"
ICON_NOTE="🛈"
# 12. Functions to display text with adjusted line breaks and colors
print_blue() { echo -e "${BLUE}$(echo "$1" | fold -s -w "$width")${NC}"; }
print_blueb() { echo -e "${BLUE_BRIGHT}$(echo "$1" | fold -s -w "$width")${NC}"; }
print_green() { echo -e "${GREEN}$(echo "$1" | fold -s -w "$width")${NC}"; }
print_yellow() { echo -e "${YELLOW}$(echo "$1" | fold -s -w "$width")${NC}"; }
print_orange() { echo -e "${ORANGE}$(echo "$1" | fold -s -w "$width")${NC}"; }
print_red() { echo -e "${RED}$(echo "$1" | fold -s -w "$width")${NC}"; }
print_redd() { echo -e "${RED_DARK}$(echo "$1" | fold -s -w "$width")${NC}"; }
print_gray() { echo -e "${GRAY}$(echo "$1" | fold -s -w "$width")${NC}"; }
center_wrap_color() {
local color="$1"
local text="$2"
local wrapped_lines
IFS=$'\n' read -rd '' -a wrapped_lines <<<"$(echo "$text" | fold -s -w "$width")" || true
for line in "${wrapped_lines[@]}"; do
local line_length=${#line}
local padding=$(( (width - line_length) / 2 ))
printf "%b%*s%s%b\n" "$color" "$padding" "" "$line" "$NC"
done
}
# 13. Helper functions for error handling and sed escaping
# Information
msg_info() {
print_blue "$ICON_INFO $1"
}
# Success
msg_success() {
print_green "$ICON_OK $1"
}
# Warning
msg_warn() {
print_yellow "$ICON_WARN $1"
}
# Caution
msg_caution() {
print_orange "$ICON_INFO $1"
}
# Error
msg_error() {
print_red "$ICON_ERR $1"
}
# Technical note
msg_note() {
print_gray "$ICON_NOTE $1"
}
# Fatal message!!!
msg_fatal() {
print_redd "$ICON_FATAL $1"
}
error_exit() {
print_redd "$ICON_FATAL ERROR: $1"
exit 1
}
# 14. Escape special characters for use in sed replacement strings
escape_sed() {
printf '%s\n' "$1" | sed 's/[\/&|\\]/\\&/g'
}
# 15. Utility: validate module against MODQTD
is_module_valid() {
local module="$1"
[[ "$module" =~ ^[A-Z]$ ]] || return 1
local index=$(( $(printf "%d" "'$module") - 65 ))
(( index >= 0 && index < MODQTD ))
}
# 16. Check for existing installs
if [ -e "$XLXDIR/xlxd" ]; then
echo ""
line_type2
echo ""
center_wrap_color $RED "XLXD ALREADY INSTALLED!!! Run the 'uninstaller.sh'."
echo ""
line_type2
echo ""
exit 1
fi
# 17. Resolve timezone from user input, checking only real system timezones
resolve_timezone() {
local input="$1"
local input_upper input_lower match
input_upper=$(echo "$input" | tr '[:lower:]' '[:upper:]')
input_lower=$(echo "$input" | tr '[:upper:]' '[:lower:]')
# 1) Case-insensitive match against the official system list
match=$(timedatectl list-timezones | grep -iFx "$input" 2>/dev/null || true)
[[ -n "$match" ]] && { echo "$match"; return 0; }
match=$(timedatectl list-timezones | grep -iFx "$input_upper" 2>/dev/null || true)
[[ -n "$match" ]] && { echo "$match"; return 0; }
match=$(timedatectl list-timezones | grep -iFx "$input_lower" 2>/dev/null || true)
[[ -n "$match" ]] && { echo "$match"; return 0; }
# 2) GMT±X – validate only if it exists in tzdata
if [[ "$input_upper" =~ ^GMT([+-]?)([0-9]{1,2})$ ]]; then
local sign="${BASH_REMATCH[1]}"
local num="${BASH_REMATCH[2]}"
local candidate
# POSIX inverted GMT logic — do NOT modify
if [[ "$sign" == "-" ]]; then
candidate="Etc/GMT+${num}"
elif [[ "$sign" == "+" ]]; then
candidate="Etc/GMT-${num}"
else
candidate="Etc/GMT"
fi
if [[ -f "/usr/share/zoneinfo/$candidate" ]]; then
echo "$candidate"
return 0
fi
fi
echo ""
return 1
}
# 18. Start of data collection
clear
line_type3
echo ""
center_wrap_color $GREEN "XLX MULTIPROTOCOL AMATEUR RADIO REFLECTOR INSTALLER PROGRAM"
echo ""
center_wrap_color $GREEN "Next, you will be asked some questions. Answer with the requested information or, if applicable, to accept the suggested value, press [ENTER]"
echo ""
line_type3
echo ""
center_wrap_color $BLUE_BRIGHT "$ICON_INFO REFLECTOR DATA INPUT"
center_wrap_color $BLUE "========================"
echo ""
echo ""
# 19. Questions begin...
question_01() {
print_red "$ICON_WARN Mandatory"
print_wrapped "01. XLX Reflector ID, 3 alphanumeric characters. (e.g., 300, US1, BRA)"
while true; do
printf "> "
read -r XRFDIGIT
XRFDIGIT=$(echo "$XRFDIGIT" | tr '[:lower:]' '[:upper:]')
if [[ "$XRFDIGIT" =~ ^[A-Z0-9]{3}$ ]]; then
break
fi
msg_caution "Invalid ID. Must be exactly 3 characters (A-Z and/or 0-9). Try again!"
done
XRFNUM="XLX$XRFDIGIT"
print_yellow "Using: $XRFNUM"
}
question_02() {
echo ""
echo "$SEPQUE"
echo ""
print_red "$ICON_WARN Mandatory"
print_wrapped "02. Dashboard FQDN (fully qualified domain name). (e.g., xlxbra.net)"
while true; do
printf "> "
read -r XLXDOMAIN
XLXDOMAIN=$(echo "$XLXDOMAIN" | tr '[:upper:]' '[:lower:]')
if [[ "$XLXDOMAIN" =~ ^([a-z0-9-]+\.)+[a-z]{2,}$ ]]; then
break
fi
msg_caution "Invalid domain. Must be a valid FQDN (e.g., xlx.example.com)."
done
print_yellow "Using: $XLXDOMAIN"
}
question_03() {
echo ""
echo "$SEPQUE"
echo ""
print_red "$ICON_WARN Mandatory"
print_wrapped "03. Sysop e-mail address"
while true; do
printf "> "
read -r EMAIL
EMAIL=$(echo "$EMAIL" | tr '[:upper:]' '[:lower:]')
if [[ "$EMAIL" =~ ^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$ ]]; then
break
fi
msg_caution "Invalid email format. (e.g., user@domain.com)."
done
print_yellow "Using: $EMAIL"
}
question_04() {
echo ""
echo "$SEPQUE"
echo ""
print_red "$ICON_WARN Mandatory"
print_wrapped "04. Sysop callsign. Only letters and numbers allowed, max 6 characters."
while true; do
printf "> "
read -r CALLSIGN
CALLSIGN=$(echo "$CALLSIGN" | tr '[:lower:]' '[:upper:]')
if [[ "$CALLSIGN" =~ ^[A-Z0-9]{3,6}$ ]]; then
break
fi
msg_caution "Invalid callsign. Use only letters and numbers, 3 - 6 characters."
done
print_yellow "Using: $CALLSIGN"
}
question_05() {
echo ""
echo "$SEPQUE"
echo ""
print_red "$ICON_WARN Mandatory"
print_wrapped "05. Reflector country name."
while true; do
printf "> "
read -r COUNTRY
if [ -z "$COUNTRY" ]; then
msg_caution "This field is mandatory and cannot be empty. Try again!"
else
break
fi
done
print_yellow "Using: $COUNTRY"
}
question_06() {
echo ""
echo "$SEPQUE"
# Detect current server timezone
AUTO_TZ=$(timedatectl show --property=Timezone --value 2>/dev/null || true)
OFFSET=$(date +%z)
SIGN=${OFFSET:0:1}
HH=${OFFSET:1:2}
MM=${OFFSET:3:2}
FRIENDLY_OFFSET="UTC${SIGN}${HH}:${MM}"
echo ""
print_red "$ICON_WARN Mandatory"
if [[ -n "$AUTO_TZ" ]]; then
print_wrapped "06. Local timezone. Detected: $AUTO_TZ ($FRIENDLY_OFFSET)"
print_gray "Press ENTER to keep it or type another timezone."
else
print_wrapped "06. What is the local timezone? (e.g., America/Sao_Paulo, UTC, GMT-3)"
fi
# Interactive timezone selection
while true; do
printf "> "
read -r USER_TZ
# CASE 1 — USER PRESSED ENTER (KEEP DETECTED TIMEZONE)
if [[ -z "$USER_TZ" && -n "$AUTO_TZ" ]]; then
TIMEZONE="$AUTO_TZ"
TIMEZONE_USE_SYSTEM=1
# Resolve tzdata link
ZONEFILE=$(readlink -f "/usr/share/zoneinfo/$TIMEZONE" || true)
REAL_OFFSET=$(TZ="$ZONEFILE" date +%z)
# Prepare display offset
SIGN=${REAL_OFFSET:0:1}
HH=${REAL_OFFSET:1:2}
MM=${REAL_OFFSET:3:2}
# If UTC+00:00 → hide offset
if [[ "$REAL_OFFSET" == "+0000" ]]; then
FINAL_DISPLAY="$TIMEZONE"
else
FINAL_DISPLAY="$TIMEZONE (UTC${SIGN}${HH}:${MM})"
fi
# No confirmation needed
break
fi
# CASE 2 — USER ENTERED A CUSTOM TIMEZONE
TZ_RESOLVED=$(resolve_timezone "$USER_TZ" || true)
if [[ -z "$TZ_RESOLVED" ]]; then
msg_caution "Invalid timezone. Please try again."
continue
fi
TIMEZONE="$TZ_RESOLVED"
TIMEZONE_USE_SYSTEM=0
# Resolve tzdata link
ZONEFILE=$(readlink -f "/usr/share/zoneinfo/$TIMEZONE" 2>/dev/null || true)
if [ -z "$ZONEFILE" ] || [ ! -f "$ZONEFILE" ]; then
msg_warn "Warning: Timezone file not found. Using system default."
TIMEZONE="$AUTO_TZ"
ZONEFILE=$(readlink -f "/usr/share/zoneinfo/$TIMEZONE" || true)
fi
REAL_OFFSET=$(TZ="$ZONEFILE" date +%z)
# Prepare offset
SIGN=${REAL_OFFSET:0:1}
HH=${REAL_OFFSET:1:2}
MM=${REAL_OFFSET:3:2}
DISPLAY_OFFSET="UTC${SIGN}${HH}:${MM}"
# If UTC+00:00 → hide offset
if [[ "$REAL_OFFSET" == "+0000" ]]; then
FINAL_DISPLAY="$TIMEZONE"
else
FINAL_DISPLAY="$TIMEZONE ($DISPLAY_OFFSET)"
fi
# Confirmation prompt (ONLY for custom TZ)
print_yellow "Selected timezone: $FINAL_DISPLAY"
# Inverted GMT warning
if [[ "$TIMEZONE" =~ ^Etc/GMT ]]; then
print_orange "$ICON_NOTE IMPORTANT: Linux POSIX GMT zones use inverted sign notation."
print_orange "In your case, $TIMEZONE (inverted) corresponds to $DISPLAY_OFFSET (real)."
fi
print_yellow "Confirm this timezone? (Y/N, ENTER = Y)"
printf "> "
read -r CONFIRM_TZ
CONFIRM_TZ=$(echo "$CONFIRM_TZ" | tr '[:lower:]' '[:upper:]')
# Default = Y
if [[ -z "$CONFIRM_TZ" || "$CONFIRM_TZ" == "Y" ]]; then
break
fi
print_yellow "Please inform your timezone or press ENTER to accept detected."
done
# Final output
print_yellow "Using: $FINAL_DISPLAY"
}
question_07() {
echo ""
echo "$SEPQUE"
echo ""
COMMENT_DEFAULT="$XRFNUM Multiprotocol Reflector by $CALLSIGN, info: $EMAIL"
print_wrapped "07. Comment to XLX Reflectors list."
print_gray "Suggested: \"$COMMENT_DEFAULT\" $ACCEPT"
while true; do
printf "> "
read -r COMMENT
COMMENT=${COMMENT:-"$COMMENT_DEFAULT"}
if [ ${#COMMENT} -le 100 ]; then
break
else
msg_caution "Comment must be max 100 characters. Please try again!"
fi
done
print_yellow "Using: $COMMENT"
}
question_08() {
echo ""
echo "$SEPQUE"
echo ""
HEADER_DEFAULT="$XRFNUM by $CALLSIGN"
print_wrapped "08. Custom text for the dashboard tab. (max 25 characters)"
print_gray "Suggested: \"$HEADER_DEFAULT\" $ACCEPT"
while true; do
printf "> "
read -r HEADER
HEADER=${HEADER:-"$HEADER_DEFAULT"}
if [ ${#HEADER} -le 25 ]; then
break
else
msg_caution "Tab page text must be max 25 characters. Please try again!"
fi
done
print_yellow "Using: $HEADER"
}
question_09() {
echo ""
echo "$SEPQUE"
echo ""
FOOTER_DEFAULT="Provided by $CALLSIGN, info: $EMAIL"
print_wrapped "09. Custom text on footer of the dashboard webpage."
print_gray "Suggested: \"$FOOTER_DEFAULT\" $ACCEPT"
while true; do
printf "> "
read -r FOOTER
FOOTER=${FOOTER:-"$FOOTER_DEFAULT"}
if [ ${#FOOTER} -le 50 ]; then
break
else
msg_caution "Footer must be max 50 characters. Please try again!"
fi
done
print_yellow "Using: $FOOTER"
}
question_10() {
echo ""
echo "$SEPQUE"
echo ""
print_wrapped "10. Create an SSL certificate (https) for the dashboard webpage? (Y/N)"
print_gray "Suggested: Y $ACCEPT"
while true; do
printf "> "
read -r INSTALL_SSL
INSTALL_SSL=$(echo "${INSTALL_SSL:-Y}" | tr '[:lower:]' '[:upper:]')
if [[ "$INSTALL_SSL" == "Y" || "$INSTALL_SSL" == "N" ]]; then
break
else
msg_caution "Please enter 'Y' or 'N'."
fi
done
print_yellow "Using: $INSTALL_SSL"
}
question_11() {
echo ""
echo "$SEPQUE"
echo ""
print_wrapped "11. Install Echo Test on module E? (Y/N)"
print_gray "Suggested: Y $ACCEPT"
while true; do
printf "> "
read -r INSTALL_ECHO
INSTALL_ECHO=$(echo "${INSTALL_ECHO:-Y}" | tr '[:lower:]' '[:upper:]')
if [[ "$INSTALL_ECHO" == "Y" || "$INSTALL_ECHO" == "N" ]]; then
break
else
msg_caution "Please enter 'Y' or 'N'."
fi
done
print_yellow "Using: $INSTALL_ECHO"
}
question_12() {
echo ""
echo "$SEPQUE"
echo ""
MIN_MODULES=1
if [ "$INSTALL_ECHO" == "Y" ]; then
MIN_MODULES=5
fi
print_wrapped "12. Number of active modules for the DStar Reflector. ($MIN_MODULES - 26)"
print_gray "Suggested: 5 $ACCEPT"
while true; do
printf "> "
read -r MODQTD
MODQTD=${MODQTD:-5}
if [[ "$MODQTD" =~ ^[0-9]+$ && "$MODQTD" -ge "$MIN_MODULES" && "$MODQTD" -le 26 ]]; then
break
else
msg_caution "Must be a number between $MIN_MODULES and 26. Try again!"
fi
done
print_yellow "Using: $MODQTD"
}
question_13() {
echo ""
echo "$SEPQUE"
echo ""
print_wrapped "13. YSF Reflector UDP port number. (1-65535)"
print_gray "Suggested: 42000 $ACCEPT"
while true; do
printf "> "
read -r YSFPORT
YSFPORT=${YSFPORT:-42000}
# Numeric Validation
if [[ ! "$YSFPORT" =~ ^[0-9]+$ || "$YSFPORT" -lt 1 || "$YSFPORT" -gt 65535 ]]; then
msg_caution "Must be a number between 1 and 65535. Try again!"
continue
fi
# Check if port is in use.
if ss -H -tuln "sport = :$YSFPORT" 2>/dev/null | grep -q .; then
msg_warn "Warning: Port $YSFPORT appears to be in use."
while true; do
read -r -p "Do you want to continue anyway? (Y/N) " PORT_ANSWER
PORT_ANSWER=$(echo "${PORT_ANSWER:-N}" | tr '[:lower:]' '[:upper:]')
case "$PORT_ANSWER" in
Y)
break 2 # exit two loops
;;
N)
print_gray "Please enter a different port, or [ENTER] to accept suggested."
break # only exit the internal loop
;;
*)
msg_caution "Please answer Y or N."
;;
esac
done
continue
fi
break
done
print_yellow "Using: $YSFPORT"
}
question_14() {
echo ""
echo "$SEPQUE"
echo ""
print_wrapped "14. YSF Wires-X frequency. In Hertz, 9 digits."
print_gray "Suggested: 433125000 $ACCEPT"
while true; do
printf "> "
read -r YSFFREQ
YSFFREQ=${YSFFREQ:-433125000}
if [[ "$YSFFREQ" =~ ^[0-9]{9}$ ]]; then
break
else
msg_caution "Must be exactly 9 numeric digits (e.g., 433125000). Try again!"
fi
done
print_yellow "Using: $YSFFREQ"
}
question_15() {
echo ""
echo "$SEPQUE"
echo ""
print_wrapped "15. Auto-link YSF to a module? (Y/N)"
print_gray "Suggested: Y $ACCEPT"
while true; do
printf "> "
read -r AUTOLINK_USER
AUTOLINK_USER=$(echo "${AUTOLINK_USER:-Y}" | tr '[:lower:]' '[:upper:]')
if [[ "$AUTOLINK_USER" == "Y" || "$AUTOLINK_USER" == "N" ]]; then
break
else
msg_caution "Please enter 'Y' or 'N'."
fi
done
# Conversion (Y/N → 1/0)
if [ "$AUTOLINK_USER" == "Y" ]; then
AUTOLINK=1
else
AUTOLINK=0
fi
print_yellow "Using: $AUTOLINK_USER"
}
question_16() {
echo ""
echo "$SEPQUE"
echo ""
if [[ "$AUTOLINK" -eq 1 ]]; then
# Determine last valid module letter
LAST_INDEX=$((MODQTD - 1))
LAST_LETTER=$(printf "\\$(printf '%03o' $((65 + LAST_INDEX)))")
# Determine smart suggestion
if (( MODQTD >= 3 )); then
SUGGESTED="C"
elif (( MODQTD == 2 )); then
SUGGESTED="B"
else
SUGGESTED="A"
fi
# Display choices
if (( MODQTD <= 3 )); then
printf -v LIST "%s " {A..Z}
LIST=${LIST:0:$((MODQTD*2))}
print_wrapped "16. Module to Auto-link YSF. (One of ${LIST% })"
else
print_wrapped "16. Module to Auto-link YSF. (Choose from A to $LAST_LETTER)"
fi
print_gray "Suggested: $SUGGESTED $ACCEPT"
while true; do
printf "> "
read -r MODAUTO
MODAUTO=${MODAUTO:-$SUGGESTED}
MODAUTO=${MODAUTO^^}
if is_module_valid "$MODAUTO"; then
break
fi
if (( MODQTD <= 3 )); then
msg_caution "Invalid entry. Valid modules are: ${LIST% }"
else
msg_caution "Invalid entry. Choose from A to $LAST_LETTER"
fi
done
print_yellow "Using: $MODAUTO"
fi
echo ""
}
collect_all_questions() {
question_01
question_02
question_03
question_04
question_05
question_06
question_07
question_08
question_09
question_10
question_11
question_12
question_13
question_14
question_15
# It only calls q16 if Auto-link is enabled.
if [[ "$AUTOLINK" -eq 1 ]]; then
question_16
fi
}
# Data input verification
review_settings() {
line_type1
echo ""
center_wrap_color $ORANGE "$ICON_INFO PLEASE REVIEW YOUR SETTINGS:"
center_wrap_color $YELLOW "================================"
echo ""
print_wrapped "01. Reflector ID: $XRFNUM"
print_wrapped "02. FQDN: $XLXDOMAIN"
print_wrapped "03. E-mail: $EMAIL"
print_wrapped "04. Callsign: $CALLSIGN"
print_wrapped "05. Country: $COUNTRY"
print_wrapped "06. Time Zone: $FINAL_DISPLAY"
print_wrapped "07. XLX list comment: $COMMENT"
print_wrapped "08. Tab page text: $HEADER"
print_wrapped "09. Dashboard footnote: $FOOTER"
print_wrapped "10. SSL certification: $INSTALL_SSL"
print_wrapped "11. Echo Test: $INSTALL_ECHO"
print_wrapped "12. Modules: $MODQTD"
print_wrapped "13. YSF UDP Port: $YSFPORT"
print_wrapped "14. YSF frequency: $YSFFREQ"
print_wrapped "15. YSF Auto-link: $AUTOLINK_USER"
if [[ "$AUTOLINK" -eq 1 ]]; then
print_wrapped "16. YSF module: $MODAUTO"
fi
echo ""
}
collect_all_questions
while true; do
review_settings
print_yellow "Settings correct? Press [ENTER] to confirm, type a question number to edit it, or [X] to cancel the installation."
printf "> "
read -r CONFIRM
CONFIRM=${CONFIRM:-YES}
CONFIRM=$(echo "$CONFIRM" | tr '[:lower:]' '[:upper:]')
if [[ "$CONFIRM" == "YES" ]]; then
msg_success "Information verified, installation starting!"
break
fi
if [[ "$CONFIRM" == "X" ]]; then
echo ""
msg_caution "Installation cancelled by user."
exit 1
fi
case "$CONFIRM" in
1) question_01 ;;
2) question_02 ;;
3) question_03 ;;
4) question_04 ;;
5) question_05 ;;
6) question_06 ;;
7) question_07 ;;
8) question_08 ;;
9) question_09 ;;
10) question_10 ;;
11)
OLD_ECHO="$INSTALL_ECHO"
question_11
if [[ "$OLD_ECHO" == "N" && "$INSTALL_ECHO" == "Y" ]]; then
print_gray "Minimum modules changed. Please reconfigure question 12."
question_12
fi
if [[ "$OLD_ECHO" == "Y" && "$INSTALL_ECHO" == "N" ]]; then
print_gray "Echo Test removed. Module minimum is now 1."
fi
# If Auto-link is enabled, validate module
if [[ "$AUTOLINK" -eq 1 && -n "${MODAUTO:-}" ]]; then
if ! is_module_valid "$MODAUTO"; then
echo ""
msg_caution "Selected YSF Auto-link module is no longer valid, choose another."
question_16
fi
fi
;;
12)
question_12
if [[ "$AUTOLINK" -eq 1 && -n "${MODAUTO:-}" ]]; then
if ! is_module_valid "$MODAUTO"; then
print_gray "Module range changed. Please reconfigure question 16."
question_16
fi
fi
;;
13) question_13 ;;
14) question_14 ;;
15)
OLD_AUTOLINK="$AUTOLINK"
question_15
if [[ "$OLD_AUTOLINK" -eq 0 && "$AUTOLINK" -eq 1 ]]; then
question_16
fi
if [[ "$OLD_AUTOLINK" -eq 1 && "$AUTOLINK" -eq 0 ]]; then
unset MODAUTO
fi
;;
16)
if [[ "$AUTOLINK" -eq 1 ]]; then
question_16
else
msg_caution "Question 16 is not active."
fi
;;
*)
msg_caution "Invalid input. Press [ENTER] to confirm, enter a question number (1-16), or [X] to cancel."
;;
esac
done
echo ""
line_type1
echo ""
center_wrap_color $BLUE_BRIGHT "$ICON_INFO UPDATING OS..."
center_wrap_color $BLUE "=================="
echo ""
apt-get update || error_exit "Failed to update package lists. Check your internet connection or package manager configuration."
apt-get full-upgrade -y || error_exit "Failed to upgrade packages. Check your internet connection or package manager configuration."
# Apply timezone only if it's NOT the system timezone.
echo ""
print_wrapped "Timezone adjustment:"
if [[ "$TIMEZONE_USE_SYSTEM" -eq 0 ]]; then
print_yellow "Applying new timezone: $TIMEZONE"
timedatectl set-timezone "$TIMEZONE" || error_exit "Failed to apply timezone: $TIMEZONE"
else
print_gray "Detected system timezone preserved: $TIMEZONE"
fi
echo ""
msg_success "System updated successfully!"
echo ""
line_type1
echo ""
center_wrap_color $BLUE_BRIGHT "$ICON_INFO INSTALLING DEPENDENCIES..."
center_wrap_color $BLUE "=============================="
echo ""
# Check available disk space (require at least 1GB)
AVAIL_SPACE=$(df /usr/src | tail -1 | awk '{print $4}')
if [ "$AVAIL_SPACE" -lt 1048576 ]; then
error_exit "Insufficient disk space. At least 1GB required in /usr/src"
fi
apt-get install -y "${DEPAPP[@]}" || error_exit "Failed to install dependencies. Check package manager configuration."
PHPVER=$(php -v | head -n1 | awk '{print $2}' | cut -d. -f1,2)
if [ -z "$PHPVER" ]; then
error_exit "PHP installation failed or version could not be determined"
fi
echo ""
print_gray "PHP version: $PHPVER"
echo ""
msg_success "Dependencies installed!"
echo ""
line_type1
echo ""
center_wrap_color $BLUE_BRIGHT "$ICON_INFO DOWNLOADING THE XLX APP..."
center_wrap_color $BLUE "=============================="
echo ""
echo ""
cd "$USRSRC" || error_exit "Failed to change to $USRSRC directory"
echo "Cloning repository..."
git clone --depth 1 "$XLXREP" || error_exit "Failed to clone XLX repository"
cd "$USRSRC/xlxd/src" || error_exit "Failed to change to xlxd/src directory"
make clean || error_exit "Failed to run 'make clean'. Check the Makefile and build environment."
echo "Seeding customizations..."
MAINCONFIG="$USRSRC/xlxd/src/main.h"
if [ ! -f "$MAINCONFIG" ]; then
error_exit "Configuration file $MAINCONFIG not found"
fi
sed -i \
-e "s|\(NB_OF_MODULES\s*\)[0-9]*|\1$MODQTD|g" \
-e "s|\(YSF_PORT\s*\)[0-9]*|\1$YSFPORT|g" \
-e "s|\(YSF_DEFAULT_NODE_TX_FREQ\s*\)[0-9]*|\1$YSFFREQ|g" \
-e "s|\(YSF_DEFAULT_NODE_RX_FREQ\s*\)[0-9]*|\1$YSFFREQ|g" \
-e "s|\(YSF_AUTOLINK_ENABLE\s*\)[0-9]*|\1$AUTOLINK|g" \
"$MAINCONFIG" || error_exit "Failed to apply customizations to $MAINCONFIG"
if [ "$AUTOLINK" -eq 1 ]; then
sed -i "s|\(YSF_AUTOLINK_MODULE\s*\)'[A-Z]*'|\1'$MODAUTO'|g" "$MAINCONFIG" \
|| error_exit "Failed to apply YSF_AUTOLINK_MODULE to $MAINCONFIG"
fi
echo ""
echo "Reflector $XRFNUM"
echo "Ethernet IP address: $HOMEIP"
echo "Public IP address: $PUBLIP"
echo "Network adapter name: $NETACT"
echo ""
msg_success "Repository cloned and customizations applied!"
echo ""
line_type1
echo ""
center_wrap_color $BLUE_BRIGHT "$ICON_INFO COMPILING..."
center_wrap_color $BLUE "================"
echo ""
echo ""