This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
install.sh
executable file
·353 lines (306 loc) · 10.2 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
#!/bin/bash
#
# Copyright 2005-2015 CENTREON
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0.
#
# 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.
#
# 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>.
#
# Linking this program statically or dynamically with other modules is making a
# combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination.
#
# As a special exception, the copyright holders of this program give CENTREON
# permission to link this program with independent modules to produce an executable,
# regardless of the license terms of these independent modules, and to copy and
# distribute the resulting executable under terms of CENTREON choice, provided that
# CENTREON also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version.
#
# For more information : [email protected]
#
# SVN : $URL
# SVN : $Id$
#
# List of files containing macros
MACRO_FILES="www/modules/centreon-clapi/core/class/centreon.Config.Poller.class.php"
MACRO_FILE_CONF="www/modules/centreon-clapi/etc/api.conf.php"
# Define Centreon Config Books version
NAME="centreon-clapi"
VERSION="1.8.1"
MODULE=$NAME.$VERSION
LOG_VERSION="$MODULE installation"
FILE_CONF="instCentWeb.conf"
CENTREON_CONF="/etc/centreon/"
MODULE_DIR="www/modules/centreon-clapi/"
INSTALL_DIR_CENTREON="0"
WEB_USER="0"
WEB_GROUP="0"
NAGIOS_USER="0"
NAGIOS_GROUP="0"
NAGIOS_PLUGIN="0"
BACKUP="www/modules/centreon-clapi-backup"
PWD=`pwd`
TEMP=/tmp/install.$$
PROGRAM="install.sh"
DB_USER="0";
DB_HOST="0";
DB_PASSWORD="0";
DB_BASE="0";
DB_CENTSTORAGE="0";
PHP_INI="0";
#---
## {Print help and usage}
##
## @Stdout Usage and Help program
#----
function usage() {
local program=$PROGRAM
echo -e "Usage: $program -i"
exit 1
}
#---
## {Get Centreon install dir and user/group for apache}
#----
function get_centreon_parameters() {
INSTALL_DIR_CENTREON=`cat $CENTREON_CONF/$FILE_CONF | grep "INSTALL_DIR_CENTREON" | cut -d '=' -f2`;
LOG_DIR_CENTREON=`cat $CENTREON_CONF/$FILE_CONF | grep "CENTREON_LOG" | cut -d '=' -f2`;
WEB_USER=`cat $CENTREON_CONF/$FILE_CONF | grep "WEB_USER" | cut -d '=' -f2`;
WEB_GROUP=`cat $CENTREON_CONF/$FILE_CONF | grep "WEB_GROUP" | cut -d '=' -f2`;
NAGIOS_PLUGIN=`cat $CENTREON_CONF/$FILE_CONF | grep "NAGIOS_PLUGIN" | cut -d '=' -f2`;
NAGIOS_VAR=`cat $CENTREON_CONF/$FILE_CONF | grep "NAGIOS_VAR" | cut -d '=' -f2`;
CENTREON_VARLIB=`cat $CENTREON_CONF/$FILE_CONF | grep "CENTREON_VARLIB" | cut -d '=' -f2 | sed -e 's|\s||g'`;
CENTREON_ETC=`cat $CENTREON_CONF/$FILE_CONF | grep "CENTREON_ETC" | cut -d '=' -f2`;
if [ "$INSTALL_DIR_CENTREON" != "" ] && [ "$WEB_USER" != "" ] && [ "$WEB_GROUP" != "" ] ; then
return 1;
else
return 0;
fi
}
#---
## {Get location of instCentWeb.conf file}
##
## @Stdout Error message if user set incorrect directory
## @Stdin Path with must contain $FILE_CONF
#----
function get_centreon_configuration_location() {
echo ""
echo "$line"
echo -e "\tLoad parameters"
echo "$line"
err=1
while [ $err != 0 ]
do
echo -e "Please specify the directory that contains \"$FILE_CONF\""
echo -en "> "
read temp_read
if [ -z "$temp_read" ]; then
echo_failure "The directory does not exist!" "$fail"
fi
if [ -d $temp_read ] && [ -f $temp_read/$FILE_CONF ] ; then
err=0
CENTREON_CONF=$temp_read
else
echo_failure "File \"$FILE_CONF\" does not exist in this directory!" "$fail"
fi
done
}
#---
## {Install Centreon CLAPI Module}
##
## @Stdout Actions realised by function
## @Stderr Log into $LOG_FILE
#----
function install_module() {
echo ""
echo "$line"
echo -e "\tCentreon CLAPI Module Installation"
echo "$line"
TEMP_D="/tmp/installation-clapi"
/bin/mkdir $TEMP_D >> $LOG_FILE 2>> $LOG_FILE
/bin/mkdir $TEMP_D/www >> $LOG_FILE 2>> $LOG_FILE
/bin/cp -Rf www/* $TEMP_D/www >> $LOG_FILE 2>> $LOG_FILE
/bin/rm -Rf $TEMP_D/install $TEMP_D/*.log
echo_success "Replacing macros" "$ok"
replace_macro $TEMP_D/$MACRO_FILES
replace_macro $TEMP_D/$MACRO_FILE_CONF
echo_success "Setting right" "$ok"
chmod -R 755 $TEMP_D/* >> $LOG_FILE 2>> $LOG_FILE
echo_success "Setting owner/group" "$ok"
/bin/chown -R $WEB_USER.$WEB_GROUP $TEMP_D/* >> $LOG_FILE 2>> $LOG_FILE
INSTALL_DIR_MODULE=$INSTALL_DIR_CENTREON/$MODULE_DIR
if [ -d $INSTALL_DIR_MODULE ] ; then
if [ -d $INSTALL_DIR_CENTREON/$BACKUP ] ; then
echo_success "Delete old Centreon CLAPI backup" "$ok"
/bin/rm -Rf $INSTALL_DIR_CENTREON/$BACKUP/*
else
echo_success "Create a directory to backup old files" "$ok"
/bin/mkdir $INSTALL_DIR_CENTREON/$BACKUP
fi
echo_success "Backup old installation" "$ok"
mv $INSTALL_DIR_MODULE/* $INSTALL_DIR_CENTREON/$BACKUP >> $LOG_FILE 2>> $LOG_FILE
fi
if [ ! -d $INSTALL_DIR_MODULE ] ; then
echo_success "Create module directory" "$ok"
/bin/mkdir $INSTALL_DIR_MODULE >> $LOG_FILE 2>> $LOG_FILE
/bin/chown -R $WEB_USER.$WEB_GROUP $INSTALL_DIR_MODULE >> $LOG_FILE 2>> $LOG_FILE
/bin/chmod -R 755 $INSTALL_DIR_MODULE >> $LOG_FILE 2>> $LOG_FILE
fi
chmod +x $TEMP_D/www/modules/centreon-clapi/core/centreon >> $LOG_FILE 2>> $LOG_FILE
dos2unix $TEMP_D/www/modules/centreon-clapi/core/centreon >> $LOG_FILE 2>> $LOG_FILE
echo_success "Copying module" "$ok"
/bin/cp -Rf --preserve $TEMP_D/www/* $INSTALL_DIR_CENTREON/www >> $LOG_FILE 2>> $LOG_FILE
echo_success "Delete temp install directory" "$ok"
/bin/rm -Rf $TEMP_D $TEMP >> $LOG_FILE 2>> $LOG_FILE
echo_success "\nThe $LOG_VERSION is finished" "$ok"
echo -e "See README and the log file for more details."
}
### Main
# 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 "I think it is not right to have Centreon source on slash"
exit 1
fi
INSTALL_DIR="$BASE_DIR/install"
export INSTALL_DIR
# init variables
line="------------------------------------------------------------------------"
export line
## log default vars
. $INSTALL_DIR/vars
## load all functions used in this script
. $INSTALL_DIR/functions
## Define a default log file
LOG_FILE="$PWD/install.log"
## Valid if you are root
USERID=`id -u`
if [ "$USERID" != "0" ]; then
echo "You must exec with root user"
exit 1
fi
_tmp_install_opts="0"
silent_install="0"
user_conf=""
## Getopts
while getopts "iu:h" Options
do
case ${Options} in
i ) _tmp_install_opts="1"
silent_install="0"
;;
u ) _tmp_install_opts="1"
silent_install="1"
user_conf="${OPTARG%/}"
;;
\?|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
## init LOG_FILE
# backup old log file...
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__
###############################################################################
# #
# Module : Centreon CLAPI version $VERSION #
# #
###############################################################################
__EOT__
## Test all binaries
BINARIES="rm cp mv ${CHMOD} ${CHOWN} echo more mkdir find ${GREP} ${CAT} ${SED}"
echo "$line"
echo -e "\tChecking 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" "\$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_info "Please check on your binaries and try again"
exit 1
fi
if [ "$silent_install" -eq 0 ] ; then
get_centreon_configuration_location;
get_centreon_parameters;
load_parameters=$?
if [ "$load_parameters" -eq 1 ] ; then
install_module;
else
echo -e "\nUnable to load all parameters in \"$FILE_CONF\""
exit 1
fi
fi
if [ "$silent_install" -eq 1 ] ; then
if [ -d $user_conf ] && [ -f $user_conf/$FILE_CONF ] ; then
CENTREON_CONF=$user_conf/;
get_centreon_parameters;
load_parameters=$?
if [ "$load_parameters" -eq 1 ] ; then
echo_success "Parameters was loaded with success" "$ok"
install_module;
else
echo_failure "Unable to load all parameters in \"$FILE_CONF\"" "$fail"
exit 1
fi
else
echo_failure "File \"$FILE_CONF\" does not exist in your specified directory!" "$fail"
exit 1
fi
fi
${CAT} << __EOT__
###############################################################################
# #
# Please go to the URL : http://your-server/centreon/ #
# to finish the setup #
# #
# #
###############################################################################
__EOT__
exit 0