-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstallMain.sh
executable file
·425 lines (372 loc) · 14.5 KB
/
installMain.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
# Wazuh installer - main functions
# Copyright (C) 2015, Wazuh Inc.
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.
function getHelp() {
echo -e ""
echo -e "NAME"
echo -e " $(basename "$0") - Install and configure Wazuh central components: Wazuh server, Wazuh indexer, and Wazuh dashboard."
echo -e ""
echo -e "SYNOPSIS"
echo -e " $(basename "$0") [OPTIONS] -a | -c | -s | -wi <indexer-node-name> | -wd <dashboard-node-name> | -ws <server-node-name>"
echo -e ""
echo -e "DESCRIPTION"
echo -e " -a, --all-in-one"
echo -e " Install and configure Wazuh server, Wazuh indexer, Wazuh dashboard."
echo -e ""
echo -e " -c, --config-file <path-to-config-yml>"
echo -e " Path to the configuration file used to generate wazuh-install-files.tar file containing the files that will be needed for installation. By default, the Wazuh installation assistant will search for a file named config.yml in the same path as the script."
echo -e ""
echo -e " -dw, --download-wazuh <deb|rpm>"
echo -e " Download all the packages necessary for offline installation. Type of packages to download for offline installation (rpm, deb)"
echo -e ""
echo -e " -fd, --force-install-dashboard"
echo -e " Force Wazuh dashboard installation to continue even when it is not capable of connecting to the Wazuh indexer."
echo -e ""
echo -e " -g, --generate-config-files"
echo -e " Generate wazuh-install-files.tar file containing the files that will be needed for installation from config.yml. In distributed deployments you will need to copy this file to all hosts."
echo -e ""
echo -e " -h, --help"
echo -e " Display this help and exit."
echo -e ""
echo -e " -i, --ignore-check"
echo -e " Ignore the check for minimum hardware requirements."
echo -e ""
echo -e " -o, --overwrite"
echo -e " Overwrites previously installed components. This will erase all the existing configuration and data."
echo -e ""
echo -e " -of, --offline-installation"
echo -e " Perform an offline installation. This option must be used with -a, -ws, -s, -wi, or -wd."
echo -e ""
echo -e " -p, --port"
echo -e " Specifies the Wazuh web user interface port. By default is the 443 TCP port. Recommended ports are: 8443, 8444, 8080, 8888, 9000."
echo -e ""
echo -e " -s, --start-cluster"
echo -e " Initialize Wazuh indexer cluster security settings."
echo -e ""
echo -e " -t, --tar <path-to-certs-tar>"
echo -e " Path to tar file containing certificate files. By default, the Wazuh installation assistant will search for a file named wazuh-install-files.tar in the same path as the script."
echo -e ""
echo -e " -u, --uninstall"
echo -e " Uninstalls all Wazuh components. This will erase all the existing configuration and data."
echo -e ""
echo -e " -v, --verbose"
echo -e " Shows the complete installation output."
echo -e ""
echo -e " -V, --version"
echo -e " Shows the version of the script and Wazuh packages."
echo -e ""
echo -e " -wd, --wazuh-dashboard <dashboard-node-name>"
echo -e " Install and configure Wazuh dashboard, used for distributed deployments."
echo -e ""
echo -e " -wi, --wazuh-indexer <indexer-node-name>"
echo -e " Install and configure Wazuh indexer, used for distributed deployments."
echo -e ""
echo -e " -ws, --wazuh-server <server-node-name>"
echo -e " Install and configure Wazuh manager and Filebeat, used for distributed deployments."
exit 1
}
function main() {
umask 177
if [ -z "${1}" ]; then
getHelp
fi
while [ -n "${1}" ]
do
case "${1}" in
"-a"|"--all-in-one")
AIO=1
shift 1
;;
"-c"|"--config-file")
if [ -z "${2}" ]; then
common_logger -e "Error on arguments. Probably missing <path-to-config-yml> after -c|--config-file"
getHelp
exit 1
fi
file_conf=1
config_file="${2}"
shift 2
;;
"-fd"|"--force-install-dashboard")
force=1
shift 1
;;
"-g"|"--generate-config-files")
configurations=1
shift 1
;;
"-h"|"--help")
getHelp
;;
"-i"|"--ignore-check")
ignore=1
shift 1
;;
"-o"|"--overwrite")
overwrite=1
shift 1
;;
"-of"|"--offline-installation")
offline_install=1
shift 1
;;
"-p"|"--port")
if [ -z "${2}" ]; then
common_logger -e "Error on arguments. Probably missing <port> after -p|--port"
getHelp
exit 1
fi
port_specified=1
port_number="${2}"
shift 2
;;
"-s"|"--start-cluster")
start_indexer_cluster=1
shift 1
;;
"-t"|"--tar")
if [ -z "${2}" ]; then
common_logger -e "Error on arguments. Probably missing <path-to-certs-tar> after -t|--tar"
getHelp
exit 1
fi
tar_conf=1
tar_file="${2}"
shift 2
;;
"-u"|"--uninstall")
uninstall=1
shift 1
;;
"-v"|"--verbose")
debugEnabled=1
debug="2>&1 | tee -a ${logfile}"
shift 1
;;
"-V"|"--version")
showVersion=1
shift 1
;;
"-wd"|"--wazuh-dashboard")
if [ -z "${2}" ]; then
common_logger -e "Error on arguments. Probably missing <node-name> after -wd|---wazuh-dashboard"
getHelp
exit 1
fi
dashboard=1
dashname="${2}"
shift 2
;;
"-wi"|"--wazuh-indexer")
if [ -z "${2}" ]; then
common_logger -e "Arguments contain errors. Probably missing <node-name> after -wi|--wazuh-indexer."
getHelp
exit 1
fi
indexer=1
indxname="${2}"
shift 2
;;
"-ws"|"--wazuh-server")
if [ -z "${2}" ]; then
common_logger -e "Error on arguments. Probably missing <node-name> after -ws|--wazuh-server"
getHelp
exit 1
fi
wazuh=1
winame="${2}"
shift 2
;;
"-dw"|"--download-wazuh")
if [ "${2}" != "deb" ] && [ "${2}" != "rpm" ]; then
common_logger -e "Error on arguments. Probably missing <deb|rpm> after -dw|--download-wazuh"
getHelp
exit 1
fi
download=1
package_type="${2}"
shift 2
;;
*)
echo "Unknow option: ${1}"
getHelp
esac
done
cat /dev/null > "${logfile}"
if [ -z "${download}" ] && [ -z "${showVersion}" ]; then
common_checkRoot
fi
if [ -n "${showVersion}" ]; then
common_logger "Wazuh version: ${wazuh_version}"
common_logger "Filebeat version: ${filebeat_version}"
common_logger "Wazuh installation assistant version: ${wazuh_install_vesion}"
exit 0
fi
common_logger "Starting Wazuh installation assistant. Wazuh version: ${wazuh_version}"
common_logger "Verbose logging redirected to ${logfile}"
# -------------- Uninstall case ------------------------------------
common_checkSystem
if [ -z "${download}" ]; then
check_dist
fi
if [ -z "${uninstall}" ] && [ -z "${offline_install}" ]; then
installCommon_installCheckDependencies
elif [ -n "${offline_install}" ]; then
offline_checkDependencies
fi
common_checkInstalled
checks_arguments
if [ -n "${uninstall}" ]; then
installCommon_rollBack
exit 0
fi
checks_arch
if [ -n "${ignore}" ]; then
common_logger -w "Hardware checks ignored."
else
common_logger "Verifying that your system meets the recommended minimum hardware requirements."
checks_health
fi
# -------------- Preliminary checks and Prerequisites --------------------------------
if [ -z "${configurations}" ] && [ -z "${AIO}" ] && [ -z "${download}" ]; then
checks_previousCertificate
fi
if [ -n "${port_specified}" ]; then
checks_available_port "${port_number}" "${wazuh_aio_ports[@]}"
dashboard_changePort "${port_number}"
elif [ -n "${AIO}" ] || [ -n "${dashboard}" ]; then
dashboard_changePort "${http_port}"
fi
if [ -n "${AIO}" ]; then
rm -f "${tar_file}"
checks_ports "${wazuh_aio_ports[@]}"
installCommon_installPrerequisites "AIO"
fi
if [ -n "${indexer}" ]; then
checks_ports "${wazuh_indexer_ports[@]}"
installCommon_installPrerequisites "indexer"
fi
if [ -n "${wazuh}" ]; then
checks_ports "${wazuh_manager_ports[@]}"
installCommon_installPrerequisites "wazuh"
fi
if [ -n "${dashboard}" ]; then
checks_ports "${wazuh_dashboard_port}"
installCommon_installPrerequisites "dashboard"
fi
# -------------- Wazuh repo ----------------------
# Offline installation case: extract the compressed files
if [ -n "${offline_install}" ]; then
offline_checkPreinstallation
offline_extractFiles
fi
if [ -n "${AIO}" ] || [ -n "${indexer}" ] || [ -n "${dashboard}" ] || [ -n "${wazuh}" ]; then
check_curlVersion
if [ -z "${offline_install}" ]; then
installCommon_addWazuhRepo
fi
fi
# -------------- Configuration creation case -----------------------
# Creation certificate case: Only AIO and -g option can create certificates.
if [ -n "${configurations}" ] || [ -n "${AIO}" ]; then
common_logger "--- Configuration files ---"
installCommon_createInstallFiles
fi
if [ -z "${configurations}" ] && [ -z "${download}" ]; then
installCommon_extractConfig
config_file="/tmp/wazuh-install-files/config.yml"
cert_readConfig
fi
# Distributed architecture: node names must be different
if [[ -z "${AIO}" && -z "${download}" && ( -n "${indexer}" || -n "${dashboard}" || -n "${wazuh}" ) ]]; then
checks_names
fi
if [ -n "${configurations}" ]; then
installCommon_removeWIADependencies
fi
# -------------- Wazuh indexer case -------------------------------
if [ -n "${indexer}" ]; then
common_logger "--- Wazuh indexer ---"
indexer_install
indexer_configure
installCommon_startService "wazuh-indexer"
indexer_initialize
installCommon_removeWIADependencies
fi
# -------------- Start Wazuh indexer cluster case ------------------
if [ -n "${start_indexer_cluster}" ]; then
indexer_startCluster
installCommon_changePasswords
installCommon_removeWIADependencies
fi
# -------------- Wazuh dashboard case ------------------------------
if [ -n "${dashboard}" ]; then
common_logger "--- Wazuh dashboard ----"
dashboard_install
dashboard_configure
installCommon_startService "wazuh-dashboard"
installCommon_changePasswords
dashboard_initialize
installCommon_removeWIADependencies
fi
# -------------- Wazuh server case ---------------------------------------
if [ -n "${wazuh}" ]; then
common_logger "--- Wazuh server ---"
manager_install
manager_configure
if [ -n "${server_node_types[*]}" ]; then
manager_startCluster
fi
installCommon_startService "wazuh-manager"
manager_checkService
filebeat_install
filebeat_configure
installCommon_changePasswords
installCommon_startService "filebeat"
filebeat_checkService
installCommon_removeWIADependencies
fi
# -------------- AIO case ------------------------------------------
if [ -n "${AIO}" ]; then
common_logger "--- Wazuh indexer ---"
indexer_install
indexer_configure
installCommon_startService "wazuh-indexer"
indexer_initialize
common_logger "--- Wazuh server ---"
manager_install
manager_configure
installCommon_startService "wazuh-manager"
manager_checkService
filebeat_install
filebeat_configure
installCommon_startService "filebeat"
filebeat_checkService
common_logger "--- Wazuh dashboard ---"
dashboard_install
dashboard_configure
installCommon_startService "wazuh-dashboard"
installCommon_changePasswords
dashboard_initializeAIO
installCommon_removeWIADependencies
fi
# -------------- Offline case ------------------------------------------
if [ -n "${download}" ]; then
common_logger "--- Download Packages ---"
offline_download
fi
# -------------------------------------------------------------------
if [ -z "${configurations}" ] && [ -z "${download}" ] && [ -z "${offline_install}" ]; then
installCommon_restoreWazuhrepo
fi
if [ -n "${AIO}" ] || [ -n "${indexer}" ] || [ -n "${dashboard}" ] || [ -n "${wazuh}" ]; then
eval "rm -rf /tmp/wazuh-install-files ${debug}"
common_logger "Installation finished."
elif [ -n "${start_indexer_cluster}" ]; then
common_logger "Wazuh indexer cluster started."
fi
}