forked from wazuh/wazuh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·265 lines (214 loc) · 5.36 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
#!/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
# 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 "${installing}"
echo ""
echo "DIR=\"${INSTALLDIR}\""
MAKEBIN=make
# Makefile
echo " - ${runningmake}"
echo ""
cd ./src
# Build compiled code.
BuildEngine
# Install
InstallWazuh
cd ../
# Calling the init script to start Wazuh during boot
runInit
runinit_value=$?
}
##########
# 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
}
##########
# 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
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
Install
# User messages
echo ""
echo " - ${configurationdone}."
echo ""
echo " - ${tostart}:"
echo " $INSTALLDIR/bin/wazuh-control start"
echo ""
echo " - ${tostop}:"
echo " $INSTALLDIR/bin/wazuh-control stop"
echo ""
echo ""
catMsg "0x103-thanksforusing"
echo ""
echo " - ${addserveragent}"
echo ""
echo " ${moreinfo}"
echo " https://documentation.wazuh.com/"
echo ""
if [ "X$notmodified" = "Xyes" ]; then
catMsg "0x105-noboot"
echo " $INSTALLDIR/bin/wazuh-control start"
echo ""
fi
}
_f_cfg="./install.cfg.sh"
if [ -f $_f_cfg ]; then
. $_f_cfg
fi
### Calling main function where everything happens
main
exit 0
#### exit ? ###