forked from HostiFi/auto-unifi-adopt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunify.sh
2430 lines (2333 loc) · 156 KB
/
unify.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
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
# UniFi Network Application Easy Installation Script.
###################################################################################################################################################################################################
# #
# List of supported Distributions/Operating Systems #
# #
###################################################################################################################################################################################################
# | Ubuntu Precise Pangolin ( 12.04 )
# | Ubuntu Trusty Tahr ( 14.04 )
# | Ubuntu Xenial Xerus ( 16.04 )
# | Ubuntu Bionic Beaver ( 18.04 )
# | Ubuntu Cosmic Cuttlefish ( 18.10 )
# | Ubuntu Disco Dingo ( 19.04 )
# | Ubuntu Eoan Ermine ( 19.10 )
# | Ubuntu Focal Fossa ( 20.04 )
# | Ubuntu Groovy Gorilla ( 20.10 )
# | Ubuntu Hirsute Hippo ( 21.04 )
# | Ubuntu Impish Indri ( 21.10 )
# | Ubuntu Jammy Jellyfish ( 22.04 )
# | Debian Jessie ( 8 )
# | Debian Stretch ( 9 )
# | Debian Buster ( 10 )
# | Debian Bullseye ( 11 )
# | Linux Mint 13 ( Maya )
# | Linux Mint 17 ( Qiana | Rebecca | Rafaela | Rosa )
# | Linux Mint 18 ( Sarah | Serena | Sonya | Sylvia )
# | Linux Mint 19 ( Tara | Tessa | Tina | Tricia )
# | Linux Mint 20 ( Ulyana | Ulyssa | Uma | Una )
# | Linux Mint 4 ( Debbie )
# | MX Linux 18 ( Continuum )
# | Progress-Linux ( Engywuck )
# | Parrot OS
# | Elementary OS
# | Deepin Linux
# | Kali Linux ( rolling )
###################################################################################################################################################################################################
# Version | 5.1.4
# Application version | 5.13.32-3e11950f9b
# Author | Glenn Rietveld
# Email | [email protected]
# Website | https://GlennR.nl
###################################################################################################################################################################################################
# #
# Color Codes #
# #
###################################################################################################################################################################################################
RESET='\033[0m'
YELLOW='\033[1;33m'
#GRAY='\033[0;37m'
#WHITE='\033[1;37m'
GRAY_R='\033[39m'
WHITE_R='\033[39m'
RED='\033[1;31m' # Light Red.
GREEN='\033[1;32m' # Light Green.
#BOLD='\e[1m'
###################################################################################################################################################################################################
# #
# Start Checks #
# #
###################################################################################################################################################################################################
header() {
clear
clear
echo -e "${GREEN}#########################################################################${RESET}\\n"
}
header_red() {
clear
clear
echo -e "${RED}#########################################################################${RESET}\\n"
}
# Check for root (SUDO).
if [[ "$EUID" -ne 0 ]]; then
header_red
echo -e "${WHITE_R}#${RESET} The script need to be run as root...\\n\\n"
echo -e "${WHITE_R}#${RESET} For Ubuntu based systems run the command below to login as root"
echo -e "${GREEN}#${RESET} sudo -i\\n"
echo -e "${WHITE_R}#${RESET} For Debian based systems run the command below to login as root"
echo -e "${GREEN}#${RESET} su\\n\\n"
exit 1
fi
if ! env | grep "LC_ALL\\|LANG" | grep -iq "en_US\\|C.UTF-8"; then
header
echo -e "${WHITE_R}#${RESET} Your language is not set to English ( en_US ), the script will temporarily set the language to English."
echo -e "${WHITE_R}#${RESET} Information: This is done to prevent issues in the script.."
export LC_ALL=C &> /dev/null
set_lc_all=true
sleep 3
fi
abort() {
if [[ "${set_lc_all}" == 'true' ]]; then unset LC_ALL; fi
echo -e "\\n\\n${RED}#########################################################################${RESET}\\n"
echo -e "${WHITE_R}#${RESET} An error occurred. Aborting script..."
echo -e "${WHITE_R}#${RESET} Please contact Glenn R. (AmazedMender16) on the Community Forums!\\n"
echo -e "${WHITE_R}#${RESET} Creating support file..."
mkdir -p "/tmp/EUS/support" &> /dev/null
if dpkg -l lsb-release 2> /dev/null | grep -iq "^ii\\|^hi"; then lsb_release -a &> "/tmp/EUS/support/lsb-release"; fi
df -h &> "/tmp/EUS/support/df"
free -hm &> "/tmp/EUS/support/memory"
uname -a &> "/tmp/EUS/support/uname"
dpkg -l | grep "mongo\\|oracle\\|openjdk\\|unifi" &> "/tmp/EUS/support/unifi-packages"
dpkg -l &> "/tmp/EUS/support/dpkg-list"
echo "${architecture}" &> "/tmp/EUS/support/architecture"
# shellcheck disable=SC2129
sed -n '3p' "${script_location}" &>> "/tmp/EUS/support/script"
grep "# Version" "${script_location}" | head -n1 &>> "/tmp/EUS/support/script"
grep "# Application version" "${script_location}" | head -n1 &>> "/tmp/EUS/support/script"
if dpkg -l tar 2> /dev/null | grep -iq "^ii\\|^hi"; then
tar -cvf /tmp/eus_support.tar.gz "/tmp/EUS" "${eus_dir}" &> /dev/null && support_file="/tmp/eus_support.tar.gz"
elif dpkg -l zip 2> /dev/null | grep -iq "^ii\\|^hi"; then
zip -r /tmp/eus_support.zip "/tmp/EUS/*" "${eus_dir}/*" &> /dev/null && support_file="/tmp/eus_support.zip"
fi
if [[ -n "${support_file}" ]]; then echo -e "${WHITE_R}#${RESET} Support file has been created here: ${support_file} \\n"; fi
if [[ -f /tmp/EUS/services/stopped_list && -s /tmp/EUS/services/stopped_list ]]; then
while read -r service; do
echo -e "\\n${WHITE_R}#${RESET} Starting ${service}.."
systemctl start "${service}" && echo -e "${GREEN}#${RESET} Successfully started ${service}!" || echo -e "${RED}#${RESET} Failed to start ${service}!"
done < /tmp/EUS/services/stopped_list
fi
exit 1
}
if uname -a | tr '[:upper:]' '[:lower:]' | grep -iq "cloudkey\\|uck\\|ubnt-mtk"; then
eus_dir='/srv/EUS'
is_cloudkey=true
elif grep -iq "UCKP\\|UCKG2\\|UCK" /usr/lib/version &> /dev/null; then
eus_dir='/srv/EUS'
is_cloudkey=true
else
eus_dir='/usr/lib/EUS'
is_cloudkey=false
fi
script_logo() {
cat << "EOF"
_______________ ___ _________ .___ __ .__ .__
\_ _____/ | \/ _____/ | | ____ _______/ |______ | | | |
| __)_| | /\_____ \ | |/ \ / ___/\ __\__ \ | | | |
| \ | / / \ | | | \\___ \ | | / __ \| |_| |__
/_______ /______/ /_______ / |___|___| /____ > |__| (____ /____/____/
\/ \/ \/ \/ \/
EOF
}
start_script() {
script_location="${BASH_SOURCE[0]}"
script_name=$(basename "${BASH_SOURCE[0]}")
mkdir -p "${eus_dir}/logs" 2> /dev/null
mkdir -p /tmp/EUS/ 2> /dev/null
mkdir -p /tmp/EUS/upgrade/ 2> /dev/null
mkdir -p /tmp/EUS/dpkg/ 2> /dev/null
header
script_logo
echo -e " Easy UniFi Network Application Install Script"
echo -e "\\n${WHITE_R}#${RESET} Starting the Easy UniFi Install Script.."
echo -e "${WHITE_R}#${RESET} Thank you for using my Easy UniFi Install Script :-)\\n\\n"
sleep 4
}
start_script
help_script() {
if [[ "${script_option_help}" == 'true' ]]; then header; script_logo; else echo -e "${WHITE_R}----${RESET}\\n"; fi
echo -e " Easy UniFi Network Application Install Script assistance\\n"
echo -e "
Script usage:
bash ${script_name} [options]
Script options:
--skip Skip any kind of manual input.
--skip-install-haveged Skip installation of haveged.
--skip-swap Skip swap file check/creation.
--add-repository Add UniFi Repository if --skip is used.
--local-install Inform script that it's a local UniFi Network installation, to open port 10001/dup ( discovery ).
--custom-url [argument] Manually provide a UniFi Network Application download URL.
example:
--custom-url https://dl.ui.com/unifi/5.12.72/unifi_sysvinit_all.deb
--help Shows this information :)\\n\\n
Script options for UniFi Easy Encrypt:
--v6 Run the script in IPv6 mode instead of IPv4.
--email [argument] Specify what email address you want to use
for renewal notifications.
example:
--email [email protected]
--fqdn [argument] Specify what domain name ( FQDN ) you want to use, you
can specify multiple domain names with : as seperator, see
the example below:
--fqdn glennr.nl:www.glennr.nl
--server-ip [argument] Specify the server IP address manually.
example:
--server-ip 1.1.1.1
--retry [argument] Retry the unattended script if it aborts for X times.
example:
--retry 5
--external-dns [argument] Use external DNS server to resolve the FQDN.
example:
--external-dns 1.1.1.1
--force-renew Force renew the certificates.
--dns-challenge Run the script in DNS mode instead of HTTP.
example:
--private-key /tmp/PRIVATE.key
--signed-certificate [argument] Specify path to your signed certificate (paid certificate)
example:
--signed-certificate /tmp/SSL_CERTIFICATE.cer
--chain-certificate [argument] Specify path to your chain certificate (paid certificate)
example:
--chain-certificate /tmp/CHAIN.cer
--intermediate-certificate [argument] Specify path to your intermediate certificate (paid certificate)
example:
--intermediate-certificate /tmp/INTERMEDIATE.cer
--own-certificate Requirement if you want to import your own paid certificates
with the use of --skip.\\n\\n"
exit 0
}
rm --force /tmp/EUS/script_options &> /dev/null
rm --force /tmp/EUS/le_script_options &> /dev/null
script_option_list=(-skip --skip --skip-install-haveged --skip-swap --add-repository --local --local-controller --local-install --custom-url --help --v6 --ipv6 --email --mail --fqdn --domain-name --server-ip --server-address --retry --external-dns --force-renew --renew --dns --dns-challenge)
while [ -n "$1" ]; do
case "$1" in
-skip | --skip)
script_option_skip=true
echo "--skip" &>> /tmp/EUS/script_options
echo "--skip" &>> /tmp/EUS/le_script_options;;
--skip-install-haveged)
script_option_skip_install_haveged=true
echo "--skip-install-haveged" &>> /tmp/EUS/script_options;;
--skip-swap)
script_option_skip_swap=true
echo "--skip-swap" &>> /tmp/EUS/script_options;;
--add-repository)
script_option_add_repository=true
echo "--add-repository" &>> /tmp/EUS/script_options;;
--local | --local-controller | --local-install)
script_option_local_install=true
echo "--local-install" &>> /tmp/EUS/script_options;;
--custom-url)
if [[ -n "${2}" ]]; then if echo "${2}" | grep -ioq ".deb"; then custom_url_down_provided=true; custom_download_url="${2}"; else header_red; echo -e "${RED}#${RESET} Provided URL does not have the 'deb' extension...\\n"; help_script; fi; fi
script_option_custom_url=true
if [[ "${custom_url_down_provided}" == 'true' ]]; then echo "--custom-url ${2}" &>> /tmp/EUS/script_options; else echo "--custom-url" &>> /tmp/EUS/script_options; fi;;
--help)
script_option_help=true
help_script;;
--v6 | --ipv6)
echo "--v6" &>> /tmp/EUS/le_script_options;;
--email | --mail)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo -e "--email ${2}" &>> /tmp/EUS/le_script_options
shift;;
--fqdn | --domain-name)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo -e "--fqdn ${2}" &>> /tmp/EUS/le_script_options
fqdn_specified=true
shift;;
--server-ip | --server-address)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo -e "--server-ip ${2}" &>> /tmp/EUS/le_script_options
shift;;
--retry)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo -e "--retry ${2}" &>> /tmp/EUS/le_script_options
shift;;
--external-dns)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then echo -e "--external-dns" &>> /tmp/EUS/le_script_options; else echo -e "--external-dns ${2}" &>> /tmp/EUS/le_script_options; fi
done;;
--force-renew | --renew)
echo -e "--force-renew" &>> /tmp/EUS/le_script_options;;
--dns | --dns-challenge)
echo -e "--dns-challenge" &>> /tmp/EUS/le_script_options;;
--priv-key | --private-key)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo "--private-key ${2}" &>> /tmp/EUS/le_script_options
shift;;
--signed-crt | --signed-certificate)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo "--signed-certificate ${2}" &>> /tmp/EUS/le_script_options
shift;;
--chain-crt | --chain-certificate)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo "--chain-certificate ${2}" &>> /tmp/EUS/le_script_options
shift;;
--intermediate-crt | --intermediate-certificate)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo "--intermediate-certificate ${2}" &>> /tmp/EUS/le_script_options
shift;;
--own-certificate)
echo "--own-certificate" &>> /tmp/EUS/le_script_options;;
esac
shift
done
# Check script options.
if [[ -f /tmp/EUS/script_options && -s /tmp/EUS/script_options ]]; then IFS=" " read -r script_options <<< "$(tr '\r\n' ' ' < /tmp/EUS/script_options)"; fi
if [[ "$(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "downloads-distro.mongodb.org")" -gt 0 ]]; then
grep -riIl "downloads-distro.mongodb.org" /etc/apt/ &>> /tmp/EUS/repository/dead_mongodb_repository
while read -r glennr_mongo_repo; do
sed -i '/downloads-distro.mongodb.org/d' "${glennr_mongo_repo}" 2> /dev/null
if ! [[ -s "${glennr_mongo_repo}" ]]; then
rm --force "${glennr_mongo_repo}" 2> /dev/null
fi
done < /tmp/EUS/repository/dead_mongodb_repository
rm --force /tmp/EUS/repository/dead_mongodb_repository
fi
if apt-key list 2>/dev/null | grep mongodb -B1 | grep -iq "expired:"; then
wget -qO - https://www.mongodb.org/static/pgp/server-3.4.asc | apt-key add - &> /dev/null
fi
find "${eus_dir}/logs/" -printf "%f\\n" | grep '.*.log' | awk '!a[$0]++' &> /tmp/EUS/log_files
while read -r log_file; do
if [[ -f "${eus_dir}/logs/${log_file}" ]]; then
log_file_size=$(stat -c%s "${eus_dir}/logs/${log_file}")
if [[ "${log_file_size}" -gt "10485760" ]]; then
tail -n1000 "${eus_dir}/logs/${log_file}" &> "${log_file}.tmp"
mv "${eus_dir}/logs/${log_file}.tmp" "${eus_dir}/logs/${log_file}"
fi
fi
done < /tmp/EUS/log_files
rm --force /tmp/EUS/log_files
run_apt_get_update() {
if ! [[ -d /tmp/EUS/keys ]]; then mkdir -p /tmp/EUS/keys; fi
if ! [[ -f /tmp/EUS/keys/missing_keys && -s /tmp/EUS/keys/missing_keys ]]; then
if [[ "${hide_apt_update}" == 'true' ]]; then
echo -e "${WHITE_R}#${RESET} Running apt-get update..."
if apt-get update &> /tmp/EUS/keys/apt_update; then echo -e "${GREEN}#${RESET} Successfully ran apt-get update! \\n"; else echo -e "${YELLOW}#${RESET} Something went wrong during running apt-get update! \\n"; fi
unset hide_apt_update
else
apt-get update 2>&1 | tee /tmp/EUS/keys/apt_update
fi
grep -o 'NO_PUBKEY.*' /tmp/EUS/keys/apt_update | sed 's/NO_PUBKEY //g' | tr ' ' '\n' | awk '!a[$0]++' &> /tmp/EUS/keys/missing_keys
fi
if [[ -f /tmp/EUS/keys/missing_keys && -s /tmp/EUS/keys/missing_keys ]]; then
#header
#echo -e "${WHITE_R}#${RESET} Some keys are missing.. The script will try to add the missing keys."
#echo -e "\\n${WHITE_R}----${RESET}\\n"
while read -r key; do
echo -e "${WHITE_R}#${RESET} Key ${key} is missing.. adding!"
http_proxy=$(env | grep -i "http.*Proxy" | cut -d'=' -f2 | sed 's/[";]//g')
if [[ -n "$http_proxy" ]]; then
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy="${http_proxy}" --recv-keys "$key" &> /dev/null && echo -e "${GREEN}#${RESET} Successfully added key ${key}!\\n" || fail_key=true
elif [[ -f /etc/apt/apt.conf ]]; then
apt_http_proxy=$(grep "http.*Proxy" /etc/apt/apt.conf | awk '{print $2}' | sed 's/[";]//g')
if [[ -n "${apt_http_proxy}" ]]; then
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy="${apt_http_proxy}" --recv-keys "$key" &> /dev/null && echo -e "${GREEN}#${RESET} Successfully added key ${key}!\\n" || fail_key=true
fi
else
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv "$key" &> /dev/null && echo -e "${GREEN}#${RESET} Successfully added key ${key}!\\n" || fail_key=true
fi
if [[ "${fail_key}" == 'true' ]]; then
echo -e "${RED}#${RESET} Failed to add key ${key}!"
echo -e "${WHITE_R}#${RESET} Trying different method to get key: ${key}"
gpg -vvv --debug-all --keyserver keyserver.ubuntu.com --recv-keys "${key}" &> /tmp/EUS/keys/failed_key
debug_key=$(grep "KS_GET" /tmp/EUS/keys/failed_key | grep -io "0x.*")
wget -q "https://keyserver.ubuntu.com/pks/lookup?op=get&search=${debug_key}" -O- | gpg --dearmor > "/tmp/EUS/keys/EUS-${key}.gpg"
mv "/tmp/EUS/keys/EUS-${key}.gpg" /etc/apt/trusted.gpg.d/ && echo -e "${GREEN}#${RESET} Successfully added key ${key}!\\n"
fi
sleep 1
done < /tmp/EUS/keys/missing_keys
rm --force /tmp/EUS/keys/missing_keys
rm --force /tmp/EUS/keys/apt_update
#header
#echo -e "${WHITE_R}#${RESET} Running apt-get update again.\\n\\n"
#sleep 2
apt-get update &> /tmp/EUS/keys/apt_update
if grep -qo 'NO_PUBKEY.*' /tmp/EUS/keys/apt_update; then
if [[ "${hide_apt_update}" != 'true' ]]; then hide_apt_update=true; fi
run_apt_get_update
fi
fi
}
# Check if system runs Unifi OS
if dpkg -l unifi-core 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
unifi_core_system=true
if [[ -f /proc/ubnthal/system.info ]]; then if grep -iq "shortname" /proc/ubnthal/system.info; then unifi_core_device=$(grep "shortname" /proc/ubnthal/system.info | sed 's/shortname=//g'); fi; fi
if [[ -f /etc/motd && -s /etc/motd && -z "${unifi_core_device}" ]]; then unifi_core_device=$(grep -io "welcome.*" /etc/motd | sed -e 's/Welcome //g' -e 's/to //g' -e 's/the //g' -e 's/!//g'); fi
if [[ -f /usr/lib/version && -s /usr/lib/version && -z "${unifi_core_device}" ]]; then unifi_core_device=$(cut -d'.' -f1 /usr/lib/version); fi
if [[ -z "${unifi_core_device}" ]]; then unifi_core_device='Unknown device'; fi
fi
cancel_script() {
if [[ "${set_lc_all}" == 'true' ]]; then unset LC_ALL &> /dev/null; fi
if [[ "${script_option_skip}" == 'true' ]]; then
echo -e "\\n${WHITE_R}#########################################################################${RESET}\\n"
else
header
fi
echo -e "${WHITE_R}#${RESET} Cancelling the script!\\n\\n"
exit 0
}
http_proxy_found() {
header
echo -e "${GREEN}#${RESET} HTTP Proxy found. | ${WHITE_R}${http_proxy}${RESET}\\n\\n"
}
remove_yourself() {
if [[ "${set_lc_all}" == 'true' ]]; then unset LC_ALL &> /dev/null; fi
if [[ "${delete_script}" == 'true' || "${script_option_skip}" == 'true' ]]; then if [[ -e "${script_location}" ]]; then rm --force "${script_location}" 2> /dev/null; fi; fi
}
christmass_new_year() {
date_d=$(date '+%d' | sed "s/^0*//g; s/\.0*/./g")
date_m=$(date '+%m' | sed "s/^0*//g; s/\.0*/./g")
if [[ "${date_m}" == '12' && "${date_d}" -ge '18' && "${date_d}" -lt '26' ]]; then
echo -e "\\n${WHITE_R}----${RESET}\\n"
echo -e "${WHITE_R}#${RESET} GlennR wishes you a Merry Christmas! May you be blessed with health and happiness!"
christmas_message=true
fi
if [[ "${date_m}" == '12' && "${date_d}" -ge '24' && "${date_d}" -le '30' ]]; then
if [[ "${christmas_message}" != 'true' ]]; then echo -e "\\n${WHITE_R}----${RESET}\\n"; fi
if [[ "${christmas_message}" == 'true' ]]; then echo -e ""; fi
date_y=$(date -d "+1 year" +"%Y")
echo -e "${WHITE_R}#${RESET} HAPPY NEW YEAR ${date_y}"
echo -e "${WHITE_R}#${RESET} May the new year turn all your dreams into reality and all your efforts into great achievements!"
new_year_message=true
elif [[ "${date_m}" == '12' && "${date_d}" == '31' ]]; then
if [[ "${christmas_message}" != 'true' ]]; then echo -e "\\n${WHITE_R}----${RESET}\\n"; fi
if [[ "${christmas_message}" == 'true' ]]; then echo -e ""; fi
date_y=$(date -d "+1 year" +"%Y")
echo -e "${WHITE_R}#${RESET} HAPPY NEW YEAR ${date_y}"
echo -e "${WHITE_R}#${RESET} Tomorrow, is the first blank page of a 365 page book. Write a good one!"
new_year_message=true
fi
if [[ "${date_m}" == '1' && "${date_d}" -le '5' ]]; then
if [[ "${christmas_message}" != 'true' ]]; then echo -e "\\n${WHITE_R}----${RESET}\\n"; fi
if [[ "${christmas_message}" == 'true' ]]; then echo -e ""; fi
date_y=$(date '+%Y')
echo -e "${WHITE_R}#${RESET} HAPPY NEW YEAR ${date_y}"
echo -e "${WHITE_R}#${RESET} May this new year all your dreams turn into reality and all your efforts into great achievements"
new_year_message=true
fi
}
author() {
christmass_new_year
if [[ "${new_year_message}" == 'true' || "${christmas_message}" == 'true' ]]; then echo -e "\\n${WHITE_R}----${RESET}\\n"; fi
echo -e "${WHITE_R}#${RESET} ${GRAY_R}Author | ${WHITE_R}Glenn R.${RESET}"
echo -e "${WHITE_R}#${RESET} ${GRAY_R}Email | ${WHITE_R}[email protected]${RESET}"
echo -e "${WHITE_R}#${RESET} ${GRAY_R}Website | ${WHITE_R}https://GlennR.nl${RESET}"
echo -e "\\n\\n"
}
# Get distro.
get_distro() {
if [[ -z "$(command -v lsb_release)" ]]; then
if [[ -f "/etc/os-release" ]]; then
if grep -iq VERSION_CODENAME /etc/os-release; then
os_codename=$(grep VERSION_CODENAME /etc/os-release | sed 's/VERSION_CODENAME//g' | tr -d '="' | tr '[:upper:]' '[:lower:]')
elif ! grep -iq VERSION_CODENAME /etc/os-release; then
os_codename=$(grep PRETTY_NAME /etc/os-release | sed 's/PRETTY_NAME=//g' | tr -d '="' | awk '{print $4}' | sed 's/\((\|)\)//g' | sed 's/\/sid//g' | tr '[:upper:]' '[:lower:]')
if [[ -z "${os_codename}" ]]; then
os_codename=$(grep PRETTY_NAME /etc/os-release | sed 's/PRETTY_NAME=//g' | tr -d '="' | awk '{print $3}' | sed 's/\((\|)\)//g' | sed 's/\/sid//g' | tr '[:upper:]' '[:lower:]')
fi
fi
fi
else
os_codename=$(lsb_release -cs | tr '[:upper:]' '[:lower:]')
if [[ "${os_codename}" == 'n/a' ]]; then
os_codename=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
fi
fi
if [[ "${os_codename}" =~ (precise|maya|luna) ]]; then repo_codename=precise; os_codename=precise
elif [[ "${os_codename}" =~ (trusty|qiana|rebecca|rafaela|rosa|freya) ]]; then repo_codename=trusty; os_codename=trusty
elif [[ "${os_codename}" =~ (xenial|sarah|serena|sonya|sylvia|loki) ]]; then repo_codename=xenial; os_codename=xenial
elif [[ "${os_codename}" =~ (bionic|tara|tessa|tina|tricia|hera|juno) ]]; then repo_codename=bionic; os_codename=bionic
elif [[ "${os_codename}" =~ (focal|ulyana|ulyssa|uma|una) ]]; then repo_codename=focal; os_codename=focal
elif [[ "${os_codename}" =~ (stretch|continuum) ]]; then repo_codename=stretch; os_codename=stretch
elif [[ "${os_codename}" =~ (buster|debbie|parrot|engywuck-backports|engywuck|deepin) ]]; then repo_codename=buster; os_codename=buster
elif [[ "${os_codename}" =~ (bullseye|kali-rolling) ]]; then repo_codename=bullseye; os_codename=bullseye
else
repo_codename="${os_codename}"
os_codename="${os_codename}"
fi
}
get_distro
if ! [[ "${os_codename}" =~ (precise|maya|trusty|qiana|rebecca|rafaela|rosa|xenial|sarah|serena|sonya|sylvia|bionic|tara|tessa|tina|tricia|cosmic|disco|eoan|focal|groovy|hirsute|impish|jammy|jessie|stretch|continuum|buster|bullseye|bookworm) ]]; then
clear
header_red
echo -e "${WHITE_R}#${RESET} This script is not made for your OS.."
echo -e "${WHITE_R}#${RESET} Feel free to contact Glenn R. (AmazedMender16) on the Community Forums if you need help with installing your UniFi Network Application."
echo -e ""
echo -e "OS_CODENAME = ${os_codename}"
echo -e ""
echo -e ""
exit 1
fi
if ! grep -iq '^127.0.0.1.*localhost' /etc/hosts; then
clear
header_red
echo -e "${WHITE_R}#${RESET} '127.0.0.1 localhost' does not exist in your /etc/hosts file."
echo -e "${WHITE_R}#${RESET} You will most likely see application startup issues if it doesn't exist..\\n\\n"
read -rp $'\033[39m#\033[0m Do you want to add "127.0.0.1 localhost" to your /etc/hosts file? (Y/n) ' yes_no
case "$yes_no" in
[Yy]*|"")
echo -e "${WHITE_R}----${RESET}\\n"
echo -e "${WHITE_R}#${RESET} Adding '127.0.0.1 localhost' to /etc/hosts"
sed -i '1i # ------------------------------' /etc/hosts
sed -i '1i 127.0.0.1 localhost' /etc/hosts
sed -i '1i # Added by GlennR EUS script' /etc/hosts && echo -e "${WHITE_R}#${RESET} Done..\\n\\n"
sleep 3;;
[Nn]*) ;;
esac
fi
if [[ $(echo "${PATH}" | grep -c "/sbin") -eq 0 ]]; then
#PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin
#PATH=$PATH:/usr/sbin
PATH="$PATH:/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin"
fi
if ! [[ -d /etc/apt/sources.list.d ]]; then mkdir -p /etc/apt/sources.list.d; fi
if ! [[ -d /tmp/EUS/keys ]]; then mkdir -p /tmp/EUS/keys; fi
unifi_package=$(dpkg -l | grep "unifi " | awk '{print $1}' | tr '[:upper:]' '[:lower:]')
if [[ -n "${unifi_package}" ]]; then
if [[ "${unifi_package}" != "ii" ]]; then
header_red
echo -e "${RED}#${RESET} You have a broken UniFi Network Application installation...\\n\\n${WHITE}#${RESET} Removing the broken UniFi Network Application installation..."
if dpkg --remove --force-remove-reinstreq unifi &>> "${eus_dir}/logs/broken_unifi.log"; then echo -e "${GREEN}#${RESET} Successfully removed the broken UniFi Network Application installation!"; else echo -e "${RED}#${RESET} Failed to remove the broken UniFi Network Application installation!"; fi
sleep 3
fi
fi
# Check if --show-progrss is supported in wget version
if wget --help | grep -q '\--show-progress'; then echo "--show-progress" &>> /tmp/EUS/wget_option; fi
if [[ -f /tmp/EUS/wget_option && -s /tmp/EUS/wget_option ]]; then IFS=" " read -r -a wget_progress <<< "$(tr '\r\n' ' ' < /tmp/EUS/wget_option)"; fi
# Check if UniFi is already installed.
if dpkg -l | grep "unifi " | grep -q "^ii\\|^hi"; then
header
echo -e "${WHITE_R}#${RESET} UniFi is already installed on your system!${RESET}"
echo -e "${WHITE_R}#${RESET} You can use my Easy Update Script to update your UniFi Network Application.${RESET}\\n\\n"
read -rp $'\033[39m#\033[0m Would you like to download and run my Easy Update Script? (Y/n) ' yes_no
case "$yes_no" in
[Yy]*|"")
rm --force "${script_location}" 2> /dev/null
wget -q "${wget_progress[@]}" https://get.glennr.nl/unifi/update/unifi-update.sh && bash unifi-update.sh; exit 0;;
[Nn]*) exit 0;;
esac
fi
dpkg_locked_message() {
header_red
echo -e "${WHITE_R}#${RESET} dpkg is locked.. Waiting for other software managers to finish!"
echo -e "${WHITE_R}#${RESET} If this is everlasting please contact Glenn R. (AmazedMender16) on the Community Forums!\\n\\n"
sleep 5
if [[ -z "$dpkg_wait" ]]; then
echo "glennr_lock_active" >> /tmp/glennr_lock
fi
}
dpkg_locked_60_message() {
header
echo -e "${WHITE_R}#${RESET} dpkg is already locked for 60 seconds..."
echo -e "${WHITE_R}#${RESET} Would you like to force remove the lock?\\n\\n"
}
# Check if dpkg is locked
if dpkg -l psmisc 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
while fuser /var/lib/dpkg/lock /var/lib/apt/lists/lock /var/cache/apt/archives/lock >/dev/null 2>&1; do
dpkg_locked_message
if [[ $(grep -c "glennr_lock_active" /tmp/glennr_lock) -ge 12 ]]; then
rm --force /tmp/glennr_lock 2> /dev/null
dpkg_locked_60_message
if [[ "${script_option_skip}" != 'true' ]]; then read -rp $'\033[39m#\033[0m Do you want to proceed with removing the lock? (Y/n) ' yes_no; fi
case "$yes_no" in
[Yy]*|"")
killall apt apt-get 2> /dev/null
rm --force /var/lib/apt/lists/lock 2> /dev/null
rm --force /var/cache/apt/archives/lock 2> /dev/null
rm --force /var/lib/dpkg/lock* 2> /dev/null
dpkg --configure -a 2> /dev/null
DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install --fix-broken 2> /dev/null;;
[Nn]*) dpkg_wait=true;;
esac
fi
done;
else
dpkg -i /dev/null 2> /tmp/glennr_dpkg_lock; if grep -q "locked.* another" /tmp/glennr_dpkg_lock; then dpkg_locked=true; rm --force /tmp/glennr_dpkg_lock 2> /dev/null; fi
while [[ "${dpkg_locked}" == 'true' ]]; do
unset dpkg_locked
dpkg_locked_message
if [[ $(grep -c "glennr_lock_active" /tmp/glennr_lock) -ge 12 ]]; then
rm --force /tmp/glennr_lock 2> /dev/null
dpkg_locked_60_message
if [[ "${script_option_skip}" != 'true' ]]; then read -rp $'\033[39m#\033[0m Do you want to proceed with force removing the lock? (Y/n) ' yes_no; fi
case "$yes_no" in
[Yy]*|"")
pgrep "apt" >> /tmp/EUS/apt
while read -r glennr_apt; do
kill -9 "$glennr_apt" 2> /dev/null
done < /tmp/EUS/apt
rm --force /tmp/EUS/apt 2> /dev/null
rm --force /var/lib/apt/lists/lock 2> /dev/null
rm --force /var/cache/apt/archives/lock 2> /dev/null
rm --force /var/lib/dpkg/lock* 2> /dev/null
dpkg --configure -a 2> /dev/null
DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install --fix-broken 2> /dev/null;;
[Nn]*) dpkg_wait=true;;
esac
fi
dpkg -i /dev/null 2> /tmp/glennr_dpkg_lock; if grep -q "locked.* another" /tmp/glennr_dpkg_lock; then dpkg_locked=true; rm --force /tmp/glennr_dpkg_lock 2> /dev/null; fi
done;
rm --force /tmp/glennr_dpkg_lock 2> /dev/null
fi
script_version_check() {
if dpkg -l curl 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
version=$(grep -i "# Application version" "${script_location}" | head -n 1 | awk '{print $5}' | cut -d'-' -f1)
script_online_version_dots=$(curl "https://get.glennr.nl/unifi/install/unifi-${version}.sh" -s | grep "# Version" | head -n 1 | awk '{print $5}')
script_local_version_dots=$(grep "# Version" "${script_location}" | head -n 1 | awk '{print $5}')
script_online_version="${script_online_version_dots//./}"
script_local_version="${script_local_version_dots//./}"
# Script version check.
if [[ "${script_online_version::3}" -gt "${script_local_version::3}" ]]; then
header_red
echo -e "${WHITE_R}#${RESET} You're currently running script version ${script_local_version_dots} while ${script_online_version_dots} is the latest!"
echo -e "${WHITE_R}#${RESET} Downloading and executing version ${script_online_version_dots} of the Easy Installation Script..\\n\\n"
sleep 3
rm --force "${script_location}" 2> /dev/null
rm --force "unifi-${version}.sh" 2> /dev/null
# shellcheck disable=SC2068
wget -q "${wget_progress[@]}" "https://get.glennr.nl/unifi/install/unifi-${version}.sh" && bash "unifi-${version}.sh" ${script_options[@]}; exit 0
fi
else
curl_missing=true
fi
}
script_version_check
armhf_recommendation() {
print_architecture=$(dpkg --print-architecture)
if [[ "${print_architecture}" == 'armhf' && "${is_cloudkey}" == "false" ]]; then
header_red
echo -e "${WHITE_R}#${RESET} Your installation might fail, please consider getting a Cloud Key Gen2 or go with a VPS at OVH/DO/AWS."
if [[ "${os_codename}" =~ (precise|trusty|xenial|bionic|cosmic|disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
echo -e "${WHITE_R}#${RESET} You could try using Debian Stretch before going with a UCK G2 ( PLUS ) or VPS"
fi
echo -e "\\n${WHITE_R}#${RESET} UniFi Cloud Key Gen2 | https://store.ui.com/products/unifi-cloud-key-gen2"
echo -e "${WHITE_R}#${RESET} UniFi Cloud Key Gen2 Plus | https://store.ui.com/products/unifi-cloudkey-gen2-plus\\n\\n"
sleep 20
fi
}
armhf_recommendation
custom_url_question() {
header
echo -e "${WHITE_R}#${RESET} Please enter the application download URL below."
read -rp $'\033[39m#\033[0m ' custom_download_url
custom_url_download_check
}
custom_url_upgrade_check() {
echo -e "\\n${WHITE_R}----${RESET}\\n"
echo -e "${YELLOW}#${RESET} The script will now install application version: ${unifi_clean}!" && sleep 3
custom_url_check=success
}
custom_url_download_check() {
mkdir -p /tmp/EUS/downloads &> /dev/null
unifi_temp="$(mktemp --tmpdir=/tmp/EUS/downloads unifi_sysvinit_all_XXXXX.deb)"
header
echo -e "${WHITE_R}#${RESET} Downloading the application release..."
echo -e "\\n------- $(date +%F-%R) -------\\n" &>> "${eus_dir}/logs/unifi_custom_url_download.log"
if ! wget -O "$unifi_temp" "${custom_download_url}" &>> "${eus_dir}/logs/unifi_custom_url_download.log"; then
header_red
echo -e "${WHITE_R}#${RESET} The URL you provided cannot be downloaded.. Please provide a working URL."
sleep 3
custom_url_question
else
dpkg -I "${unifi_temp}" | awk '{print tolower($0)}' &> "${unifi_temp}.tmp"
package_maintainer=$(awk '/maintainer/{print$2}' "${unifi_temp}.tmp")
unifi_clean=$(awk '/version/{print$2}' "${unifi_temp}.tmp" | grep -io "5.*\\|6.*\\|7.*\\|8.*" | cut -d'-' -f1 | cut -d'/' -f1)
rm --force "${unifi_temp}.tmp" &> /dev/null
if [[ "${package_maintainer}" =~ (unifi|ubiquiti) ]]; then
echo -e "${GREEN}#${RESET} Successfully downloaded the application release!"
sleep 2
custom_url_upgrade_check
else
header_red
echo -e "${WHITE_R}#${RESET} You did not provide a UniFi Network Application that is maintained by Ubiquiti ( UniFi )..."
read -rp $'\033[39m#\033[0m Do you want to provide the script with another URL? (Y/n) ' yes_no
case "$yes_no" in
[Yy]*|"") custom_url_question;;
[Nn]*) ;;
esac
fi
fi
}
if [[ "${script_option_custom_url}" == 'true' ]]; then if [[ "${custom_url_down_provided}" == 'true' ]]; then custom_url_download_check; else custom_url_question; fi; fi
###################################################################################################################################################################################################
# #
# Required Packages #
# #
###################################################################################################################################################################################################
# Install needed packages if not installed
install_required_packages() {
sleep 2
installing_required_package=yes
header
echo -e "${WHITE_R}#${RESET} Installing required packages for the script..\\n"
hide_apt_update=true
run_apt_get_update
sleep 2
}
apt_get_install_package() {
if [[ "${old_openjdk_version}" == 'true' ]]; then
apt_get_install_package_variable="update"
apt_get_install_package_variable_2="updated"
else
apt_get_install_package_variable="install"
apt_get_install_package_variable_2="installed"
fi
hide_apt_update=true
run_apt_get_update
echo -e "\\n------- ${required_package} installation ------- $(date +%F-%R) -------\\n" &>> "${eus_dir}/logs/apt.log"
echo -e "${WHITE_R}#${RESET} Trying to ${apt_get_install_package_variable} ${required_package}..."
if DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install "${required_package}" &>> "${eus_dir}/logs/apt.log"; then echo -e "${GREEN}#${RESET} Successfully ${apt_get_install_package_variable_2} ${required_package}! \\n" && sleep 2; else echo -e "${RED}#${RESET} Failed to ${apt_get_install_package_variable} ${required_package}! \\n"; abort; fi
unset required_package
}
if ! dpkg -l sudo 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then install_required_packages; fi
echo -e "${WHITE_R}#${RESET} Installing sudo..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install sudo &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install sudo in the first run...\\n"
if [[ "${repo_codename}" =~ (precise|trusty|xenial) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu/ ${repo_codename}-security main") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu/ ${repo_codename}-security main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (bionic|cosmic|disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (stretch|jessie|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
fi
required_package="sudo"
apt_get_install_package
else
echo -e "${GREEN}#${RESET} Successfully installed sudo! \\n" && sleep 2
fi
fi
if ! dpkg -l lsb-release 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then install_required_packages; fi
echo -e "${WHITE_R}#${RESET} Installing lsb-release..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install lsb-release &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install lsb-release in the first run...\\n"
if [[ "${repo_codename}" =~ (precise|trusty|xenial|bionic|cosmic|disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu/ ${repo_codename} main universe") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu/ ${repo_codename} main universe" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (jessie|stretch|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
fi
required_package="lsb-release"
apt_get_install_package
else
echo -e "${GREEN}#${RESET} Successfully installed lsb-release! \\n" && sleep 2
fi
fi
if ! dpkg -l net-tools 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then install_required_packages; fi
echo -e "${WHITE_R}#${RESET} Installing net-tools..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install net-tools &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install net-tools in the first run...\\n"
if [[ "${repo_codename}" =~ (precise|trusty|xenial|bionic|cosmic|disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (jessie|stretch|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
fi
required_package="net-tools"
apt_get_install_package
else
echo -e "${GREEN}#${RESET} Successfully installed net-tools! \\n" && sleep 2
fi
fi
if ! dpkg -l apt-transport-https 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then install_required_packages; fi
echo -e "${WHITE_R}#${RESET} Installing apt-transport-https..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install apt-transport-https &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install apt-transport-https in the first run...\\n"
if [[ "${repo_codename}" =~ (precise|trusty|xenial) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://security.ubuntu.com/ubuntu ${repo_codename}-security main") -eq 0 ]]; then
echo -e "deb http://security.ubuntu.com/ubuntu ${repo_codename}-security main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (bionic|cosmic) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://security.ubuntu.com/ubuntu ${repo_codename}-security main universe") -eq 0 ]]; then
echo -e "deb http://security.ubuntu.com/ubuntu ${repo_codename}-security main universe" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu ${repo_codename} main universe") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu ${repo_codename} main universe" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" == "jessie" ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://security.debian.org/debian-security ${repo_codename}/updates main") -eq 0 ]]; then
echo -e "deb http://security.debian.org/debian-security ${repo_codename}/updates main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (stretch|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
fi
required_package="apt-transport-https"
apt_get_install_package
else
echo -e "${GREEN}#${RESET} Successfully installed apt-transport-https! \\n" && sleep 2
fi
fi
if ! dpkg -l software-properties-common 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then install_required_packages; fi
echo -e "${WHITE_R}#${RESET} Installing software-properties-common..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install software-properties-common &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install software-properties-common in the first run...\\n"
if [[ "${repo_codename}" == "precise" ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://security.ubuntu.com/ubuntu ${repo_codename}-security main") -eq 0 ]]; then
echo -e "deb http://security.ubuntu.com/ubuntu ${repo_codename}-security main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (trusty|xenial|bionic|cosmic|disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (jessie|stretch|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
fi
required_package="software-properties-common"
apt_get_install_package
else
echo -e "${GREEN}#${RESET} Successfully installed software-properties-common! \\n" && sleep 2
fi
fi
if ! dpkg -l curl 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then install_required_packages; fi
echo -e "${WHITE_R}#${RESET} Installing curl..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install curl &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install curl in the first run...\\n"
if [[ "${repo_codename}" =~ (precise|trusty|xenial|bionic|cosmic) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://security.ubuntu.com/ubuntu ${repo_codename}-security main") -eq 0 ]]; then
echo -e "deb http://security.ubuntu.com/ubuntu ${repo_codename}-security main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" == "jessie" ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://security.debian.org/debian-security ${repo_codename}/updates main") -eq 0 ]]; then
echo -e "deb http://security.debian.org/debian-security ${repo_codename}/updates main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (stretch|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
fi
required_package="curl"
apt_get_install_package
else
echo -e "${GREEN}#${RESET} Successfully installed curl! \\n" && sleep 2
fi
fi
if ! dpkg -l dirmngr 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then install_required_packages; fi
echo -e "${WHITE_R}#${RESET} Installing dirmngr..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install dirmngr &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install dirmngr in the first run...\\n"
if [[ "${repo_codename}" =~ (precise|trusty|xenial|bionic|cosmic|disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu/ ${repo_codename} universe") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu/ ${repo_codename} universe" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu/ ${repo_codename} main restricted") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu/ ${repo_codename} main restricted" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (jessie|stretch|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
fi
required_package="dirmngr"
apt_get_install_package
else
echo -e "${GREEN}#${RESET} Successfully installed dirmngr! \\n" && sleep 2
fi
fi
if ! dpkg -l wget 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then install_required_packages; fi
echo -e "${WHITE_R}#${RESET} Installing wget..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install wget &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install wget in the first run...\\n"
if [[ "${repo_codename}" =~ (precise|trusty|xenial|bionic|cosmic) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://security.ubuntu.com/ubuntu ${repo_codename}-security main") -eq 0 ]]; then
echo -e "deb http://security.ubuntu.com/ubuntu ${repo_codename}-security main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" == "jessie" ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://security.debian.org/debian-security ${repo_codename}/updates main") -eq 0 ]]; then
echo -e "deb http://security.debian.org/debian-security ${repo_codename}/updates main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (stretch|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
fi
required_package="wget"
apt_get_install_package
else
echo -e "${GREEN}#${RESET} Successfully installed wget! \\n" && sleep 2
fi
fi
if ! dpkg -l netcat netcat-traditional 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then install_required_packages; fi
echo -e "${WHITE_R}#${RESET} Installing netcat..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install netcat &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install netcat in the first run...\\n"
if [[ "${repo_codename}" =~ (precise|trusty|xenial|bionic|cosmic|disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu/ ${repo_codename} universe") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu/ ${repo_codename} universe" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (jessie|stretch|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
fi
if apt-cache search netcat | grep "^netcat\b" | awk '{print$1}' | grep -iq "traditional"; then
required_package="netcat-traditional"
else
required_package="netcat"
fi
apt_get_install_package
else
echo -e "${GREEN}#${RESET} Successfully installed netcat! \\n" && sleep 2
fi
netcat_installed=true
fi
if [[ "${unifi_core_system}" != 'true' && "${script_option_skip_install_haveged}" != 'true' ]]; then
if ! dpkg -l haveged 2> /dev/null | awk '{print $1}' | grep -iq "^ii\\|^hi"; then
if [[ "${installing_required_package}" != 'yes' ]]; then
install_required_packages
fi
echo -e "${WHITE_R}#${RESET} Installing haveged..."
if ! DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install haveged &>> "${eus_dir}/logs/required.log"; then
echo -e "${RED}#${RESET} Failed to install haveged in the first run...\\n"
if [[ "${repo_codename}" =~ (precise|trusty|xenial|bionic|cosmic|disco|eoan|focal|groovy|hirsute|impish|jammy) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://[A-Za-z0-9]*.archive.ubuntu.com/ubuntu/ ${repo_codename} universe") -eq 0 ]]; then
echo -e "deb http://nl.archive.ubuntu.com/ubuntu/ ${repo_codename} universe" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi
elif [[ "${repo_codename}" =~ (jessie|stretch|buster|bullseye|bookworm) ]]; then
if [[ $(find /etc/apt/ -name "*.list" -type f -print0 | xargs -0 cat | grep -c "^deb http[s]*://ftp.[A-Za-z0-9]*.debian.org/debian ${repo_codename} main") -eq 0 ]]; then
echo -e "deb http://ftp.nl.debian.org/debian ${repo_codename} main" >>/etc/apt/sources.list.d/glennr-install-script.list || abort
fi