forked from kduret/centreon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·427 lines (380 loc) · 14.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
#!/bin/bash
#----
## @Synopsis Install Script for Centreon project
## @Copyright Copyright 2008, Guillaume Watteeux
## @Copyright Copyright 2008-2020, Centreon
## @License GPL : http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
## Centreon Install Script
## Use
## <pre>
## Usage: sh install.sh [OPTION]
## Options:
## -f Input file with all variables define (use for with template)
## -u Input file with all variables define for update centreon
## -v Verbose mode
## -h print usage
## </pre>
#----
## Centreon is developed with GPL Licence 2.0
##
## GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
##
## Developed by : Julien Mathis - Romain Le Merlus
## Contributors : Guillaume Watteeux - Maximilien Bersoult
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## For information : [email protected]
#
#----
## Usage information for install.sh
## @Sdtout Usage information
#----
usage() {
local program=$0
echo -e "$(gettext "Usage: $program -f <file>")"
echo -e " -i\t$(gettext "install centreon")"
echo -e " -f\t$(gettext "file with all variable")"
echo -e " -u\t$(gettext "upgrade centreon with specify your directory with instCent* files")"
echo -e " -v\t$(gettext "verbose mode")"
exit 1
}
# define where is a centreon source
BASE_DIR=$(dirname $0)
## set directory
BASE_DIR=$( cd $BASE_DIR; pwd )
export BASE_DIR
if [ -z "${BASE_DIR#/}" ] ; then
echo -e "You cannot select the filesystem root folder"
exit 1
fi
INSTALL_DIR="$BASE_DIR/libinstall"
export INSTALL_DIR
INSTALL_VARS_DIR="$BASE_DIR/varinstall"
export INSTALL_VARS_DIR
PERL_LIB_DIR=`eval "\`perl -V:installvendorlib\`"; echo $installvendorlib`
# for freebsd
if [ "$PERL_LIB_DIR" = "" -o "$PERL_LIB_DIR" = "UNKNOWN" ]; then
PERL_LIB_DIR=`eval "\`perl -V:installsitelib\`"; echo $installsitelib`
fi
# define a locale directory for use gettext (LC_MESSAGE)
TEXTDOMAINDIR=$BASE_DIR/locale
export TEXTDOMAINDIR
TEXTDOMAIN=install.sh
export TEXTDOMAIN
# init variables
line="------------------------------------------------------------------------"
export line
## log default vars
. $INSTALL_VARS_DIR/vars
## Test if gettext was installed
# I use PATH variable to find
found="0"
OLDIFS="$IFS"
IFS=:
for p in $PATH ; do
if [ -x "$p/gettext.sh" ]; then
found="1"
. $p/gettext.sh
fi
done
IFS=$OLDIFS
if [ $found -eq 0 ] ; then # if not, use dummy gettext
PATH="$PATH:$INSTALL_DIR"
fi
## load all functions used in this script
. $INSTALL_DIR/functions
## Use TRAPs to call clean_and_exit when user press
## CRTL+C or exec kill -TERM.
trap clean_and_exit SIGINT SIGTERM
## Define a default log file
LOG_FILE=${LOG_FILE:=log\/install_centreon.log}
## Valid if you are root
if [ "${FORCE_NO_ROOT:-0}" -ne 0 ]; then
USERID=$(id -u)
if [ "$USERID" != "0" ]; then
echo -e "$(gettext "You must launch this script using a root user")"
exit 1
fi
fi
_tmp_install_opts="0"
silent_install="0"
upgrade="0"
user_install_vars=""
inst_upgrade_dir=""
use_upgrade_files="0"
#define cinstall options
cinstall_opts=""
## Getopts :)
# When you use options, by default I set silent_install to 1.
while getopts "if:u:hv" Options
do
case ${Options} in
i ) silent_install="0"
_tmp_install_opts="1"
;;
f ) silent_install="1"
user_install_vars="${OPTARG}"
_tmp_install_opts="1"
;;
u ) silent_install="1"
inst_upgrade_dir="${OPTARG%/}"
cinstall_opts="$cinstall_opts -f"
upgrade="1"
_tmp_install_opts="1"
;;
v ) cinstall_opts="$cinstall_opts -v"
# need one variable to parse debug log
;;
\?|h) usage ; exit 0 ;;
* ) usage ; exit 1 ;;
esac
done
if [ "$_tmp_install_opts" -eq 0 ] ; then
usage
exit 1
fi
#Export variable for all programs
export silent_install user_install_vars CENTREON_CONF cinstall_opts inst_upgrade_dir upgrade
## init LOG_FILE
# backup old log file...
[ ! -d "$LOG_DIR" ] && mkdir -p "$LOG_DIR"
if [ -e "$LOG_FILE" ] ; then
mv "$LOG_FILE" "$LOG_FILE.`date +%Y%m%d-%H%M%S`"
fi
# Clean (and create) my log file
${CAT} << __EOL__ > "$LOG_FILE"
__EOL__
# Init GREP,CAT,SED,CHMOD,CHOWN variables
define_specific_binary_vars
${CAT} << __EOT__
###############################################################################
# #
# Centreon (www.centreon.com) #
# #
# #
# Make sure you have installed and configured #
# centreon-gorgone - sudo - sed - php - apache - rrdtool - mysql #
# #
###############################################################################
__EOT__
## Test all binaries
BINARIES="rm cp mv ${CHMOD} ${CHOWN} echo more mkdir find ${GREP} ${CAT} ${SED}"
echo "$line"
echo -e "\t$(gettext "Checking all needed binaries")"
echo "$line"
binary_fail="0"
# For the moment, I check if all binary exists in path.
# After, I must look a solution to use complet path by binary
for binary in $BINARIES; do
if [ ! -e ${binary} ] ; then
pathfind "$binary"
if [ "$?" -eq 0 ] ; then
echo_success "${binary}" "$ok"
else
echo_failure "${binary}" "$fail"
log "ERR" "$(gettext "\$binary not found in \$PATH")"
binary_fail=1
fi
else
echo_success "${binary}" "$ok"
fi
done
###### Mandatory step
# ask if gorgone is already installed
echo -e "\n$line"
echo -e "\t$(gettext "Check mandatory gorgone service status")"
echo -e "$line"
yes_no_default "$(gettext "Is the Gorgone module already installed?")"
if [ "$?" -ne 0 ] ; then
echo_failure "\n$(gettext "Gorgone is required.\nPlease install it before launching this script")" "$fail"
echo -e "\n\t$(gettext "Please read the documentation to manage the Gorgone daemon installation")"
echo -e "\t$(gettext "Available on github") : https://github.com/centreon/centreon-gorgone"
echo -e "\t$(gettext "or on the centreon documentation") : https://documentation.centreon.com/\n"
exit 1
fi
# Script stop if one binary wasn't found
if [ "$binary_fail" -eq 1 ] ; then
echo_info "$(gettext "Please check fail binary and retry")"
exit 1
fi
# When you exec this script without file, you must valid a GPL licence.
if [ "$silent_install" -ne 1 ] ; then
echo -e "\n$(gettext "You will now read Centreon Licence.\\n\\tPress enter to continue.")"
read
tput clear
more "$BASE_DIR/LICENSE.md"
yes_no_default "$(gettext "Do you accept GPL license ?")"
if [ "$?" -ne 0 ] ; then
echo_info "$(gettext "As you did not accept the license, we cannot continue.")"
log "INFO" "Installation aborted - License not accepted"
exit 1
else
log "INFO" "Accepted the license"
fi
else
if [ "$upgrade" -eq 0 ] ; then
. $user_install_vars
fi
fi
if [ "$upgrade" -eq 1 ] ; then
# Test if instCent* file exist
if [ "$(ls $inst_upgrade_dir/instCent* | wc -l )" -ge 1 ] ; then
inst_upgrade_dir=${inst_upgrade_dir%/}
echo "$line"
echo -e "\t$(gettext "Detecting old installation")"
echo "$line"
echo_success "$(gettext "Finding configuration file in:") $inst_upgrade_dir" "$ok"
log "INFO" "$(gettext "Old configuration found in ") $(ls $inst_upgrade_dir/instCent*)"
echo_info "$(gettext "You seem to have an existing Centreon.")\n"
yes_no_default "$(gettext "Do you want to use the last Centreon install parameters ?")" "$yes"
if [ "$?" -eq 0 ] ; then
echo_passed "\n$(gettext "Using: ") $(ls $inst_upgrade_dir/instCent*)" "$ok"
use_upgrade_files="1"
fi
fi
fi
if [ "$silent_install" -ne 1 ] ; then
echo "$line"
echo -e "\t$(gettext "Please choose what you want to install")"
echo "$line"
fi
## init install process
# I prefer split install script.
# 0 = do not install
# 1 = install
# 2 = question in console
[ -z $PROCESS_CENTREON_WWW ] && PROCESS_CENTREON_WWW="2"
## For a moment, isn't possible to install standalone CentStorage daemon
## without CentWeb
[ -z $PROCESS_CENTSTORAGE ] && PROCESS_CENTSTORAGE="0"
[ -z $PROCESS_CENTREON_PLUGINS ] && PROCESS_CENTREON_PLUGINS="2"
[ -z $PROCESS_CENTREON_SNMP_TRAPS ] && PROCESS_CENTREON_SNMP_TRAPS="2"
## install centreon perl lib
if [ ! -d "$PERL_LIB_DIR/centreon/" ] ; then
mkdir "$PERL_LIB_DIR/centreon/"
log "INFO" "$(gettext "Created perl library directory")"
fi
## request centreon_www
if [ "$PROCESS_CENTREON_WWW" -eq 2 ] ; then
yes_no_default "$(gettext "Do you want to install") : Centreon Web Front"
if [ "$?" -eq 0 ] ; then
PROCESS_CENTREON_WWW="1"
log "INFO" "$(gettext "You chose to install") : Centreon Web Front"
## CentStorage dependency
PROCESS_CENTSTORAGE="1"
fi
fi
## request centreon_plugins
if [ "$PROCESS_CENTREON_PLUGINS" -eq 2 ] ; then
yes_no_default "$(gettext "Do you want to install") : Centreon Nagios Plugins"
if [ "$?" -eq 0 ] ; then
PROCESS_CENTREON_PLUGINS="1"
log "INFO" "$(gettext "You chose to install") : Centreon Nagios Plugins"
fi
fi
## request centreon_snmp_traps
if [ "$PROCESS_CENTREON_SNMP_TRAPS" -eq 2 ] ; then
yes_no_default "$(gettext "Do you want to install") : CentreonTrapd process"
if [ "$?" -eq 0 ] ; then
PROCESS_CENTREON_SNMP_TRAPS="1"
log "INFO" "$(gettext "You chose to install") : CentreonTrapd process"
fi
fi
## Start Centreon Web Front install
if [ "$PROCESS_CENTREON_WWW" -eq 1 ] ; then
if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentWeb.conf" ] ; then
log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentWeb.conf"
. $inst_upgrade_dir/instCentWeb.conf
if [ -n "$NAGIOS_USER" ]; then
echo_info "$(gettext "Convert variables for upgrade:")"
MONITORINGENGINE_USER=$NAGIOS_USER
[ -n "$NAGIOS_GROUP" ] && MONITORINGENGINE_GROUP=$NAGIOS_GROUP
[ -n "$NAGIOS_ETC" ] && MONITORINGENGINE_ETC=$NAGIOS_ETC
[ -n "$NAGIOS_BINARY" ] && MONITORINGENGINE_BINARY=$NAGIOS_BINARY
fi
fi
. $INSTALL_DIR/CentWeb.sh
fi
## Start CentStorage install
if [ "$PROCESS_CENTSTORAGE" -eq 1 ] ; then
if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentStorage.conf" ] ; then
log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentStorage.conf"
. $inst_upgrade_dir/instCentStorage.conf
if [ -n "$NAGIOS_USER" ]; then
echo_info "$(gettext "Convert variables for upgrade:")"
MONITORINGENGINE_USER=$NAGIOS_USER
[ -n "$NAGIOS_GROUP" ] && MONITORINGENGINE_GROUP=$NAGIOS_GROUP
fi
fi
. $INSTALL_DIR/CentStorage.sh
fi
## Start CentPlugins install
if [ "$PROCESS_CENTREON_PLUGINS" -eq 1 ] ; then
if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentPlugins.conf" ] ; then
log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentPlugins.conf"
. $inst_upgrade_dir/instCentPlugins.conf
if [ -n "$NAGIOS_USER" ]; then
echo_info "$(gettext "Convert variables for upgrade:")"
MONITORINGENGINE_USER=$NAGIOS_USER
[ -n "$NAGIOS_GROUP" ] && MONITORINGENGINE_GROUP=$NAGIOS_GROUP
[ -n "$NAGIOS_ETC" ] && MONITORINGENGINE_ETC=$NAGIOS_ETC
[ -n "$NAGIOS_PLUGIN" ] && PLUGIN_DIR=$NAGIOS_PLUGIN
fi
fi
. $INSTALL_DIR/CentPlugins.sh
fi
## Start CentPluginsTraps install
if [ "$PROCESS_CENTREON_SNMP_TRAPS" -eq 1 ] ; then
if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentPlugins.conf" ] ; then
log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentPlugins.conf"
. $inst_upgrade_dir/instCentPlugins.conf
if [ -n "$NAGIOS_USER" ]; then
echo_info "$(gettext "Convert variables for upgrade:")"
MONITORINGENGINE_USER=$NAGIOS_USER
[ -n "$NAGIOS_GROUP" ] && MONITORINGENGINE_GROUP=$NAGIOS_GROUP
[ -n "$NAGIOS_ETC" ] && MONITORINGENGINE_ETC=$NAGIOS_ETC
[ -n "$NAGIOS_PLUGIN" ] && PLUGIN_DIR=$NAGIOS_PLUGIN
fi
fi
. $INSTALL_DIR/CentPluginsTraps.sh
fi
## Purge working directories
purge_centreon_tmp_dir "silent"
server=$(hostname -f)
# Replace global variables
${CAT} << __EOT__
###############################################################################
# #
# Thanks for using Centreon. #
# ----------------------- #
# #
# Go to the URL : http://$server/centreon/ #
# to finish the setup #
# #
# Please read the documentation available here : #
# documentation.centreon.com #
# #
# ------------------------------------------------------------------ #
# #
# Report bugs at https://github.com/centreon/centreon/issues #
# #
# Contact : [email protected] #
# http://www.centreon.com #
# #
# ----------------------- #
# For security issues, please read our security policy #
# https://github.com/centreon/centreon/security/policy #
# #
###############################################################################
__EOT__
exit 0