forked from wazuh/wazuh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·1142 lines (976 loc) · 27.1 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
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/sh
# Copyright (C) 2015, Wazuh Inc.
# Installation script for Wazuh
# Author: Daniel B. Cid <[email protected]>
### Looking up for the execution directory
cd `dirname $0`
### Looking for echo -n
ECHO="echo -n"
hs=`echo -n "a"`
if [ ! "X$hs" = "Xa" ]; then
if [ -x /usr/ucb/echo ]; then
ECHO="/usr/ucb/echo -n"
elif [ -x /bin/echo ]; then
ECHO="/bin/echo -n"
else
ECHO=echo
fi
fi
# For solaris
echo "xxxx" | grep -E "xxx" > /dev/null 2>&1
if [ ! $? = 0 ]; then
if [ -x /usr/xpg4/bin/grep ]; then
PATH=/usr/xpg4/bin:$PATH
fi
fi
# Initializing vars
SET_DEBUG=""
# Checking for command line arguments
for i in $*; do
if [ "X$i" = "Xdebug" ]; then
SET_DEBUG="debug"
elif [ "X$i" = "Xbinary-install" ]; then
USER_BINARYINSTALL="yes"
elif [ "X$i" = "Xhelp" ]; then
echo "$0 debug"
echo "$0 binary-install"
exit 1;
fi
done
##########
# install()
##########
Install()
{
echo ""
echo "4- ${installing}"
echo ""
echo "DIR=\"${INSTALLDIR}\""
# Changing Config.OS with the new C flags
# Checking if debug is enabled
if [ "X${SET_DEBUG}" = "Xdebug" ]; then
CEXTRA="${CEXTRA} -DDEBUGAD"
fi
echo "CEXTRA=${CEXTRA}" >> ./src/Config.OS
MAKEBIN=make
## Find make/gmake
if [ "X$NUNAME" = "XOpenBSD" ]; then
MAKEBIN=gmake
elif [ "X$NUNAME" = "XFreeBSD" ]; then
MAKEBIN=gmake
elif [ "X$NUNAME" = "XNetBSD" ]; then
MAKEBIN=gmake
elif [ "X$NUNAME" = "XDragonflyBSD" ]; then
MAKEBIN=gmake
elif [ "X$NUNAME" = "XBitrig" ]; then
MAKEBIN=gmake
elif [ "X$NUNAME" = "XSunOS" ]; then
MAKEBIN=gmake
elif [ "X$NUNAME" = "XHP-UX" ]; then
MAKEBIN=/usr/local/bin/gmake
elif [ "X$NUNAME" = "XAIX" ]; then
MAKEBIN=/opt/freeware/bin/gmake
fi
if [ $(grep "Alpine Linux" /etc/os-release > /dev/null && echo 1) ]; then
ALPINE_DEPS="EXTERNAL_SRC_ONLY=1"
fi
# On CentOS <= 5 we need to disable syscollector compilation
OS_VERSION_FOR_SYSC="${DIST_NAME}"
if ([ "X${OS_VERSION_FOR_SYSC}" = "Xrhel" ] || [ "X${OS_VERSION_FOR_SYSC}" = "Xcentos" ]) && [ ${DIST_VER} -le 5 ]; then
AUDIT_FLAG="USE_AUDIT=no"
MSGPACK_FLAG="USE_MSGPACK_OPT=no"
if [ ${DIST_VER} -lt 5 ]; then
SYSC_FLAG="DISABLE_SYSC=yes"
fi
fi
# Makefile
echo " - ${runningmake}"
echo ""
cd ./src
# Binary install will use the previous generated code.
if [ "X${USER_BINARYINSTALL}" = "X" ]; then
# Download external libraries if missing
find external/* > /dev/null 2>&1 || ${MAKEBIN} deps ${ALPINE_DEPS} TARGET=${INSTYPE}
if [ "X${OPTIMIZE_CPYTHON}" = "Xy" ]; then
CPYTHON_FLAGS="OPTIMIZE_CPYTHON=yes"
fi
# Add DATABASE=pgsql or DATABASE=mysql to add support for database
# alert entry
${MAKEBIN} TARGET=${INSTYPE} INSTALLDIR=${INSTALLDIR} ${SYSC_FLAG} ${MSGPACK_FLAG} ${AUDIT_FLAG} ${CPYTHON_FLAGS} -j${THREADS} build
if [ $? != 0 ]; then
cd ../
catError "0x5-build"
fi
fi
# If update, stop Wazuh
if [ "X${update_only}" = "Xyes" ]; then
echo "Stopping Wazuh..."
UpdateStopOSSEC
fi
# Install
InstallWazuh
cd ../
# Install Wazuh ruleset updater
if [ "X$INSTYPE" = "Xserver" ]; then
WazuhSetup
fi
# Calling the init script to start Wazuh during boot
runInit $INSTYPE ${update_only}
runinit_value=$?
# If update, start Wazuh
if [ "X${update_only}" = "Xyes" ]; then
WazuhUpgrade $INSTYPE
# Update versions previous to Wazuh 1.2
UpdateOldVersions
echo "Starting Wazuh..."
UpdateStartOSSEC
fi
if [ $runinit_value = 1 ]; then
notmodified="yes"
elif [ "X$START_WAZUH" = "Xyes" ]; then
echo "Starting Wazuh..."
UpdateStartOSSEC
fi
}
##########
# UseSyscheck()
##########
UseSyscheck()
{
# Integrity check config
echo ""
$ECHO " 3.2- ${runsyscheck} ($yes/$no) [$yes]: "
if [ "X${USER_ENABLE_SYSCHECK}" = "X" ]; then
read AS
else
AS=${USER_ENABLE_SYSCHECK}
fi
echo ""
case $AS in
$nomatch)
echo " - ${nosyscheck}."
;;
*)
SYSCHECK="yes"
echo " - ${yessyscheck}."
;;
esac
}
##########
# UseRootcheck()
##########
UseRootcheck()
{
# Rootkit detection configuration
echo ""
$ECHO " 3.3- ${runrootcheck} ($yes/$no) [$yes]: "
if [ "X${USER_ENABLE_ROOTCHECK}" = "X" ]; then
read ES
else
ES=${USER_ENABLE_ROOTCHECK}
fi
echo ""
case $ES in
$nomatch)
echo " - ${norootcheck}."
;;
*)
ROOTCHECK="yes"
echo " - ${yesrootcheck}."
;;
esac
}
UseSyscollector()
{
# Syscollector config predefined (is overwritten by the preload-vars file)
if [ "X${USER_ENABLE_SYSCOLLECTOR}" = "Xn" ]; then
SYSCOLLECTOR="no"
else
SYSCOLLECTOR="yes"
fi
}
UseSecurityConfigurationAssessment()
{
# Configuration assessment config predefined (is overwritten by the preload-vars file)
if [ "X${USER_ENABLE_SCA}" = "Xn" ]; then
SECURITY_CONFIGURATION_ASSESSMENT="no"
else
SECURITY_CONFIGURATION_ASSESSMENT="yes"
fi
}
UseSSLCert()
{
if [ "X${USER_CREATE_SSL_CERT}" = "Xn" ]; then
SSL_CERT="no"
else
SSL_CERT="yes"
fi
}
UseUpdateCheck()
{
# Update_check config predefined (is overwritten by the preload-vars file)
if [ "X${USER_ENABLE_UPDATE_CHECK}" = "Xn" ]; then
UPDATE_CHECK="no"
else
UPDATE_CHECK="yes"
fi
}
##########
# EnableAuthd()
##########
EnableAuthd()
{
# Authd config
NB=$1
echo ""
$ECHO " $NB - ${runauthd} ($yes/$no) [$yes]: "
if [ "X${USER_ENABLE_AUTHD}" = "X" ]; then
read AS
else
AS=${USER_ENABLE_AUTHD}
fi
echo ""
case $AS in
$nomatch)
AUTHD="no"
echo " - ${norunauthd}."
;;
*)
AUTHD="yes"
echo " - ${yesrunauthd}."
;;
esac
}
##########
# ConfigureBoot()
##########
ConfigureBoot()
{
NB=$1
if [ "X$INSTYPE" != "Xagent" ]; then
echo ""
$ECHO " $NB- ${startwazuh} ($yes/$no) [$yes]: "
if [ "X${USER_AUTO_START}" = "X" ]; then
read ANSWER
else
ANSWER=${USER_AUTO_START}
fi
echo ""
case $ANSWER in
$nomatch)
echo " - ${nowazuhstart}"
;;
*)
START_WAZUH="yes"
echo " - ${yeswazuhstart}"
;;
esac
fi
}
##########
# SetupLogs()
##########
SetupLogs()
{
NB=$1
echo ""
echo " $NB- ${readlogs}"
echo ""
WriteLogs "echo"
echo ""
catMsg "0x106-logs"
if [ "X$USER_NO_STOP" = "X" ]; then
read ANY
fi
}
##########
# ConfigureClient()
##########
ConfigureClient()
{
echo ""
echo "3- ${configuring} $NAME."
echo ""
if [ "X${USER_AGENT_SERVER_IP}" = "X" -a "X${USER_AGENT_SERVER_NAME}" = "X" ]; then
# Looping and asking for server ip or hostname
while [ 1 ]; do
$ECHO " 3.1- ${serveraddr}: "
read ADDRANSWER
# Is it an IP?
echo $ADDRANSWER | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" > /dev/null 2>&1
if [ $? = 0 ]; then
echo ""
SERVER_IP=$ADDRANSWER
echo " - ${addingip} $IP"
break;
# Must be a name
elif [ $? != 0 ]; then
echo ""
HNAME=$ADDRANSWER
echo " - ${addingname} $HNAME"
break;
fi
done
else
SERVER_IP=${USER_AGENT_SERVER_IP}
HNAME=${USER_AGENT_SERVER_NAME}
fi
# Syscheck?
UseSyscheck
# Rootcheck?
UseRootcheck
UseSyscollector
UseSecurityConfigurationAssessment
echo ""
$ECHO " 3.5 - ${enable_ar} ($yes/$no) [$yes]: "
if [ "X${USER_ENABLE_ACTIVE_RESPONSE}" = "X" ]; then
read ANY
else
ANY=${USER_ENABLE_ACTIVE_RESPONSE}
fi
case $ANY in
$nomatch)
echo ""
echo " - ${noactive}."
;;
*)
ACTIVERESPONSE="yes"
echo ""
echo " - ${yesactive}."
;;
esac
# Set up CA store
catMsg "0x109-castore"
AddCAStore
# Set up the log files
SetupLogs "3.7"
# Write configuration
WriteAgent
}
##########
# ConfigureServer()
##########
ConfigureServer()
{
echo ""
echo "3- ${configuring} $NAME."
# Configuring e-mail notification
echo ""
$ECHO " 3.1- ${mailnotify} ($yes/$no) [$no]: "
if [ "X${USER_ENABLE_EMAIL}" = "X" ]; then
read ANSWER
else
ANSWER=${USER_ENABLE_EMAIL}
fi
case $ANSWER in
$yesmatch)
EMAILNOTIFY="yes"
$ECHO " - ${whatsemail} "
if [ "X${USER_EMAIL_ADDRESS}" = "X" ]; then
read EMAIL
echo "${EMAIL}" | grep -E "^[a-zA-Z0-9_.+-]{1,36}@[a-zA-Z0-9_.-]{1,54}$" > /dev/null 2>&1 ;RVAL=$?;
# Ugly e-mail validation
while [ "$EMAIL" = "" -o ! ${RVAL} = 0 ] ; do
$ECHO " - ${whatsemail} "
read EMAIL
echo "${EMAIL}" | grep -E "^[a-zA-Z0-9_.+-]{1,36}@[a-zA-Z0-9_.-]{1,54}$" > /dev/null 2>&1 ;RVAL=$?;
done
else
EMAIL=${USER_EMAIL_ADDRESS}
fi
if [ -x "$HOST_CMD" ]; then
HOSTTMP=`${HOST_CMD} -W 5 -t mx wazuh.com 2>/dev/null`
if [ $? = 1 ]; then
# Trying without the -W
HOSTTMP=`${HOST_CMD} -t mx wazuh.com 2>/dev/null`
fi
echo "x$HOSTTMP" | grep "wazuh.com mail is handled" > /dev/null 2>&1
if [ $? = 0 ]; then
# Breaking down the user e-mail
EMAILHOST=`echo ${EMAIL} | cut -d "@" -f 2`
if [ "X${EMAILHOST}" = "Xlocalhost" ]; then
SMTPHOST="127.0.0.1"
else
HOSTTMP=`${HOST_CMD} -W 5 -t mx ${EMAILHOST}`
SMTPHOST=`echo ${HOSTTMP} | cut -d " " -f 7`
fi
fi
fi
if [ "X${USER_EMAIL_SMTP}" = "X" ]; then
if [ "X${SMTPHOST}" != "X" ]; then
echo ""
echo " - ${yoursmtp}: ${SMTPHOST}"
$ECHO " - ${usesmtp} ($yes/$no) [$yes]: "
read EMAIL2
case ${EMAIL2} in
$nomatch)
echo ""
SMTP=""
;;
*)
SMTP=${SMTPHOST}
echo ""
echo " --- ${usingsmtp} ${SMTP}"
;;
esac
fi
if [ "X${SMTP}" = "X" ]; then
$ECHO " - ${whatsmtp} "
read SMTP
fi
else
SMTP=${USER_EMAIL_SMTP}
fi
;;
*)
echo ""
echo " --- ${nomail}."
EMAILNOTIFY="no"
;;
esac
# Checking if syscheck should run
UseSyscheck
# Checking if rootcheck should run
UseRootcheck
UseSyscollector
UseSecurityConfigurationAssessment
# Active response
catMsg "0x107-ar"
echo ""
echo " - ${defaultwhitelist}"
for ip in ${NAMESERVERS} ${NAMESERVERS2};
do
if [ ! "X${ip}" = "X" -a ! "${ip}" = "0.0.0.0" ]; then
echo " - ${ip}"
fi
done
AddWhite
if [ "X$INSTYPE" = "Xserver" ]; then
# Configuring remote syslog
echo ""
$ECHO " 3.6- ${syslog} ($yes/$no) [$yes]: "
if [ "X${USER_ENABLE_SYSLOG}" = "X" ]; then
read ANSWER
else
ANSWER=${USER_ENABLE_SYSLOG}
fi
echo ""
case $ANSWER in
$nomatch)
echo " --- ${nosyslog}."
;;
*)
echo " - ${yessyslog}."
RLOG="yes"
;;
esac
# Configuring remote connections
SLOG="yes"
fi
UseSSLCert
# Setting up the auth daemon & logs
if [ "X$INSTYPE" = "Xserver" ]; then
EnableAuthd "3.7"
ConfigureBoot "3.8"
SetupLogs "3.9"
UseUpdateCheck
WriteManager
else
ConfigureBoot "3.6"
SetupLogs "3.7"
WriteLocal
fi
}
##########
# setInstallDir()
##########
setInstallDir()
{
if [ "X${USER_DIR}" = "X" ]; then
# If we don't have a value in USER_DIR, it means that the user
# should specify the installation directory.
while [ 1 ]; do
echo ""
$ECHO "2- ${wheretoinstall} [$INSTALLDIR]: "
read ANSWER
if [ ! "X$ANSWER" = "X" ]; then
echo $ANSWER |grep -E "^/[a-zA-Z0-9./_-]{3,128}$">/dev/null 2>&1
if [ $? = 0 ]; then
INSTALLDIR=$ANSWER;
break;
fi
else
break;
fi
done
else
# This else statement handles the case in which it was determined that the installation
# is an upgrade. So, the USER_DIR variable was previously set with the value of PREINSTALLEDDIR.
# Another possibility is that USER_DIR could have been set before running the script in
# order to run an unattended installation.
INSTALLDIR=${USER_DIR}
fi
}
##########
# setEnv()
##########
setEnv()
{
echo ""
echo " - ${installat} ${INSTALLDIR} ."
if [ "X$INSTYPE" = "Xagent" ]; then
CEXTRA="$CEXTRA -DCLIENT"
elif [ "X$INSTYPE" = "Xlocal" ]; then
CEXTRA="$CEXTRA -DLOCAL"
fi
}
##########
# askForDelete()
##########
askForDelete()
{
if [ -d "$INSTALLDIR" ]; then
if [ "X${USER_DELETE_DIR}" = "X" ]; then
echo ""
$ECHO " - ${deletedir} ($yes/$no) [$no]: "
read ANSWER
else
ANSWER=${USER_DELETE_DIR}
fi
case $ANSWER in
$yesmatch)
echo " Stopping Wazuh..."
UpdateStopOSSEC
rm -rf $INSTALLDIR
if [ ! $? = 0 ]; then
echo "Error deleting ${INSTALLDIR}"
exit 2;
fi
;;
esac
fi
}
##########
# checkDependencies()
# Thanks to [email protected]
##########
checkDependencies()
{
echo ""
OLDOPATH=$PATH
if [ "X$NUNAME" = "XSunOS" ]; then
PATH=$PATH:/usr/ccs/bin:/usr/xpg4/bin:/opt/csw/gcc3/bin:/opt/csw/bin:/usr/sfw/bin
export PATH
elif [ "X$NUNAME" = "XAIX" ]; then
PATH=$PATH:/usr/vac/bin
export PATH
fi
PATH=$OLDOPATH
export PATH
}
##########
# AddWhite()
##########
AddWhite()
{
while [ 1 ]
do
echo ""
$ECHO " - ${addwhite} ($yes/$no)? [$no]: "
# If white list is set, we don't need to ask it here.
if [ "X${USER_WHITE_LIST}" = "X" ]; then
read ANSWER
else
ANSWER=${USER_WHITE_LIST}
fi
if [ "X${ANSWER}" = "X" ] ; then
ANSWER=$no
fi
case $ANSWER in
$no)
break;
;;
*)
SET_WHITE_LIST="true"
$ECHO " - ${ipswhite}"
if [ "X${USER_WHITE_LIST}" = "X" ]; then
read IPS
else
IPS=${USER_WHITE_LIST}
fi
break;
;;
esac
done
}
##########
# AddCAStore()
##########
AddCAStore()
{
while [ 1 ]
do
echo ""
$ECHO " - ${addcastore} ($yes/$no)? [$no]: "
# If white list is set, we don't need to ask it here.
if [ "X${USER_CA_STORE}" = "X" ]; then
read ANSWER
else
ANSWER=${USER_CA_STORE}
fi
if [ "X${ANSWER}" = "X" ] ; then
ANSWER=$no
fi
case $ANSWER in
$no)
break;
;;
*)
SET_CA_STORE="true"
$ECHO " - ${castore}"
if [ "X${USER_CA_STORE}" = "X" ]; then
read CA_STORE
else
CA_STORE=${USER_CA_STORE}
fi
break;
;;
esac
done
# Check the certificate
if [ -n "$CA_STORE" ]
then
if [ -f $CA_STORE ]
then
if hash openssl 2>&1 > /dev/null && [ $(date -d "$(openssl x509 -enddate -noout -in $CA_STORE | cut -d = -f 2)" +%s) -lt $(date +%s) ]
then
echo ""
echo " Warning: the certificate at \"$CA_STORE\" is expired."
fi
elif [ ! -d $CA_STORE ]
then
echo ""
echo " Warning: No such file or directory \"$CA_STORE\"."
fi
fi
}
##########
# AddPFTable()
##########
AddPFTable()
{
#default pf rules
TABLE="wazuh_fwtable"
# Add table to the first line
echo ""
echo " - ${pfmessage}:"
echo " ${moreinfo}"
echo " https://documentation.wazuh.com"
echo ""
echo ""
echo " table <${TABLE}> persist #$TABLE "
echo " block in quick from <${TABLE}> to any"
echo " block out quick from any to <${TABLE}>"
echo ""
echo ""
}
##########
# main()
##########
main()
{
LG="en"
LANGUAGE="en"
. ./src/init/dist-detect.sh
. ./src/init/shared.sh
. ./src/init/functions.sh
# Reading pre-defined file
if [ ! `isFile ${PREDEF_FILE}` = "${FALSE}" ]; then
. ${PREDEF_FILE}
fi
# If user language is not set
if [ "X${USER_LANGUAGE}" = "X" ]; then
# Choosing the language.
while [ 1 ]; do
echo ""
for i in `ls ${TEMPLATE}`; do
# ignore CVS (should not be there anyways and config)
if [ "$i" = "CVS" -o "$i" = "config" ]; then continue; fi
cat "${TEMPLATE}/$i/language.txt"
if [ ! "$i" = "en" ]; then
LG="${LG}/$i"
fi
done
$ECHO " (${LG}) [en]: "
read USER_LG;
if [ "X${USER_LG}" = "X" ]; then
USER_LG="en"
fi
if [ -d "${TEMPLATE}/${USER_LG}" ]; then
break;
fi
done;
LANGUAGE=${USER_LG}
else
# If provided language is not valid, default to english
if [ -d "${TEMPLATE}/${USER_LANGUAGE}" ]; then
LANGUAGE=${USER_LANGUAGE}
else
LANGUAGE="en"
fi
fi # for USER_LANGUAGE
. ./src/init/language.sh
. ./src/init/init.sh
. ./src/init/wazuh/wazuh.sh
. ${TEMPLATE}/${LANGUAGE}/messages.txt
. ./src/init/inst-functions.sh
. ./src/init/template-select.sh
# Must be executed as ./install.sh
if [ `isFile ${VERSION_FILE}` = "${FALSE}" ]; then
catError "0x1-location";
fi
# Must be root
if [ ! "X$ME" = "Xroot" ]; then
catError "0x2-beroot";
fi
# Checking dependencies
checkDependencies
if [ "X$USER_NO_STOP" = "X" ]; then
clear 2> /dev/null
fi
# Initial message
echo " $NAME $VERSION (Rev. $REVISION) ${installscript} - https://www.wazuh.com"
catMsg "0x101-initial"
echo ""
echo " - $system: $UNAME (${DIST_NAME} ${DIST_VER}.${DIST_SUBVER})"
echo " - $user: $ME"
echo " - $host: $HOST"
echo ""
echo ""
echo " -- $hitanyorabort --"
if [ "X$USER_NO_STOP" = "X" ]; then
read ANY
fi
. ./src/init/update.sh
# Is this an update?
if getPreinstalledDir && [ "X${USER_CLEANINSTALL}" = "X" ]; then
echo ""
ct="1"
while [ $ct = "1" ]; do
ct="0"
$ECHO " - ${wanttoupdate} ($yes/$no): "
if [ "X${USER_UPDATE}" = "X" ]; then
read ANY
else
ANY=$yes
fi
case $ANY in
$yes)
update_only="yes"
break;
;;
$no)
echo ""
echo "${mustuninstall}"
exit 0;
;;
*)
ct="1"
;;
esac
done
# Do some of the update steps.
if [ "X${update_only}" = "Xyes" ]; then
. ./src/init/update.sh
if [ "`doUpdatecleanup`" = "${FALSE}" ]; then
# Disabling update
echo ""
echo "${unabletoupdate}"
sleep 5;
update_only=""
else
# Get update
USER_DIR="$PREINSTALLEDDIR"
USER_INSTALL_TYPE=`getPreinstalledType`
USER_OLD_VERSION=`getPreinstalledVersion`
USER_OLD_NAME=`getPreinstalledName`
USER_DELETE_DIR="$nomatch"
fi
ct="1"
# We dont need to update the rules on agent installs
if [ "X${USER_INSTALL_TYPE}" = "Xagent" ]; then
ct="0"
fi
fi
fi
# Setting up the installation type
hybrid="hybrid"
HYBID=""
hybridm=`echo ${hybrid} | cut -b 1`
serverm=`echo ${server} | cut -b 1`
localm=`echo ${local} | cut -b 1`
agentm=`echo ${agent} | cut -b 1`
helpm=`echo ${help} | cut -b 1`
# If user install type is not set, ask for it.
if [ "X${USER_INSTALL_TYPE}" = "X" ]; then
# Loop for the installation options
while [ 1 ]
do
echo ""
$ECHO "1- ${whattoinstall} "
read ANSWER
case $ANSWER in
${helpm}|${help})
catMsg "0x102-installhelp"
;;
${server}|${serverm}|"manager"|"m")
echo ""
echo " - ${serverchose}."
INSTYPE="server"
break;
;;
${agent}|${agentm}|"a")
echo ""
echo " - ${clientchose}."
INSTYPE="agent"
break;
;;
${hybrid}|${hybridm})
echo ""
echo " - ${serverchose} (hybrid)."
INSTYPE="server"
HYBID="go"
break;
;;
${local}|${localm})
echo ""
echo " - ${localchose}."
INSTYPE="local"
break;
;;
esac
done
else
INSTYPE=${USER_INSTALL_TYPE}
fi
# Setting up the installation directory
setInstallDir
# Setting up the environment
setEnv