-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxibuild
More file actions
2461 lines (2012 loc) · 98.3 KB
/
maxibuild
File metadata and controls
2461 lines (2012 loc) · 98.3 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
#"=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~="
# ==================================================
_APP_SPECIFIC_NAME="Maxibuild"
_APP_VERSION="0.4.0"
_APP_STATUS="alpha"
_APP_INFO="${_APP_SPECIFIC_NAME} is a bash script to manage packages."
_APP_VERSION_STATUS="${_APP_VERSION}-${_APP_STATUS}"
_AUTHOR="Author: Arafat Ali | Email: arafat@sofibox.com | (C) 2019-2023"
# ====================================================
# Usage:
# maxibuild --include "p1 p2 p3 p4" --force
# This script is used to update script from a remote repository based on a given path
# Usage: script_update [script_path]
# Example: script_update /opt/maxigpg_public/
# ================ shell config ====================
shopt -s extglob
# ================ shell config ====================
script_update() {
local script_name script_path caller script_install_path current_configs new_configs
script_name="$(basename "${0}")"
script_path="$(dirname "$(readlink -f "$0")")"
caller="${script_name}->${FUNCNAME[0]}"
script_install_path="${1}"
echo "[${caller}]: Updating $(basename -- "$0") to latest version ..."
# CD to ${script_path} and if does not exist exit with error
cd "${script_path}" || {
echo "[${caller}]: ERROR, could not change directory to ${script_path}"
exit 1
}
echo ""
echo "START git update information:"
git fetch --all
get_status_message "$?"
git reset --hard origin/main
get_status_message "$?"
echo "END git update information:"
echo ""
echo "[${caller}]: Updating ${script_name} configuration file ..."
# This will add a new config variable into the config file if it does not exist
# It will not disturb variable that already has value. So you do not need to reconfigure the script
# If config contain invalid value like having no equal sign, it will also replace them with a new variable from sample config
current_configs=$(grep -E '^[A-Za-z0-9_].+=.+$' "${script_install_path}/${script_name}.conf" | awk -F "=" '{print $1}')
new_configs=$(grep -E '^[A-Za-z0-9_].+=.+$' "${script_install_path}/${script_name}.conf.sample" | awk -F "=" '{print $1}')
for new_config in ${new_configs}; do
if [[ ${current_configs} =~ ${new_config} ]]; then
:
else
echo "Adding new config: ${new_config} into ${script_install_path}/${script_name}.conf"
echo "${new_config}=\"\"" >>"${script_install_path}/${script_name}.conf"
get_status_message "$?"
fi
done
# Remove blank lines, comments and sort config file
grep -E '^[A-Za-z0-9_].+=.+$' "${script_install_path}/${script_name}.conf" | sort >"${script_install_path}/${script_name}.conf_tmp"
mv "${script_install_path}/${script_name}.conf_tmp" "${script_install_path}/${script_name}.conf"
get_status_message "$?"
echo "[${caller}]: Running ${script_name} -V ..."
chmod +x "${script_install_path}/${script_name}"
${script_name} -V
get_status_message "$?"
}
# This function is used to check for script update. It will also prompt user to update the script if there is a new version available.
# Usage: check_update
# Example: check_update
check_update() {
local script_name script_path caller temp_file script_install_path
script_name="$(basename "${0}")"
script_path="$(dirname "$(readlink -f "$0")")"
caller="${script_name}->${FUNCNAME[0]}"
script_install_path="/usr/local/maxicode/maxibuild"
echo "[${caller}]: Checking ${script_name} for update..."
temp_file="${TEMP_PATH}/${script_name}"
# The github raw hosting will not be updated immediately after I push the update to github. Need to wait about 5 minutes
if ! command -v curl &>/dev/null; then
[[ "$(get_distro id)" == @(debian|ubuntu|centos|almalinux|rhel) ]] && apt-get install -y curl
fi
curl -H 'Cache-Control: no-cache' -so "${temp_file}" "https://raw.githubusercontent.com/sofibox/${script_name}_public/main/${script_name}"
get_status_message "$?"
available_version="$(awk -F'=' '/^_APP_VERSION=/{ print $2 }' "${temp_file}" | sed 's/\"//g')"
this_version="${_APP_VERSION}"
echo ""
echo "Installed version is: v${this_version}"
echo "Online version is: v${available_version}"
echo ""
if [[ "ok" == "$(echo | awk "(${available_version} > ${this_version}) { print \"ok\"; }")" ]]; then
echo "[${caller}]: A new version of ${script_name} is available."
read -r -p "[${caller}->input]: Do you want to update ${script_name} to version ${available_version}? [default:Y] [Y/n]: " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
script_update "${script_install_path}"
else
echo "[${caller}->cancel]: Operation aborted!"
exit 0
fi
elif [[ "ok" == "$(echo | awk "(${available_version} == ${this_version}) { print \"ok\"; }")" ]]; then
echo "[${caller}]: You are using the latest version of ${script_name}."
else
echo "[${caller}]: You are using a newer version of ${script_name} than the latest available."
fi
rm -f "${temp_file}"
}
# This function is used to check if given package is installed and install the package if it is not installed
# It will not do anything if the required package exist
# Usage: maxibuild [package(s)]
# Example: maxibuild curl wget git
get_status_message() {
local retval
retval="$1"
if [[ "${retval}" -eq 0 ]]; then
echo " [ OK ]"
else
echo " [ FAILED ]"
exit 1
fi
}
get_distro() {
local arg distro_id distro_version distro_codename
arg="$1"
if [ -e /etc/os-release ]; then
distro_id=$(awk -F= '$1 == "ID" {print $2}' /etc/os-release | LC_ALL=C tr '[:upper:]' '[:lower:]' | tr -d "\"")
distro_version=$(awk -F= '$1 == "VERSION_ID" {print $2}' /etc/os-release | tr -d "\"")
distro_codename=$(awk -F= '$1 == "VERSION_CODENAME" {print $2}' /etc/os-release | tr -d "\"")
elif type lsb_release >/dev/null 2>&1; then
distro_id=$(lsb_release -si | LC_ALL=C tr '[:upper:]' '[:lower:]')
distro_version=$(lsb_release -sr)
distro_codename=$(lsb_release -sc)
else
distro_id=$(uname -s)
distro_version=$(uname -r)
distro_codename=""
fi
if [ "${arg}" == "id" ]; then
echo "${distro_id}"
elif [ "${arg}" == "version" ]; then
echo "${distro_version}"
elif [ "${arg}" == "codename" ]; then
echo "${distro_codename}"
fi
}
# This function is used to convert an integer to ordinal number
# Usage: ordinal [number]
# Example: ordinal 1
# Output: 1st
to_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
}
navigate_to() {
local to_path="$1"
if [[ "${to_path^^}" == +(PRE|PREVIOUS|OLDPATH|BACK|OLDPWD) ]]; then
# OLD_PATH holds a previous path (see global variable of PREPATH in this script)
echo "Navigating out into ${OLD_PATH} ..."
to_path="${OLD_PATH}"
else
if [[ -z "${to_path}" ]]; then
echo "Error, no path specified"
exit 1
fi
if [[ ! -d "${to_path}" ]]; then
echo "Error, the path ${to_path} does not exist"
exit 1
fi
echo "Navigating into ${to_path} ..."
OLD_PATH="${PWD}"
fi
cd "${to_path}" || {
echo "Error, failed to enter into the directory ${to_path}"
exit 1
}
}
maxibuild_cmd() {
local caller required_cps missing_count
# To avoid error for current, we must always start from this path
cd "${SCRIPT_PATH}" || {
echo "Failed to change directory to ${SCRIPT_PATH}"
exit 1
}
caller="$(basename -- "$0")->${FUNCNAME[0]}"
((missing_count = 0))
# Detect required packages
read -ra required_cps <<<"$(echo "${INCLUDE_CPS}" | tr ',' ' ' | tr -d '"')"
for required_cp in ${required_cps[*]}; do
# If the required package is a special command, we list it here
# For example `puttygen` is a command and its package name is `putty-tools`. So if we want to install putty-tools, we can use `puttygen` as the command to install
if [[ "${required_cp}" == @(mail|linode-cli|ipcalc|maxipi|maxiaide|maxigpg|maxiperm|maxida|maxilog|maxiwall|dbxcli|ip|pstree|netstat|puttygen|grepaddr|gotify-server|gotify-client|blcheck|wp|wpcli|rclone|yq|suricata_distro|suricata_backport|suricata|suricata_v6.0.9|suricata_v6.0.10|suricata_v7.0.0-rc1|lua|lua5.1|lua5.2|lua5.3|lua5.4|aipdb|greynoise|virustotal|mysqltuner|netcat) ]]; then
local cmd_status retval
# Using command to obtain installation status
command -v "${required_cp}" >/dev/null
cmd_status="$?"
# START Special case
if [[ "${required_cp}" == @(suricata|suricata_distro|suricata_backport|suricata_v6.0.9|suricata_v6.0.10|suricata_v7.0.0-rc1) ]]; then
if command -v suricata &>/dev/null; then
echo "[${caller}]: Suricata is already installed. Use --force to force install ${required_cp}"
cmd_status=0
fi
fi
# END Special case
[[ "${FORCE_INSTALL}" == "true" ]] && cmd_status=1
if [[ "${cmd_status}" -eq 1 ]]; then
((missing_count++))
echo ""
if [[ "${FORCE_INSTALL}" == "true" ]]; then
echo "[${caller}]: Notice, ${required_cp} will be installed in --force mode"
else
echo "[${caller}]: Warning, the required command ${required_cp} is missing!"
fi
echo ""
# This prevents error if we never run apt-get update when the apt cache is expired
# When the first missing package is triggered, then we display warning message,
# and for this first time, we trigger update command to refresh the expired apt cache
if [[ "${missing_count}" -eq 1 ]]; then
echo "[${caller}]: Running system update for the first missing command ..."
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
apt-get -qq -y update
elif [[ "$(get_distro id)" == @(centos|fedora|rhel|almalinux|rocklylinux) ]]; then
dnf -q -y update
fi
get_status_message "$?"
echo ""
# Check if git is installed (it is necessary)
if ! command -v git >/dev/null; then
echo "[${caller}]: Warning, git is missing!"
echo ""
echo "[${caller}]: Installing git ..."
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
apt-get -qq -y install git
elif [[ "$(get_distro id)" == @(centos|fedora|rhel|almalinux|rocklylinux) ]]; then
dnf -q -y install git
fi
get_status_message "$?"
echo ""
fi
# Check if curl is installed (it is necessary)
if ! command -v curl >/dev/null; then
echo "[${caller}]: Warning, curl is missing!"
echo ""
echo "[${caller}]: Installing curl ..."
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
apt-get -qq -y install curl
elif [[ "$(get_distro id)" == @(centos|fedora|rhel|almalinux|rocklylinux) ]]; then
dnf -q -y install curl
fi
get_status_message "$?"
echo ""
fi
# Check if wget is installed (it is necessary)
if ! command -v wget >/dev/null; then
echo "[${caller}]: Warning, wget is missing!"
echo ""
echo "[${caller}]: Installing wget ..."
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
apt-get -qq -y install wget
elif [[ "$(get_distro id)" == @(centos|fedora|rhel|almalinux|rocklylinux) ]]; then
dnf -q -y install wget
fi
get_status_message "$?"
echo ""
fi
# Check if unzip is installed (it is necessary)
if ! command -v unzip >/dev/null; then
echo "[${caller}]: Warning, unzip is missing!"
echo ""
echo "[${caller}]: Installing unzip ..."
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
apt-get -qq -y install unzip
elif [[ "$(get_distro id)" == @(centos|fedora|rhel|almalinux|rocklylinux) ]]; then
dnf -q -y install unzip
fi
get_status_message "$?"
echo ""
fi
# Check if tar is installed (it is necessary)
if ! command -v tar >/dev/null; then
echo "[${caller}]: Warning, tar is missing!"
echo ""
echo "[${caller}]: Installing tar ..."
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
apt-get -qq -y install tar
elif [[ "$(get_distro id)" == @(centos|fedora|rhel|almalinux|rocklylinux) ]]; then
dnf -q -y install tar
fi
get_status_message "$?"
echo ""
fi
fi
echo "[${caller}]: ${missing_count}) Installing the $(to_ordinal "${missing_count}") missing command: ${required_cp} ..."
echo ""
# Package installation condition here
if [[ "${required_cp}" == @(mail) ]]; then
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
apt-get -y install bsd-mailx
elif [[ "$(get_distro id)" == @(centos|almalinux|rockylinux) ]]; then
apt-get -y install mail-utils
fi
get_status_message "$?"
echo ""
elif [[ "${required_cp}" == @(linode-cli) ]]; then
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
apt-get -y install python3-pip
elif [[ "$(get_distro id)" == @(centos|almalinux|rockylinux) ]]; then
dnf -y install python3-pip
fi
pip3 install linode-cli --upgrade
elif [[ "${required_cp}" == @(ipcalc) ]]; then
local ipcalc_bin script_install_path
script_install_path="/usr/local/opencode/ipcalc"
ipcalc_bin="${script_install_path}/build/ipcalc"
echo "[${caller}]: Removing the old ipcalc installation ..."
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
apt-get -y remove ipcalc
elif [[ "$(get_distro id)" == @(centos|almalinux|rockylinux) ]]; then
dnf -y remove ipcalc
fi
get_status_message "$?"
echo ""
echo "[${caller}]: Removing the old ipcalc directory"
rm -rf "${script_install_path}" /usr/local/bin/ipcalc /usr/bin/ipcalc
get_status_message "$?"
echo ""
echo "[${caller}]: Install required packages to build ipcalc ..."
apt-get -y install git gcc meson
get_status_message "$?"
echo ""
echo "[${caller}]: Creating an installation directory for ipcalc ..."
mkdir -p "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Cloning the ipcalc repository ..."
git clone https://github.com/sofibox/ipcalc.git "${script_install_path}"
get_status_message "$?"
echo ""
# Change directory to script_install_path, if failed then exit with a message
navigate_to "${script_install_path}"
echo "[${caller}]: Configuring ipcalc build type ..."
meson setup build --buildtype=release
get_status_message "$?"
echo ""
echo "[${caller}]: Building ipcalc ..."
ninja -C build
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the ipcalc installation script ..."
chmod +x ${ipcalc_bin}
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the ipcalc installation script ..."
ln -s ${ipcalc_bin} /usr/local/bin
get_status_message "$?"
echo ""
#echo "[${caller}]: Copying sample config file ..."
#cp "${script_install_path}/ipcalc.conf.sample" "${script_install_path}/ipcalc.conf"
#echo ""
# echo "[${caller}]: Running ipcalc --version ..."
# ipcalc --version
# get_status_message "$?"
# retval=$?
echo "[${caller}]: Checking if ipcalc is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
elif [ "${required_cp}" == "maxipi" ]; then
if [[ "$(get_distro id)" == @(debian|ubuntu|centos|almalinux) ]]; then
local maxipi_bin script_install_path
script_install_path="/usr/local/maxicode/maxipi"
maxipi_bin="${script_install_path}/maxipi"
echo "[${caller}]: Removing the old maxipi directory"
rm -rf "${script_install_path}" /usr/local/bin/maxipi /usr/bin/maxipi
get_status_message "$?"
echo ""
echo "[${caller}]: Install required packages to build maxipi ..."
apt-get -y install gcc meson
get_status_message "$?"
echo ""
echo "[${caller}]: Creating an installation directory for maxipi ..."
mkdir -p "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Cloning the maxipi repository ..."
git clone https://github.com/sofibox/maxipi_public.git "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the maxipi installation script ..."
chmod +x ${maxipi_bin}
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the maxipi installation script ..."
ln -s ${maxipi_bin} /usr/local/bin
get_status_message "$?"
echo ""
#echo "[${caller}]: Running maxipi --version ..."
#maxipi --version
#get_status_message "$?"
#retval=$?
echo "[${caller}]: Checking if maxipi is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
fi
elif [[ "${required_cp}" == "maxiaide" ]]; then
local maxiaide_bin script_install_path
script_install_path="/usr/local/maxicode/maxiaide"
maxiaide_bin="${script_install_path}/maxiaide"
echo "[${caller}]: Removing the old maxiaide directory"
rm -rf "${script_install_path}" /usr/local/bin/maxiaide /usr/bin/maxiaide
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
echo "[${caller}]: Removing aide aide-common..."
apt-get -y remove aide aide-common
get_status_message "$?"
echo ""
echo "[${caller}]: Purging aide aide-common..."
apt-get -y purge aide-common
get_status_message "$?"
echo ""
echo "[${caller}]: Install maxiaide required packages ..."
apt-get -y install aide
get_status_message "$?"
echo ""
elif [[ "$(get_distro id)" == @(centos|almalinux) ]]; then
echo "[${caller}]: Removing aide ..."
dnf -y remove aide
get_status_message "$?"
echo ""
echo "[${caller}]: Install maxiaide required packages ..."
dnf -y install aide
get_status_message "$?"
echo ""
# TODO make it support next time
echo "[${caller}]: Note that maxiaide is not supported on this distribution yet."
else
echo "[${caller}]: ${required_cp} is not supported on this distribution"
exit 1
fi
echo "[${caller}]: Creating an installation directory for maxiaide ..."
mkdir -p "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Cloning the maxiaide repository ..."
git clone https://github.com/sofibox/maxiaide_public.git "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the maxiaide installation script ..."
chmod +x ${maxiaide_bin}
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the maxiaide installation script ..."
ln -s ${maxiaide_bin} /usr/local/bin
get_status_message "$?"
echo ""
echo "[${caller}]: Copying sample config file ..."
cp "${script_install_path}/maxiaide.conf.sample" "${script_install_path}/maxiaide.conf"
get_status_message "$?"
echo ""
#echo "[${caller}]: Running maxiaide --version ..."
#maxiaide --version
#get_status_message "$?"
#retval=$?
# Extra steps for Debian
if [ -f /etc/cron.daily/aide ]; then
echo "[${caller}]: Removing /etc/cron.daily/aide ..."
rm -fv /etc/cron.daily/aide
get_status_message "$?"
echo ""
fi
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
elif [[ "${required_cp}" == "maxigpg" ]]; then
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
local maxigpg_bin script_install_path
script_install_path="/usr/local/maxicode/maxigpg"
maxigpg_bin="${script_install_path}/maxigpg"
echo "[${caller}]: Removing GPG ..."
apt-get -y remove gpg
get_status_message "$?"
echo ""
echo "[${caller}]: Removing the old maxigpg directory"
rm -rf "${script_install_path}" /usr/local/bin/maxigpg /usr/bin/maxigpg
get_status_message "$?"
echo ""
echo "[${caller}]: Install maxigpg required packages ..."
apt-get -y install gpg
get_status_message "$?"
echo ""
echo "[${caller}]: Creating an installation directory for maxigpg ..."
mkdir -p "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Cloning the maxigpg repository ..."
git clone https://github.com/sofibox/maxigpg_public.git "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the maxigpg installation script ..."
chmod +x ${maxigpg_bin}
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the maxigpg installation script ..."
ln -s ${maxigpg_bin} /usr/local/bin
get_status_message "$?"
echo ""
echo "[${caller}]: Copying sample config file ..."
cp "${script_install_path}/maxigpg.conf.sample" "${script_install_path}/maxigpg.conf"
get_status_message "$?"
echo ""
#echo "[${caller}]: Running maxigpg --version ..."
#maxigpg --version
#get_status_message "$?"
#retval=$?
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
fi
elif [[ "${required_cp}" == "maxiperm" ]]; then
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
local maxiperm_bin perm_bin script_install_path
script_install_path="/usr/local/maxicode/maxiperm"
maxiperm_bin="${script_install_path}/maxiperm"
perm_bin="${script_install_path}/perm"
echo "[${caller}]: Removing the old maxiperm directory"
rm -rf "${script_install_path}" /usr/local/bin/maxiperm /usr/bin/maxiperm /usr/local/bin/perm /usr/bin/perm
get_status_message "$?"
echo ""
echo "[${caller}]: Creating an installation directory for maxiperm ..."
mkdir -p "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Cloning the maxiperm repository ..."
git clone https://github.com/sofibox/maxiperm_public.git "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the maxiperm installation script ..."
chmod +x ${maxiperm_bin}
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the maxiperm installation script ..."
ln -s ${maxiperm_bin} /usr/local/bin
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the perm installation script ..."
chmod +x ${perm_bin}
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the perm installation script ..."
ln -s ${perm_bin} /usr/local/bin
get_status_message "$?"
echo ""
echo "[${caller}]: Copying sample config file ..."
cp "${script_install_path}/maxiperm.conf.sample" "${script_install_path}/maxiperm.conf"
get_status_message "$?"
echo ""
# echo "[${caller}]: Running maxiperm --version ..."
# maxiperm --version
# get_status_message "$?"
# retval=$?
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
fi
elif [[ "${required_cp}" == "maxida" ]]; then
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
local maxida_bin dacli_bin script_install_path
script_install_path="/usr/local/maxicode/maxida"
maxida_bin="${script_install_path}/maxida"
dacli_bin="${script_install_path}/dacli"
echo "[${caller}]: Removing the old maxida directory"
rm -rf "${script_install_path}" /usr/local/bin/maxida /usr/bin/maxida /usr/local/bin/dacli /usr/bin/dacli
get_status_message "$?"
echo ""
echo "[${caller}]: Creating an installation directory for maxida ..."
mkdir -p "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Cloning the maxida repository ..."
git clone https://github.com/sofibox/maxida_public.git "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the maxida installation script ..."
chmod +x ${maxida_bin}
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the maxida installation script ..."
ln -s ${maxida_bin} /usr/local/bin
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the dacli installation script ..."
chmod +x ${dacli_bin}
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the dacli installation script ..."
ln -s ${dacli_bin} /usr/local/bin
get_status_message "$?"
echo ""
echo "[${caller}]: Copying sample config file ..."
cp "${script_install_path}/maxida.conf.sample" "${script_install_path}/maxida.conf"
get_status_message "$?"
echo ""
# echo "[${caller}]: Running maxida --version ..."
# maxida --version
# get_status_message "$?"
# retval=$?
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
fi
elif [[ "${required_cp}" == "maxilog" ]]; then
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
local maxilog_bin script_install_path
script_install_path="/usr/local/maxicode/maxilog"
maxilog_bin="${script_install_path}/maxilog"
echo "[${caller}]: Removing the old maxilog directory"
rm -rf "${script_install_path}" /usr/local/bin/maxilog /usr/bin/maxilog
get_status_message "$?"
echo ""
echo "[${caller}]: Creating an installation directory for maxilog ..."
mkdir -p "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Cloning the maxilog repository ..."
git clone https://github.com/sofibox/maxilog_public.git "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the maxilog installation script ..."
chmod +x ${maxilog_bin}
get_status_message "$?"
echo "[${caller}]: Creating a symbolic link to the maxilog installation script ..."
ln -s ${maxilog_bin} /usr/local/bin
get_status_message "$?"
echo ""
echo "[${caller}]: Copying sample config file ..."
cp "${script_install_path}/maxilog.conf.sample" "${script_install_path}/maxilog.conf"
get_status_message "$?"
echo "[${caller}]: Copying sample log_list.json file ..."
cp "${script_install_path}/log_list.json.sample" "${script_install_path}/log_list.json"
get_status_message "$?"
echo ""
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
fi
elif [ "${required_cp}" == "dbxcli" ]; then
if [[ "$(get_distro id)" == @(debian|ubuntu) ]]; then
local dbxcli_bin script_install_path
script_install_path="/usr/local/opencode/dbxcli"
dbxcli_bin="${script_install_path}/dbxcli"
dropbox_uploader_bin="${script_install_path}/dropbox_uploader.sh"
echo "[${caller}]: Removing the old dbxcli directory"
rm -rf "${script_install_path}" /usr/local/bin/dbxcli /usr/bin/dbxcli
get_status_message "$?"
echo ""
echo "[${caller}]: Creating an installation directory for dbxcli ..."
mkdir -p "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Cloning the dbxcli repository ..."
git clone https://github.com/sofibox/dbxcli.git "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the ${dropbox_uploader_bin} installation script ..."
chmod +x "${dropbox_uploader_bin}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the dbxcli installation script ..."
chmod +x "${dbxcli_bin}"
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the dbxcli installation script ..."
ln -s "${dbxcli_bin}" /usr/local/bin
get_status_message "$?"
echo ""
# echo "[${caller}]: Running dbxcli version ..."
# dbxcli version
# get_status_message "$?"
# retval=$?
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
fi
elif [[ "${required_cp}" == "ip" ]]; then
[[ "$(get_distro id)" == @(debian|ubuntu) ]] && apt-get -y install iproute2
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
elif [[ "${required_cp}" == "pstree" ]]; then
[[ "$(get_distro id)" == @(debian|ubuntu|centos|almalinux|rockylinux) ]] && apt-get -y install psmisc
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
elif [[ "${required_cp}" == @(dig|nslookup) ]]; then
[[ "$(get_distro id)" == @(debian|ubuntu) ]] && apt-get -y install dnsutils
[[ "$(get_distro id)" == @(centos|almalinux|rockylinux) ]] && dnf -y install bind-utils
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
elif [[ "${required_cp}" == @(netstat) ]]; then
[[ "$(get_distro id)" == @(debian|ubuntu|centos|almalinux|rockylinux) ]] && apt-get -y install net-tools
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
elif [[ "${required_cp}" == @(puttygen) ]]; then
[[ "$(get_distro id)" == @(debian|ubuntu|centos|almalinux|rockylinux) ]] && apt-get -y install putty-tools
echo "[${caller}]: Checking if ${required_cp} is installed ..."
command -v "${required_cp}" &>/dev/null
get_status_message "$?"
elif [[ "${required_cp}" == @(grepaddr) ]]; then
if [[ "$(get_distro id)" == @(debian|ubuntu|centos|almalinux|rockylinux) ]]; then
local grepaddr_bin script_install_path
script_install_path="/usr/local/opencode/grepaddr"
grepaddr_bin="${script_install_path}/grepaddr"
echo "[${caller}]: Removing the old grepaddr directory"
rm -rf "${script_install_path}" /usr/local/bin/grepaddr /usr/bin/grepaddr
get_status_message "$?"
echo ""
echo "[${caller}]: Creating an installation directory for grepaddr ..."
mkdir -p "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Cloning the grepaddr repository ..."
git clone https://github.com/sofibox/grepaddr.git "${script_install_path}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the grepaddr.py installation script ..."
chmod +x "${grepaddr_bin}.py"
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the grepaddr installation script ..."
ln -s "${grepaddr_bin}.py" "/usr/local/bin"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the grepaddr.py alias called grepaddr ..."
chmod +x "${grepaddr_bin}"
get_status_message "$?"
echo ""
echo "[${caller}]: Creating a symbolic link to the grepaddr.py alias called grepaddr ..."
ln -s "${grepaddr_bin}" /usr/local/bin
get_status_message "$?"
echo ""
echo "grepaddr has been installed. Please note that you need a python 3.6+ installation to use it."
echo ""
echo "[${caller}]: Checking if grepaddr is installed ..."
command -v grepaddr &>/dev/null
get_status_message "$?"
fi
elif
[[ "${required_cp}" == @(gotify-server) ]]
then
if [[ "$(get_distro id)" == @(debian|ubuntu|centos|almalinux|rockylinux) ]]; then
local script_install_path gotify_server_system_username gotify_server_system_group gotify_server_platform gotify_server_app_name gotify_server_service_name gotify_server_service_location \
gotify_server_app_path gotify_server_bin gotify_server_data_path gotify_server_config gotify_server_latest_version gotify_server_latest_url
script_install_path="/usr/local/opencode/gotify"
gotify_server_system_username="gotify"
gotify_server_system_group="gotify"
gotify_server_platform="linux-amd64"
gotify_server_app_name="gotify-server"
gotify_server_service_name="gotify-server"
gotify_server_service_location="/etc/systemd/system/${gotify_server_service_name}.service"
gotify_server_app_path="${script_install_path}/server"
gotify_server_bin="${gotify_server_app_path}/${gotify_server_app_name}"
gotify_server_data_path="${gotify_server_app_path}/data"
gotify_server_config="${gotify_server_app_path}/config.yml"
gotify_server_latest_version=$(curl -s https://api.github.com/repos/gotify/server/releases/latest | grep "tag_name" | cut -d '"' -f 4)
gotify_server_latest_url="https://github.com/gotify/server/releases/download/${gotify_server_latest_version}/gotify-${gotify_server_platform}.zip"
if [ "${gotify_server_app_name}" == "gotify" ]; then
echo "[${caller}]: Error, it is not recommend to use the gotify as the application name because you will have conflict with the gotify client. Please use something else such as gotify-server"
exit 1
fi
echo "[${caller}]: Latest version of gotify server is ${gotify_server_latest_url}"
echo ""
if [[ "$(systemctl is-active htop)" == "active" ]]; then
echo "[${caller}]: Stopping ${gotify_server_service_name}.service"
systemctl stop "${gotify_server_service_name}.service"
get_status_message "$?"
echo ""
fi
echo "[${caller}]: Removing the old gotify server installation"
rm -rf "${gotify_server_app_path}" /etc/systemd/system/"${gotify_server_service_name}.service" "/usr/local/bin/${gotify_server_app_name}"
get_status_message "$?"
echo ""
if id -u "${gotify_server_system_username}" >/dev/null 2>&1; then
echo "[${caller}]: Removing gotify server previous user ..."
userdel -r "${gotify_server_system_username}"
get_status_message "$?"
echo ""
fi
if [[ $(getent group ${gotify_server_system_group}) ]]; then
echo "[${caller}]: Removing gotify server previous group ..."
groupdel "${gotify_server_system_group}"
get_status_message "$?"
echo ""
fi
echo "[${caller}]: Creating an installation directory for gotify server ..."
mkdir -p "${gotify_server_app_path}"
get_status_message "$?"
echo ""
navigate_to "${gotify_server_app_path}"
echo "[${caller}]: Downloading the latest version of gotify server ..."
wget -q "${gotify_server_latest_url}"
get_status_message "$?"
echo ""
echo "[${caller}]: Unzipping the gotify server ..."
unzip -q "gotify-${gotify_server_platform}.zip"
get_status_message "$?"
echo ""
# We don't need the zip file anymore
echo "[${caller}]: Removing previous gotify server zip file ..."
rm -rf "gotify-${gotify_server_platform}.zip"
get_status_message "$?"
echo ""
echo "[${caller}]: Renaming the gotify server binary ..."
mv "${gotify_server_app_path}/gotify-${gotify_server_platform}" "${gotify_server_bin}"
get_status_message "$?"
echo ""
echo "[${caller}]: Changing the owner of the gotify server binary to root:root ..."
chown root:root "${gotify_server_bin}"
get_status_message "$?"
echo ""
echo "[${caller}]: Giving execution permission to the gotify server binary ..."
chmod +x "${gotify_server_bin}"
get_status_message "$?"
echo ""
echo "[${caller}]: Creating gotify server symbolic link to /usr/local/bin ..."
ln -s "${gotify_server_bin}" /usr/local/bin
get_status_message "$?"
echo ""