-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmaxinet
More file actions
18185 lines (16641 loc) · 918 KB
/
maxinet
File metadata and controls
18185 lines (16641 loc) · 918 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
# =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~="
# Author: Arafat Ali | Email: webmaster@sofibox.com | Website: sofibox.com
# local OS fully tested: ubuntu | local OS partially tested: debian,
# remote OS fully tested: debian 11 | remote OS partially tested: Almalinux
_APP_SPECIFIC_NAME="Maxinet"
# Note that some minor versions are not published
_APP_VERSION="1.8.2"
_APP_STATUS="alpha"
_APP_VERSION_STATUS="${_APP_VERSION}-${_APP_STATUS}"
### START TEMPORARY NOTE
# TODO configure cloudflare IP in CSF
# TODO note for new domain of users to have custom .html edit this :/home/reseller_username/domains/default/index.html
# TODO switch to sftp using proftpd (working fine using this tutorial https://forum.directadmin.com/threads/how-to-set-up-your-proftpd-ftp-server-to-support-the-secure-protocols-while-disabling-insecure-ftp.65025/ and make sure to use port 23 as mentioned in doc)
# TODO check log for proftpd
# TODO trigger admin backup from directadmin automatically before deploy a new server (also create validation if the file restoration success first). So we will always have working restoration file.
### END TEMPORARY NOTE
# This is a personal project that I wrote for server automation to reduce server configuration time.
# The aim of this project is to have everything automated when deploying a new server without wasting a lot of time.
# For example setting up a secured server from scratch with hardened configs might take few days (I've experienced this) but this script will reduce that longer period to about 1 hour with one command!
# I focused a lot of security enhancements in this script for a new server deployment in order to reduce server malicious attack.
# Warning, you should not use this script if you dont know the purpose of this script. This script might contain bug (especially this public version)
# There is another private version without _public name URL that always have the latest code and features.
# Running example:
# maxinet create-server --rebuild-all --backup
# For example if everything is configured correctly for Directadmin and Linode in maxinet.conf,
# the above command will configure a new server disk and config in linode, it will then create custom ISO file for Debian, then it will install this operating system.
# then do a lot of thing behind ... bla2 bla2 ... (read the code to understand what it does because it is huge to write what it does) ... and finally you will get a fully working server with live websites. So, with only a single command, you will get a clean server with security hardened features
# The feature is currently huge to list out.
# It might contain bugs for other distributions. This script is fully tested on Debian 10, Debian 11 and with Directadmin custom and auto installation. This script compatible with linode + directadmin
# Author: Arafat Ali | Email: arafat@sofibox.com | Personal Blog: arafatx.com
# See maxinet --help for more information
# To update remote files from local run this: maxinet update-remote-scripts
# To login into remote: maxinet login
#######################
# FUNCTION BEGIN HERE #
#######################
# This function is used to handle exit trap that can accept multiple trap arguments
# syntax: traps <traps_cleanup_function> SIG1 SIG2 SIG3 ... SIGN[N]
# eg: traps exit_function QUIT INT TERM EXIT
traps() {
local clean_function
clean_function="$1"
shift
for sig; do
trap "${clean_function} ${sig}" "${sig}"
done
}
# This function is used by traps() function to clean exit
script_exit() {
# The first argument will have the name of the trap signal executed:
# eg: echo "Trapped: $1"
# This variable hold the count of key press of CTRL+C
((CTRL_C_COUNT++))
# Check if the locking directory is exist, if yes, remove it
if [ -d "${LOCK_DIR}" ]; then
rm -rf "${LOCK_DIR}"
#echo ""
#echo "OK, locked flag removed from ${LOCK_DIR}"
fi
# this if condition will determine that this cleanup function is only called a single time CTRL_C_COUNT=1
# this function might be called several times because we passed long arguments for trap to call this function
if [[ ${CTRL_C_COUNT} == 1 ]]; then
local signal
signal="$1"
echo ""
# if the trapped signal is INT (or interactive) then we know this is interactive exit executed by a user.
if [ "${signal}" == "INT" ]; then
# so print the current user who terminated this script
msg "$(s yellow)*** Warning, this script has been terminated by user: $(s red)${USER}!$(e) $(s yellow)***$(e)" --caller="${SCRIPT_NAME}"
# Check if trap with other signal here
#elif [ "${signal}" == "OTHER_SIGNAL" ]; then
:
else
# for other trap signals that we don't care, we just print out the trap signal type
msg "$(s cyan)This script has been terminated with signal:$(e) $(s red)${signal}$(e)" --caller="${SCRIPT_NAME}"
fi
echo ""
echo "-------------------------------END-----------------------------------------"
echo ""
echo "Remember you can always resume installation with the following command:"
echo "For local installation: ${SCRIPT_NAME} setup 2>&1 | tee ${SCRIPT_NAME}.log"
echo "For remote installation: ${SCRIPT_NAME} --push-ssh-script --sp ${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT} --gu root:${C_ROOT_USERNAME} --push-maxinet-setup-script"
echo ""
echo "SSH user login guide:"
echo "To login as root user: ${SCRIPT_NAME} ssh-login ${C_ROOT_USERNAME} or ${SCRIPT_NAME} login"
echo "To login as SSH user: ${SCRIPT_NAME} ssh-login ${C_SSH_USERNAME}"
echo ""
echo "Server LUKS unlock guide:"
echo "To unlock LUKS Disk encryption: ${SCRIPT_NAME} --luks-unlock"
echo ""
script_time
echo ""
fi
# clean exit
exit 1
}
get_listening_port() {
local port
port="$1"
netstat -na | grep "${port}"
}
generate_unused_port() {
local port
read -r lowerport upperport </proc/sys/net/ipv4/ip_local_port_range
while :; do
port="$(shuf -i "${lowerport}-${upperport}" -n 1)"
ss -lpn | grep -q ":${port} " || break
done
echo "${port}"
}
# Directadmin debug exit trap
da_debug_exit() {
# echo "Trapped: $1"
((CTRL_C_COUNT++))
if [[ $CTRL_C_COUNT == 1 ]]; then
local signal
signal="$1"
echo ""
if [ "${signal}" == "INT" ]; then
echo "*** Warning, Directadmin debug mode has been terminated by ${USER}! ***"
fi
echo "Starting directadmin in normal mode ..."
systemctl restart directadmin
echo "Directadmin running status is: $(systemctl is-active directadmin)"
echo ""
echo " **END DEBUG** "
echo "=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~"
fi
# clean exit
exit 1
}
# This function will read current status of the last script passed to the first argument whether it is return 0 or not
# If it returns 0, display [ OK ] else display [ FAILED ] and exit
get_status_message() {
local retval
retval="$1"
if [[ "${retval}" -eq 0 ]]; then
echo " [ OK ]"
else
echo " [ FAILED ]"
exit 1
fi
}
get_ordinal() {
local integer
integer="$1"
case "${integer}" in
*1[0-9] | *[04-9]) echo "${integer}"th ;;
*1) echo "${integer}"st ;;
*2) echo "${integer}"nd ;;
*3) echo "${integer}"rd ;;
esac
}
# This function will pause the current running terminal
# It will interactively ask to press enter or wait within <duration_in_seconds> to continue the next command
# syntax: _pause <optional_duration>
# eg: _pause | no timeout means we need to press enter to continue
# eg: _pause 10 | wait 10 seconds or press enter to continue
_pause() {
echo ""
local duration=$1
# If argument is not an integer, we disable read timeout
# TODO validate this statement again
if [[ ${duration} =~ ^[0-9]+$ ]]; then
read -t "${duration}" -r -s -n 1 -p "[${SCRIPT_NAME}]: Press any key or wait within ${duration} second(s) to continue or press (Ctrl+c) to cancel ..."
else
read -r -s -n 1 -p "[${SCRIPT_NAME}]: Terminal is paused! Press any key to continue or press (Ctrl+c) to cancel ..."
fi
echo ""
}
# This function will display a confirmation to continue (force continue; no exit function)
_confirm() {
# call with a prompt string or use a default
read -r -p "[${SCRIPT_NAME}->${FUNCNAME[0]}->input]: ${1:-Continue? [y] Exit? [CTRL+C]} " response
case "$response" in
[yY][eE][sS] | [yY])
return 0
;;
*)
msg "Error, invalid response to the question!" --msg-type=error --caller="${SCRIPT_NAME}->${FUNCNAME[0]}->invalid"
_confirm "$1"
;;
esac
}
# This function is used to ask the next action.
# Usage: _ask [message] [default-response]
# Example: _ask "Do you want to continue?" "y"
_ask() {
local text default_response
text=$1
default_response=$2
if [ -z "${default_response}" ]; then
default_response="Y"
fi
read -r -p "[${SCRIPT_NAME}->${FUNCNAME[0]}->input]: ${text} [default:${default_response}] [Y/n]: " response
# Simulate a default response so that we can press Enter key
if [[ -z "${response}" ]]; then
response="${default_response}"
fi
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
return 0
else
msg "Operating aborted" --msg-type=info --caller="${SCRIPT_NAME}->${FUNCNAME[0]}->cancel"
exit 0
fi
}
# This function is used to terminate a current running script.
# pass the normal exit code
# syntax: _exit <exit_code>
# eg: _exit 3
_exit() {
exit "$1"
}
# This function is used to reboot the system using force reboot -r now without any arguments
# syntax _reboot
_reboot() {
# an exit ASCII symbol invented by MaXi32
msg "Rebooting system ..."
echo "--<]--"
shutdown -r now
}
# This function is used to shutdown the system using force shutdown -h now without any arguments
# syntax _shutdown
_shutdown() {
# a shutdown ASCII symbol invented by MaXi32
msg "Shutting down system ..."
echo "--[]--"
shutdown -h now
}
# decode URL, use with echo -n "string" | urldecode or printf %s "string" | urldecode
urldecode() {
printf '%b\n' "$(sed 's/+/ /g;s/%\(..\)/\\x\1/g;')"
}
# encode URL, use with echo -n "string" | urlencode or printf %s "string" | urlencode
urlencode() {
maxibuild --include "jq"
printf '%b\n' "$(jq -sRr @uri)"
}
# This function will print all text as multiple row separated by separator symbol. Usage example:
# echo "Test=19-&Hello=2+" | awksep '&'
# output:
# Test=19-
# Hello=2+
awksep() {
local separator="$1"
printf '%b\n' "$(awk -F"${separator}" '{for(i=1;i<=NF;++i)print $i }')"
}
# This function set_linux_crlf will automatically remove CRLF character in file to make sure file is compatible with linux
# It does not return error if the file is already in unix format before
set_linux_crlf() {
local files retval
files="$1"
maxibuild --include "dos2unix"
for file in ${files}; do
echo "Checking and converting file [ ${file} ] into unix compatible file ..."
dos2unix <"${file}" | cmp - "${file}" 2>&1
retval=$?
if [ "${retval}" -ne 0 ]; then
dos2unix "${file}"
fi
echo ""
done
}
script_header() {
# This is script header
msg "$(s red)=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=$(e)"
msg "$(s cyan)Welcome to $(s red)${_APP_SPECIFIC_NAME}$(s cyan) Automated Script on (${C_HOST_TYPE})$(e)"
msg "$(s blue)This powerful script is part of Sofibox/MaxiNet scripts$(e)"
msg "$(s green)For script help: $(s yellow)${SCRIPT_NAME} --help$(e)"
msg "$(s green)Script official URL: $(s yellow)http://sofibox.com/maxinet$(e)"
msg "$(s green)Version: $(s yellow)${SCRIPT_NAME}-${_APP_VERSION_STATUS}$(e)"
msg "$(s green)Distro ID: $(s yellow)${DISTRO_ID}$(e) | $(s green) Distro Version: $(s yellow)${DISTRO_VERSION}$(e)"
msg "$(s green)Hostname: $(s magenta)$(hostname)$(e) | $(s green) Public IP: $(s magenta)${C_HOST_PUBLIC_IP}$(e)"
msg "$(s cyan)$(s bold)(C) Author: Arafat Ali | Email: arafat@sofibox.com$(e)"
msg "$(s red)=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=$(e)"
msg "$(s yellow)Running date and time: ${DATE_TIME_NOW}$(e)" --caller="${SCRIPT_NAME}"
msg ""
}
help() {
# This help section is deprecated, will update time to time when the code finish
echo ""
echo "Welcome to help section!"
echo "------------------------"
echo ""
echo "To deploy a new server automatically with log output: "
echo "==============="
echo "${SCRIPT_NAME} create-server --rebuild-all 2>&1 | tee ${SCRIPT_NAME}.log"
echo "OR with ISO backup"
echo "${SCRIPT_NAME} create-server --rebuild-all --backup 2>&1 | tee ${SCRIPT_NAME}.log"
echo "Note: These arguments are optional for installation log that can be omitted -> 2>&1 | tee ${SCRIPT_NAME}.log"
echo "==============="
echo ""
echo "To start/resume local installation: "
echo "==============="
echo "${SCRIPT_NAME} setup 2>&1 | tee ${SCRIPT_NAME}.log"
echo "==============="
echo ""
echo "To start/resume remote installation:"
echo "==============="
echo "Syntax: ${SCRIPT_NAME} ssh-login <fqdn>:<ssh_port> <user_role>:<user_name> <local_script_to_push_for_installation>"
echo "${SCRIPT_NAME} ssh-login \"${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}\" \"root:${C_ROOT_USERNAME}\" \"${CODE_PATH}/ssh_scripts/maxinet_setup.sh\""
echo "==============="
echo ""
echo "To unlock LUKS Disk encryption without login into terminal:"
echo "==============="
echo "Syntax: ${SCRIPT_NAME} --ssh-luks-unlock <DROP_BEAR_PORT> \"<LUKS_PASS>\""
echo "eg:"
echo "${SCRIPT_NAME} --ssh-luks-unlock ${C_DROP_BEAR_PORT} \"${C_LUKS_PASS}\""
echo "==============="
echo ""
echo "To login server as a root user:"
echo "==============="
echo "${SCRIPT_NAME} ssh-login \"${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}\" \"user:root\" OR maxinet login"
echo "Note: this will automatically unlock LUKS disk"
echo "==============="
echo ""
echo "To login as an SSH user:"
echo "==============="
echo "${SCRIPT_NAME} ssh-login \"${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}\" \"root:${C_SSH_USERNAME}\""
echo "Note: this will automatically unlock LUKS disk"
echo "==============="
echo ""
echo "There are a lot more, this section is developing ..."
}
manual() {
# This help section is deprecated, will update time to time when the code finish
local manual_name="$1"
if [ "${manual_name}" == "init_server" ]; then
local lopt="--init-server"
echo "----------------------------------------------"
echo "Help section for ${SCRIPT_NAME}/${manual_name}"
echo "----------------------------------------------"
echo "CALL METHOD"
echo ""
echo "FOR EXTERNAL CALL: ${SCRIPT_NAME} ${lopt} --help"
echo "FOR INTERNAL CALL: ${manual_name} --help"
echo ""
echo "SYNTAX 1: "
echo ""
echo "${SCRIPT_NAME} ${lopt} *<long-option1> +<long-option2> ... +<long-optionN>"
echo ""
echo "EXAMPLE SYNTAX 1: "
echo ""
echo "${SCRIPT_NAME} ${lopt} --rebuild-iso --backup-ssh-key --backup-iso"
echo "EXAMPLE SYNTAX 2: "
echo ""
echo "${SCRIPT_NAME} ${lopt} --rebuild-all --backup-all"
echo ""
echo "DESCRIPTION"
echo ""
echo "1) <LONG OPTIONS>"
echo "--rebuild-iso - rebuild server OS ISO image from scratch"
echo "--rebuild-partition - rebuild server disk partition from scratch"
echo "--rebuild-config - rebuild server config from scratch"
echo "--rebuild-all - rebuild everything from the above"
echo "--backup-ssh-key - backup server previous ssh key file (both private and public keys)"
echo "--backup-iso - backup server previous OS ISO image file"
echo "--backup-all - backup everything from the above"
echo ""
echo "NOTE 1:"
echo ""
echo "${SCRIPT_NAME} --init-server --rebuild-iso --rebuild-partition --rebuild-config"
echo "is equivalent to"
echo "${SCRIPT_NAME} --rebuild-all"
echo ""
echo "NOTE 2:"
echo ""
echo "${SCRIPT_NAME} --init-server --backup-ssh-key --backup-iso"
echo "is equivalent to"
echo "${SCRIPT_NAME} --backup-all"
echo ""
echo "NOTE 3:"
echo ""
echo "Can only accept long options that begins with 2 dashes --. eg: --rebuild-iso"
echo ""
fi
}
# Create dynamic variable
# variable_api <required action> <required VARIABLE --name> <optional --value>
# variable_api create-variable --name myvariable --value hello | this creates variable name with value hello
# variable_api create-variable --name testvariable | this creates a variable name testvariable without value
# variable_api get-variable-value --name testvariable | this will display the variable testvariable value
variable_api() {
local action argnum options retval name value
action="$1"
argnum="$#"
if [ ${argnum} -eq 0 ]; then
echo "Error, no argument is supplied. Use [ ${SCRIPT_NAME} --create-var --help ] to see the valid options"
exit 1
fi
short_opts=""
long_opts="help,name:,value:"
options=$(getopt -o "${short_opts}" --long "${long_opts}" -n "${FUNCNAME[0]} in ${SCRIPT_NAME}" -- "$@")
retval=$?
if [ "${retval}" != 0 ]; then
echo "Error, invalid parse data. Terminating..."
exit 1
fi
# Must quote this option variable
eval set -- "${options}"
name=""
value=""
while true; do
case "$1" in
--help)
manual "${FUNCNAME[0]}"
shift
exit 0
;;
--name)
name="$2"
shift 2
;;
--value)
value="$2"
shift 2
;;
--)
shift
break
;;
*)
break
;;
esac
done
if [ "${action}" == "create-variable" ]; then
if [ -z "${name}" ]; then
echo "Error, the option --name is required!"
_exit 1
fi
# Put option -g for global variable
if [ -n "${value}" ]; then
declare -g "VAR_${name}=${value}"
else
declare -g "VAR_${name}"
fi
elif [ "${action}" == "get-variable-value" ]; then
local dv
if [ -z "${name}" ]; then
echo "Error, the option --name is required!"
_exit 1
fi
dv="VAR_${name}"
echo "${!dv}"
else
echo "Error, invalid action for variable_api!"
exit 147
fi
}
# This function validate all data argument. Eg: check if the domain name provided is FQDN or valid
# is_valid server_record_type <data>
is_valid() {
local type data1 data2 retval distro_id
type="$1"
data1="$2"
data2="$3"
distro_id="${DISTRO_ID}"
maxibuild --include "iproute2"
# is_valid version_required <required_version> <current_version>
if [[ "${type}" == "version_required" || "${type}" == "version_needed" ]]; then
local current_version required_version
required_version="${data1}"
current_version="${data2}"
if [ "$(printf '%s\n' "${required_version}" "${current_version}" | sort -V | head -n1)" = "${required_version}" ]; then
return 0
else
return 1
fi
# is_valid ipv4-resolved 1.1.1.1 sun.server.com
# is_valid ipv4_resolved
elif [[ "${type}" == "ipv4-resolved" || "${type}" == "ipv4_resolved" ]]; then
maxibuild --include "dnsutils"
local ipv4 ipv4_propagated domain
ipv4="${data1}"
domain="${data2}"
if [ -z "${domain}" ]; then
domain="${C_BOX_HOSTNAME_FQHN}"
fi
ipv4_propagated=$(dig "${domain}" A +short)
if [ "${ipv4_propagated}" = "${ipv4}" ]; then
return 0
else
return 1
fi
# is_valid ipv6-resolved 1.1.1.1 sun.server.com
# is_valid ipv6_resolved
elif [[ "${type}" == "ipv6-resolved" || "${type}" == "ipv6_resolved" ]]; then
maxibuild --include "dnsutils"
local ipv6 ipv6_propagated domain
ipv6="${data1}"
domain="${data2}"
if [ -z "${domain}" ]; then
domain="${C_BOX_HOSTNAME_FQHN}"
fi
ipv6_propagated=$(dig ${domain} AAAA +short)
if [ "${ipv6_propagated}" == "${ipv6}" ]; then
return 0
else
return 1
fi
# subnet regex matching between 1-256
elif [[ "${type}" == "ipv6_prefix" || "${type}" == "ipv6_subnet" ]]; then
local ipv6_prefix ipv6_prefix_pattern
ipv6_prefix="${data1}"
ipv6_prefix_pattern='^(\/)\b(1?[1-9]{1,2}|2[0-4][0-9]|25[0-5])\b'
if [[ ${ipv6_prefix} =~ ${ipv6_prefix_pattern} ]]; then
return 0
else
return 1
fi
# subnet regex matching between 1-31
elif [[ "${type}" == "ipv4_prefix" || "${type}" == "ipv4_subnet" ]]; then
local ipv4_prefix ipv4_prefix_pattern
ipv4_prefix="${data1}"
ipv4_prefix_pattern='^(\/)\b([1-9]|[1-2][0-9]|3[0-1])\b'
if [[ ${ipv4_prefix} =~ ${ipv4_prefix_pattern} ]]; then
return 0
else
return 1
fi
#if is_valid ssl_site "${C_BOX_HOSTNAME_FQHN}:${C_DA_PORT}"; then
elif [[ "${type}" == "ssl_site" ]]; then
local url final_hostname status
url="${data1}"
# echo "url: ${url}
host "${url}" >/dev/null 2>&1
retval=$?
if [ "${retval}" -eq 0 ]; then
#echo "Link is valid"
# Use timeout 3 instead of the built-in function because the built in function --max-wait does not work
# This will get the final redirection for a hostname
final_hostname=$(timeout 3 curl "${url}" -s -L -I -o /dev/null -w '%{url_effective}' | awk -F[/:] '{print $4}')
#echo "URL: ${url}"
#echo "FINAL_HOSTNAME: ${final_hostname}"
#echo "PORT: ${port}"
status=$(curl --cert-status -v "https://${final_hostname}" 2>&1 | awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } /^\*/ { if (cert) print }' | grep "\* SSL certificate verify ok.")
#status=$(timeout 3 openssl s_client -connect "${final_hostname}:${port}" </dev/null 2>/dev/null | grep 'Verify return code: 0 (ok)')
if [ -n "${status}" ]; then
#echo "Site ${final_hostname} with port ${port} is valid https"
return 0
else
return 1
#echo "Site ${final_hostname} with port ${port} is not valid https"
fi
else
#echo "Link is not valid"
return 1
fi
# is_valid available_port <server> <port>
# This function will check if defined server and port is available (in a listening state)
# Usage: available_port <server> <port>
# eg: available_port test.sofibox.com 22
# It will return 0 (if available), and other return codes (if listening state for the port is not available)
elif [[ "${type}" == "available_port" ]]; then
local server port retval
server="${data1}"
port="${data2}"
nc -z -v -w5 "${server}" "${port}" 2>/dev/null
retval=$?
return ${retval}
elif [[ "${type}" == "integer" ]]; then
if [[ ${data1} =~ [0-9] ]]; then
return 0
else
return 1
fi
elif [[ "${type}" == "domain" ]]; then
if grep -oP '(?=^.{4,253}$)(^(?:[a-zA-Z0-9](?:(?:[a-zA-Z0-9\-]){0,61}[a-zA-Z0-9])?\.)+([a-zA-Z]{2,}|xn--[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])$)' <<<"${data1}" >/dev/null 2>&1; then
#if grep -oP '^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$' <<< "$1" >/dev/null 2>&1;then
return 0
# do another check using host if regex above detected as false and return either true or false
else
host "${data1}" >/dev/null 2>&1
retval=$?
return "${retval}"
fi
elif [[ "${type}" == "domain_type" ]]; then
# Convert to capital with ^^ and compare with capital letters
if [[ "${data1^^}" == +(MASTER|SLAVE) ]]; then
return 0
else
return 1
fi
# For linode case ttl
# record_ttl="300" # 300(5m), 3600(1h), 7200(2h), 14400(4h), 28800(8h), 57600(16h), 0/86400(1d)-Default, 172800(2d), 345600(4d), 691200(8d), 604800(1w), 1209600(2w), 2419200(4w).
elif [[ "${type}" == "domain_ttl" ]]; then
if [[ ${data1} -ge 30 && ${data1} -le 2419200 && ${data1} =~ ^[0-9]+$ ]]; then
return 0
else
return 1
fi
elif [[ "${type}" == "record_ttl" ]]; then
if [[ ${data1} -ge 30 && ${data1} -le 2419200 && ${data1} =~ ^[0-9]+$ ]]; then
return 0
else
return 1
fi
elif [[ "${type}" == "record_type" ]]; then
# Convert to capital with ^^ and compare with capital letters
if [[ "${data1^^}" == +(NS|MX|A|AAAA|TXT|CNAME|SRV|CAA) ]]; then
return 0
else
return 1
fi
elif [[ "${type}" == "record_priority" ]]; then
if [[ ${data1} -ge 0 && ${data1} -le 255 && ${data1} =~ ^[0-9]+$ ]]; then
return 0
else
return 1
fi
elif [[ "${type}" == "email" ]]; then
if [[ "${data1}" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]]; then
return 0
else
return 1
fi
elif [[ "${type}" == "server_record_valid_character" ]]; then
if ! [[ ${data1} == *['!'@#\$%^\&*()+]* ]]; then
return 0
else
return 1
fi
#Check ipv4
elif [[ "${type}" == "ipv4" ]]; then
local ipv4="${data1}" ipv4_pattern='^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$'
if [[ "${ipv4}" =~ ${ipv4_pattern} ]]; then
retval=0
# Using this command will check IP is reachable ( do not use )
#if command -v ip &>/dev/null; then
#method_bin=$(command -v ip)
#"${method_bin}" route get "${ipv4}" >/dev/null 2>&1
#retval=$?
#else
# #msg "$(s yellow)Warning, unable to find suitable binary for checking ipv4 or ipv6 address. $(e)" --caller="${SCRIPT_NAME}"
# retval=1
#fi
else
retval=1
fi
return ${retval}
# Check ipv6
elif [[ "${type}" == "ipv6" ]]; then
local ipv6="${data1}" ipv6_pattern method_bin retval
ipv6_pattern='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$'
if [[ ${ipv6} =~ ${ipv6_pattern} ]]; then
retval=0
# Using this command will check IP is reachable ( do not use )
#if command -v ip &>/dev/null; then
# method_bin=$(command -v ip)
# "${method_bin}" route get "${ipv6}" >/dev/null 2>&1
# retval=$?
#else
# #msg "$(s yellow)Warning, unable to find suitable binary for checking ipv4 or ipv6 address. $(e)" --caller="${SCRIPT_NAME}"
# retval=1
#fi
else
retval=1
fi
return ${retval}
# Check both ipv4 and ipv6 (does not work if ip is not reachable)
elif [[ "${type}" == "ipv46" ]]; then
local ip="${data1}" method_bin retval
if command -v ip &>/dev/null; then
method_bin=$(command -v ip)
${method_bin} route get "${ip}" >/dev/null 2>&1
retval=$?
else
#msg "$(s yellow)Warning, unable to find suitable binary for checking ipv4 or ipv6 address. $(e)" --caller="${SCRIPT_NAME}"
retval=1
fi
return ${retval}
elif [[ "${type}" == "not-empty-string" ]]; then
if [ -n "${data1}" ]; then
return 0
else
return 1
fi
elif [[ "${type}" == "valid-linode-disk-filetype" ]]; then
if [[ "${data1^^}" == +(RAW|SWAP|EXT3|EXT4|INITRD) ]]; then
return 0
else
return 1
fi
# if is_valid sha256sum data1 data2; then
elif [[ "${type}" == "sha256sum" ]]; then
local retval
echo "${data1}" "${data2}" | sha256sum --check &>/dev/null
retval=$?
return ${retval}
fi
}
init_server_rebuild_config() {
local run_mode func_name
run_mode="$1"
extra_option="$2"
func_name="${FUNCNAME[0]}"
if [[ "${extra_option}" == "--silent-if-executed" ]]; then
start_execute_options "${run_mode}" "${func_name}" &>/dev/null
else
start_execute_options "${run_mode}" "${func_name}"
fi
[[ "${SKIP_RUN}" == "true" ]] && return 0
if [[ ! -f "${OS_TEMP_PATH}/${C_BOX_HOSTNAME_FQHN}_${func_name}_executed" && "${FUNCTION_RUN}" == "true" ]]; then
msg "Deleting all linode config profiles ..." --caller="${SCRIPT_NAME}"
maxipi linode delete-configs --for-linode-label "${C_BOX_HOSTNAME_FQHN}" --without-prompt
get_status_message "$?"
echo ""
# For installer
msg "Creating a linode config ${C_LINODE_BOOT_CONFIG_LABEL} ..." --caller="${SCRIPT_NAME}"
maxipi linode create-config --for-linode-label "${C_BOX_HOSTNAME_FQHN}" --config-label "${C_LINODE_BOOT_CONFIG_LABEL}" --config-comments "The installer boot configuration" \
--config-kernel "linode/direct-disk" --config-rootdev "/dev/sdb" --dev-sda "disk:${C_LINODE_OS_DISK_LABEL}" --dev-sdb "disk:${C_LINODE_BOOT_DISK_LABEL}"
get_status_message "$?"
echo ""
# For operating system boot
msg "Creating linode config ${C_LINODE_OS_CONFIG_LABEL} ..." --caller="${SCRIPT_NAME}"
maxipi linode create-config --for-linode-label "${C_BOX_HOSTNAME_FQHN}" --config-label "${C_LINODE_OS_CONFIG_LABEL}" --config-comments "The operating boot configuration" \
--config-kernel "linode/direct-disk" --config-rootdev "/dev/sda" --dev-sda "disk:${C_LINODE_OS_DISK_LABEL}"
get_status_message "$?"
echo ""
check_finish_reboot "${func_name}"
else
msg "$(s yellow)[Skipped by system]: $(s magenta)${func_name}$(e) $(s yellow)with current option ${run_mode} has ran before $(e)" --caller="${SCRIPT_NAME}"
msg "$(s yellow)=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=$(e)"
fi
if [[ "${extra_option}" == "--silent-if-executed" ]]; then
end_execute_options "${run_mode}" "${func_name}" &>/dev/null
else
end_execute_options "${run_mode}" "${func_name}"
fi
}
init_server_rebuild_partition() {
local run_mode func_name
run_mode="$1"
extra_option="$2"
func_name="${FUNCNAME[0]}"
if [[ "${extra_option}" == "--silent-if-executed" ]]; then
start_execute_options "${run_mode}" "${func_name}" &>/dev/null
else
start_execute_options "${run_mode}" "${func_name}"
fi
[[ "${SKIP_RUN}" == "true" ]] && return 0
if [[ ! -f "${OS_TEMP_PATH}/${C_BOX_HOSTNAME_FQHN}_${func_name}_executed" && "${FUNCTION_RUN}" == "true" ]]; then
((box_os_disk = server_main_disk_raw_size - server_boot_disk_raw_size))
server_main_disk_raw_size="${C_BOX_MAIN_DISK_RAW_SIZE}"
server_boot_disk_raw_size="${C_BOX_BOOT_DISK_RAW_SIZE}"
msg "Deleting all linode disks ..." --caller="${SCRIPT_NAME}"
maxipi linode delete-disks --for-linode-label "${C_BOX_HOSTNAME_FQHN}" --check-for-busy-status --without-prompt
retval=$?
if [ "${retval}" -ne 0 ]; then
msg "Skipped deleting all disks ..." --caller="${SCRIPT_NAME}" --msg-type="warning"
fi
echo ""
# Create Boot Disk that boot the operating system installer with raw format
msg "Creating linode boot disk for boot header ..." --caller="${SCRIPT_NAME}"
maxipi linode create-disk --for-linode-label "${C_BOX_HOSTNAME_FQHN}" --disk-label "${C_LINODE_BOOT_DISK_LABEL}" --disk-filetype "raw" --disk-size "${server_boot_disk_raw_size}" --check-for-busy-status --wait-until-disk-status ready
get_status_message "$?"
echo ""
msg "Creating linode OS disk for operating system installer ..." --caller="${SCRIPT_NAME}"
maxipi linode create-disk --for-linode-label "${C_BOX_HOSTNAME_FQHN}" --disk-label "${C_LINODE_OS_DISK_LABEL}" --disk-filetype "raw" --disk-size "${box_os_disk}" --check-for-busy-status --wait-until-disk-status ready
get_status_message "$?"
echo ""
check_finish_reboot "${func_name}"
else
msg "$(s yellow)[Skipped by system]: $(s magenta)${func_name}$(e) $(s yellow)with current option ${run_mode} has ran before $(e)" --caller="${SCRIPT_NAME}"
msg "$(s yellow)=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=$(e)"
fi
if [[ "${extra_option}" == "--silent-if-executed" ]]; then
end_execute_options "${run_mode}" "${func_name}" &>/dev/null
else
end_execute_options "${run_mode}" "${func_name}"
fi
}
# Configure dropbox for both local and remote server
configure_dropbox_cli() {
local run_mode func_name
run_mode="$1"
extra_option="$2"
func_name="${FUNCNAME[0]}"
if [[ "${extra_option}" == "--silent-if-executed" ]]; then
start_execute_options "${run_mode}" "${func_name}" &>/dev/null
else
start_execute_options "${run_mode}" "${func_name}"
fi
[[ "${SKIP_RUN}" == "true" ]] && return 0
if [[ ! -f "${OS_TEMP_PATH}/${C_BOX_HOSTNAME_FQHN}_${func_name}_executed" && "${FUNCTION_RUN}" == "true" ]]; then
local script_install_path
script_install_path="/usr/local/opencode/dbxcli"
msg "$(s cyan)Configuring dbxcli (Dropbox Uploader) forked from andreafabrizi/Dropbox-Uploader ... $(e)" --caller="${SCRIPT_NAME}"
maxibuild --include dbxcli
echo ""
msg "$(s cyan)Copying ${script_install_path}/dropbox_uploader.conf.sample to ${HOME}/.dropbox_uploader ...$(e)" --caller="${SCRIPT_NAME}"
cp -f "${script_install_path}/dropbox_uploader.conf.sample" "${HOME}/.dropbox_uploader.conf"
echo ""
msg "Configuring dbxcli API authentication ..."
sed -i "s|^CONFIGFILE_VERSION\=.*|CONFIGFILE_VERSION=\"2.0\"|" "${HOME}/.dropbox_uploader.conf"
sed -i "s|^OAUTH_APP_KEY\=.*|OAUTH_APP_KEY=\"${C_DROPBOX_OAUTH_APP_KEY}\"|" "${HOME}/.dropbox_uploader.conf"
sed -i "s|^OAUTH_APP_SECRET\=.*|OAUTH_APP_SECRET=\"${C_DROPBOX_OAUTH_APP_SECRET}\"|" "${HOME}/.dropbox_uploader.conf"
get_status_message "$?"
if command -v dbxcli &>/dev/null; then
dbxcli reauth
else
msg "$(s red)Error, dbxcli is not installed. Please install it first. $(e)" --caller="${SCRIPT_NAME}"
exit 1
fi
dbxcli test
check_finish_reboot "${func_name}"
else
msg "$(s yellow)[Skipped by system]: $(s magenta)${func_name}$(e) $(s yellow)with current option ${run_mode} has ran before $(e)" --caller="${SCRIPT_NAME}"
msg "$(s yellow)=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=$(e)"
fi
if [[ "${extra_option}" == "--silent-if-executed" ]]; then
end_execute_options "${run_mode}" "${func_name}" &>/dev/null
else
end_execute_options "${run_mode}" "${func_name}"
fi
}
update_remote() {
local data file_to_transfer remote_path_to_receive
data="$1"
if [ "${data}" == "all" ]; then
msg "$(s cyan)Copying all setup files into server ... $(e)" --caller="${SCRIPT_NAME}"
# Main script to update
check_path "${SCRIPT_PATH}/maxinet" "${SCRIPT_PATH}/maxinet.conf" "${SCRIPT_PATH}/readme.txt"
file_to_transfer="${SCRIPT_PATH}/maxinet ${SCRIPT_PATH}/maxinet.conf ${SCRIPT_PATH}/readme.txt"
remote_path_to_receive="${HOME}/"
ssh_api transfer-files --server-port "${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}" --group-user "${C_ROOT_USERGROUP}:${C_ROOT_USERNAME}" --local-files "${file_to_transfer}" --remote-path "${remote_path_to_receive}"
echo ""
# GPG private key to update
file_to_transfer="${SECURE_PATH}/gpg/gpg_private_key.gpg"
remote_path_to_receive="${HOME}/gpg/"
ssh_api mkdir --server-port ${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT} --group-user ${C_ROOT_USERGROUP}:${C_ROOT_USERNAME} --remote-path "${remote_path_to_receive}"
ssh_api transfer-files --server-port "${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}" --group-user "${C_ROOT_USERGROUP}:${C_ROOT_USERNAME}" --local-files "${file_to_transfer}" --remote-path "${remote_path_to_receive}"
echo ""
# SSL cert to update
file_to_transfer="${SECURE_PATH}/ssl/*"
remote_path_to_receive="${HOME}/ssl/"
ssh_api mkdir --server-port ${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT} --group-user ${C_ROOT_USERGROUP}:${C_ROOT_USERNAME} --remote-path "${remote_path_to_receive}"
ssh_api transfer-files --server-port "${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}" --group-user "${C_ROOT_USERGROUP}:${C_ROOT_USERNAME}" --local-files "${file_to_transfer}" --remote-path "${remote_path_to_receive}"
echo ""
# Backup file to update
file_to_transfer="${SECURE_PATH}/backup/admin_backups/current_backups/*"
remote_path_to_receive="${HOME}/admin_backups/"
ssh_api mkdir --server-port ${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT} --group-user ${C_ROOT_USERGROUP}:${C_ROOT_USERNAME} --remote-path "${remote_path_to_receive}"
ssh_api transfer-files --server-port "${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}" --group-user "${C_ROOT_USERGROUP}:${C_ROOT_USERNAME}" --local-files "${file_to_transfer}" --remote-path "${remote_path_to_receive}"
echo ""
# maxiaide / AIDE custom_rules file
file_to_transfer="${SECURE_PATH}/maxiaide/custom_rules"
remote_path_to_receive="${HOME}/maxiaide/"
ssh_api mkdir --server-port ${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT} --group-user ${C_ROOT_USERGROUP}:${C_ROOT_USERNAME} --remote-path "${remote_path_to_receive}"
ssh_api transfer-files --server-port "${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}" --group-user "${C_ROOT_USERGROUP}:${C_ROOT_USERNAME}" --local-files "${file_to_transfer}" --remote-path "${remote_path_to_receive}"
echo ""
# maxiclam / maxiclam exclude scan files
file_to_transfer="${SECURE_PATH}/maxiclam/*"
remote_path_to_receive="${HOME}/maxiclam/"
ssh_api mkdir --server-port ${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT} --group-user ${C_ROOT_USERGROUP}:${C_ROOT_USERNAME} --remote-path "${remote_path_to_receive}"
ssh_api transfer-files --server-port "${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}" --group-user "${C_ROOT_USERGROUP}:${C_ROOT_USERNAME}" --local-files "${file_to_transfer}" --remote-path "${remote_path_to_receive}"
echo ""
# add directadmin custom hook scripts
file_to_transfer="${SECURE_PATH}/directadmin/custom_scripts/*"
remote_path_to_receive="${HOME}/directadmin/custom_scripts"
ssh_api mkdir --server-port ${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT} --group-user ${C_ROOT_USERGROUP}:${C_ROOT_USERNAME} --remote-path "${remote_path_to_receive}"
ssh_api transfer-files --server-port "${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}" --group-user "${C_ROOT_USERGROUP}:${C_ROOT_USERNAME}" --local-files "${file_to_transfer}" --remote-path "${remote_path_to_receive}"
echo ""
elif [ "${data}" == "da-hook-script" ]; then
msg "$(s cyan)Copying da-hook-script files into server ... $(e)" --caller="${SCRIPT_NAME}"
# add directadmin custom hook scripts
file_to_transfer="${SECURE_PATH}/directadmin/custom_scripts/*"
remote_path_to_receive="${HOME}/directadmin/custom_scripts"
ssh_api mkdir --server-port ${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT} --group-user ${C_ROOT_USERGROUP}:${C_ROOT_USERNAME} --remote-path "${remote_path_to_receive}"
ssh_api transfer-files --server-port "${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}" --group-user "${C_ROOT_USERGROUP}:${C_ROOT_USERNAME}" --local-files "${file_to_transfer}" --remote-path "${remote_path_to_receive}"
echo ""
elif [ "${data}" == "setup-script-only" ]; then
msg "$(s cyan)Copying maxinet setup scripts into server ... $(e)" --caller="${SCRIPT_NAME}"
# Main script to update
check_path "${SCRIPT_PATH}/maxinet" "${SCRIPT_PATH}/maxinet.conf" "${SCRIPT_PATH}/readme.txt"
file_to_transfer="${SCRIPT_PATH}/maxinet ${SCRIPT_PATH}/maxinet.conf ${SCRIPT_PATH}/readme.txt"
remote_path_to_receive="${HOME}/"
ssh_api transfer-files --server-port "${C_BOX_HOSTNAME_FQHN}:${C_SSH_PORT}" --group-user "${C_ROOT_USERGROUP}:${C_ROOT_USERNAME}" --local-files "${file_to_transfer}" --remote-path "${remote_path_to_receive}"
echo ""
else
msg "$(s red)Error, unknown argument passed for update_remote function ... $(e)" --caller="${SCRIPT_NAME}"
fi
}
ensure_internet_connected() {
maxibuild --include "curl"
if curl -s --head --request GET www.google.com | grep "200 OK" >/dev/null; then
#echo "OK, connected to the internet"
return 0
else
echo "Error, could not connect to the internet"
exit 147
fi
}
ensure_linode_label_ipv4_valid() {
# Because labelling is important, it must be unique to represent that node is a hostname (1 node = 1 hostname)
echo -n "Checking if linode label is matched with the host domain name ${C_LINODE_LABEL} ... "
while :; do
# linode_api_admin get-linode-ipv4 --scripting
readarray -t linode_current_ipv4s <<<"$(maxipi linode get-linode-ipv4 --scripting)"
match_label=false
match_ip=false
count_ip=0
while [[ ${count_ip} -lt $(echo "${!C_IPV4_ADD@}" | wc -w) ]]; do
local c_ipv4_add
typeset -n c_ipv4_add="C_IPV4_ADD${count_ip}"
for linode_current_ipv4 in "${linode_current_ipv4s[@]}"; do
if [[ "${linode_current_ipv4}" == "${c_ipv4_add}" ]]; then
match_ip=true