forked from Centreon-Community/centreon-discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
424 lines (380 loc) · 11.6 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
#!/bin/bash
# This file is part of Centreon-Discovery module.
#
# Centreon-Discovery 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.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses>.
#
# Module name: Centreon-Discovery
#
# First developpement by: Jean Marc Grisard - Christophe Coraboeuf
# Adaptation for Centreon 2.0 by: Merethis team
# Inspired from Watt's script.
#
# Modified by: Sub2.13
#
# WEBSITE: http://community.centreon.com/projects/centreon-discovery
# SVN: http://svn.modules.centreon.com/centreon-discovery
#---
## {Print help and usage}
##
## @Stdout Usage and Help program
#----
function usage() {
local program=$0
echo -e "\nUsage: $program -u <directory> / -r <directory> / -i -t <type> / -h"
echo -e " -i\tinstall Discovery module"
echo -e " -t\tdefine type install : central/poller/both"
echo -e " -u\tupgrade Discovery with specify your directory with instCentDisco.conf file"
echo -e " -r\tremove Discovery with specify your directory with instCentDisco.conf file"
echo -e " -h\tdisplay this message"
echo -e "\nExample for poller:"
echo -e " ./install.sh -i -t poller"
echo -e "\nExample for update:"
echo -e " ./install.sh -u /usr/share/centreon-discovery"
echo -e "\nExample for uninstall:"
echo -e " ./install.sh -r /usr/share/centreon-discovery"
exit 1
}
# define where is a centreon-module source
BASE_DIR=$(dirname $0)
## set directory
BASE_DIR=$( cd $BASE_DIR; pwd )
export BASE_DIR
if [ -z "${BASE_DIR#/}" ] ; then
echo -e "I think it is not right to have Centreon-Discovery source on slash"
exit 1
fi
INSTALL_DIR="$BASE_DIR/install"
export INSTALL_DIR
## load all functions used in this script
. $INSTALL_DIR/variables
. $INSTALL_DIR/display_functions
. $INSTALL_DIR/functions
if [ $# -eq 0 ] ; then
echo -e "No options found !"
usage;
exit 1;
fi
## Getopts
error="1"
while getopts "ir:u:t:h" Options ; do
case ${Options} in
i)
_tmp_install_opts="1"
UPDATE="1"
error="0"
;;
u)
UPDATE="0"
error="0"
DIR_CONF_DISCO=$OPTARG
if [ ! -d $DIR_CONF_DISCO ] ; then
echo -e "\"$DIR_CONF_DISCO\" is not a valid directory !"
usage;
exit 1
fi
;;
t)
TYPE_INSTALL=$OPTARG
error="0"
if [ $TYPE_INSTALL != "poller" ] && [ $TYPE_INSTALL != "central" ] && [ $TYPE_INSTALL != "both" ] ; then
echo -e "Type install incorrect !"
usage;
exit 1
fi
;;
r)
UPDATE="2"
error="0"
DIR_CONF_DISCO=$OPTARG
if [ ! -d $DIR_CONF_DISCO ] ; then
echo -e "\"$DIR_CONF_DISCO\" is not a valid directory !"
usage;
exit 1
fi
;;
\?|h)
usage;
exit 0
;;
*)
usage;
exit 1
;;
esac
done
if [ $error -eq 1 ] || [ $UPDATE -eq 1 ] && ( [ $_tmp_install_opts -eq 0 ] || ( [ "$TYPE_INSTALL" != "poller" ] && [ "$TYPE_INSTALL" != "central" ] && [ "$TYPE_INSTALL" != "both" ] )) ; then
usage;
exit 1
fi
### Main
echo "Waiting ..."
## Valid if you are root
USERID=`id -u`
if [ "$USERID" != "0" ]; then
echo -e "You must exec with root user"
exit 1
fi
#Export variable for all programs
export UPDATE CENTREON_CONF
## Define a default log file
LOG_DIR="$BASE_DIR/log"
if [ $UPDATE -eq 0 ] ; then
LOG_FILE="$PWD/update.log"
elif [ $UPDATE -eq 1 ] ; then
LOG_FILE="$PWD/install.log"
else
LOG_FILE="$PWD/uninstall.log"
fi
## init LOG_FILE
# backup old log file...
[ ! -d "$LOG_DIR" ] && mkdir -p "$LOG_DIR"
if [ -e "$LOG_FILE" ] ; then
/bin/mv "$LOG_FILE" "$LOG_FILE.`date +%Y%m%d-%H%M%S`"
fi
# Clean (and create) my log file
${CAT} << __EOL__ > "$LOG_FILE"
###############################################################################
command : $0 $@
###############################################################################
__EOL__
# Init GREP,CAT,SED,CHMOD,CHOWN variables
define_specific_binary_vars;
${CAT} << __EOT__
###############################################################################
# #
# http://community.centreon.com/projects/centreon-discovery #
# Thanks for using Centreon #
# #
# v$VERSION #
# #
###############################################################################
__EOT__
## Find OS
find_OS;
if [ $? -eq 0 ] ; then
echo_success "OS found: $DISTRIB" "$ok"
else
echo_failure "OS not found" "$fail"
exit 1
fi
BINARIES="rm cp mv ${CHMOD} ${CHOWN} echo more mkdir find ${GREP} ${CAT} ${SED} ${PYTHON} ${GCC}"
## binaries in function $TYPE_INSTALL
if [ "$TYPE_INSTALL" != "central" ] ; then
BINARIES=$BINARIES" ${NMAP}"
fi
## binaries/packages in function distrib
if [ "$DISTRIB" == "DEBIAN" ] || [ "$DISTRIB" == "UBUNTU" ] ; then
BINARIES=$BINARIES" ${DPKG}"
if [ "$TYPE_INSTALL" == "poller" ] ; then
PACKAGES="python-dev"
else
PACKAGES="python-dev libmysqlclient-dev"
fi
elif [ "$DISTRIB" == "REDHAT" ] || [ "$DISTRIB" == "CENTOS" ] ; then
BINARIES=$BINARIES" ${YUM}"
if [ "$TYPE_INSTALL" == "poller" ] ; then
PACKAGES="python-devel"
else
PACKAGES="python-devel mysql-devel"
fi
fi
# Check binaries
write_header "Checking all needed binaries" ""
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" "\$binary not found in \$PATH"
binary_fail=1
fi
else
echo_success "${binary}" "$ok"
fi
done
# Script stop if one binary wasn't found
if [ "$binary_fail" -eq 1 ] ; then
echo ""
echo_info "Please check fail binary/package and retry"
exit 1
fi
# Check packages for "install" and "update" cases
if [ $UPDATE -ne 2 ] ; then
check_list_packages;
fi
#if [ $UPDATE -eq 0 ] ; then
# write_header "Checking all needed packages"
# error=0
# for package in $PACKAGES; do
# echo -n $package
# check_package $package;
# if [ $? -eq 0 ] ; then
# #package not installed !
# display_return "1" "$package"
# error=1
# else
# #package installed !
# display_return "0" "$package"
# fi
# done
# if [ $error == 1 ]; then
# echo_info "\nPlease check fail packages and retry"
# exit 1
if [ $UPDATE -eq 0 ] ; then
# Case update
write_header "Detect previous installation" ""
check_old_install $DIR_CONF_DISCO/$FILE_CONF_DISCO;
echo -n "Loading parameters"
. $DIR_CONF_DISCO/$FILE_CONF_DISCO
display_return "$?" "Loading parameters"
get_centreon_parameters;
# Check version number
write_header "Checking version number" ""
check_version "$INSTALL_DIR/bin_version"
write_header "Install Python modules" ""
install_modPython;
if [ "$?" -eq 0 ] ; then
install_agent;
if [ "$TYPE_INSTALL" != "poller" ] ; then
execute_sql_update;
install_module;
fi
else
echo_failure "Modules Python weren't installed with success" "$fail"
echo -e "\tINSTALL ABORT"
exit 1
fi
else
if [ $UPDATE -eq 1 ] ; then
# Case clean install
# License
write_header "Accepting licence" ""
echo -e "You will now read Centreon Discovery module Licence.\\n\\tPress enter to continue."
read
tput clear
more "$BASE_DIR/LICENSE"
echo ""
yes_no_default "Do you accept GPL license ?"
if [ "$?" -ne 0 ] ; then
echo_info "You do not agree to GPL license ? Okay... have a nice day."
echo -e "\tINSTALL ABORT"
exit 1
else
log "INFO" "You accepted GPL license"
fi
# Check version number
write_header "Checking version number"
check_version "$INSTALL_DIR/bin_version"
write_header "Install Python modules" ""
install_modPython;
if [ "$?" -eq 0 ] ; then
if [ "$TYPE_INSTALL" != "poller" ] ; then
get_centreon_configuration_location;
get_centreon_parameters;
if [ "$?" -eq 0 ] ; then
echo ""
echo_success "Parameters were loaded with success" "$ok"
# NE PAS FACTORISER : "install_agent"
install_agent;
install_module;
else
echo -e "\nUnable to load all parameters in \"$FILE_CONF\""
echo -e "\tINSTALL ABORT"
exit 1
fi
else
install_agent;
fi
create_CentDiscoConf;
else
echo_failure "Modules Python weren't installed with success" "$fail"
echo -e "\tINSTALL ABORT"
exit 1
fi
else
# Case uninstall
write_header "Uninstall" ""
yes_no_default "Are you sure to uninstall totally Discovery module ?"
if [ "$?" -eq 0 ] ; then
write_header "Detect previous installation"
if [ -f $DIR_CONF_DISCO/$FILE_CONF_DISCO ] && [ `grep "# Discovery version" $DIR_CONF_DISCO/$FILE_CONF_DISCO | wc -l` -eq 1 ] ; then
echo -n "Loading parameters"
. $DIR_CONF_DISCO/$FILE_CONF_DISCO
display_return "$?" "Loading parameters"
else
echo_failure "Finding configuration file in: $DIR_CONF_DISCO" "$fail"
exit 1;
fi
get_centreon_parameters;
write_header "Deleting" ""
delete_module;
else
echo -e "Uninstall process canceled"
exit 0;
fi
fi
fi
# if [ "$TYPE_INSTALL" == "poller" ] ; then
# install_modPython;
# if [ "$?" -eq 0 ] ; then
# install_agent;
# else
# echo_failure "Modules Python weren't installed with success" "$fail"
# echo -e "\tINSTALL ABORT"
# exit 1
# fi
# else
# get_centreon_configuration_location;
# get_centreon_parameters;
# if [ "$?" -eq 0 ] ; then
# echo_success "Parameters were loaded with success" "$ok"
# else
# echo -e "\nUnable to load all parameters in \"$FILE_CONF\""
# echo -e "\tINSTALL ABORT"
# exit 1
# fi
# install_modPython;
# if [ "$?" -eq 0 ] ; then
# install_agent;
# install_module;
# else
# echo_failure "Modules Python weren't installed with success" "$fail"
# echo -e "\tINSTALL ABORT"
# exit 1
# fi
# fi
if [ $UPDATE -eq 0 ] ; then
echo_success "\nThe $LOG_VERSION update is finished" "$ok"
elif [ $UPDATE -eq 1 ] ; then
echo_success "\nThe $LOG_VERSION install is finished" "$ok"
else
echo_success "\nThe $LOG_VERSION uninstall is finished" "$ok"
fi
echo -e "See README and the log file for more details.\n"
${CAT} << __EOT__
###############################################################################
# #
# Go to the URL : http://your-server/centreon/ #
# to finish the setup in clean install case #
# #
# Report bugs at #
# http://community.centreon.com/projects/centreon-discovery/issues/new #
# #
###############################################################################
__EOT__
exit 0