| 1 | #!/bin/bash |
|---|
| 2 | #---- |
|---|
| 3 | ## @Synopsis Install Script for Centreon project |
|---|
| 4 | ## @Copyright Copyright 2008, Guillaume Watteeux |
|---|
| 5 | ## @License GPL : http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt |
|---|
| 6 | ## Centreon Install Script |
|---|
| 7 | ## Use |
|---|
| 8 | ## <pre> |
|---|
| 9 | ## Usage: bash install.sh [OPTION] |
|---|
| 10 | ## Options: |
|---|
| 11 | ## -f Input file with all variables define (use for with template) |
|---|
| 12 | ## -u Input file with all variables define for update centreon |
|---|
| 13 | ## -v Verbose mode |
|---|
| 14 | ## -h print usage |
|---|
| 15 | ## </pre> |
|---|
| 16 | #---- |
|---|
| 17 | ################################################################### |
|---|
| 18 | # Centreon is developped with GPL Licence 2.0 |
|---|
| 19 | # |
|---|
| 20 | # GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt |
|---|
| 21 | # |
|---|
| 22 | # Developped by : Julien Mathis - Romain Le Merlus |
|---|
| 23 | # Contribute : Guillaume Watteeux - Maximilien Bersoult |
|---|
| 24 | # |
|---|
| 25 | ################################################################### |
|---|
| 26 | # This program is free software; you can redistribute it and/or |
|---|
| 27 | # modify it under the terms of the GNU General Public License |
|---|
| 28 | # as published by the Free Software Foundation; either version 2 |
|---|
| 29 | # of the License, or (at your option) any later version. |
|---|
| 30 | # |
|---|
| 31 | # This program is distributed in the hope that it will be useful, |
|---|
| 32 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 33 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 34 | # GNU General Public License for more details. |
|---|
| 35 | # |
|---|
| 36 | # For information : infos@centreon.com |
|---|
| 37 | #################################################################### |
|---|
| 38 | # |
|---|
| 39 | # SVN: $URL$ |
|---|
| 40 | # SVN: $Rev$ |
|---|
| 41 | # SVN: $Author$ |
|---|
| 42 | # SVN: $Date$ |
|---|
| 43 | # SVN $Id$ |
|---|
| 44 | # |
|---|
| 45 | # |
|---|
| 46 | # Todo list |
|---|
| 47 | # - upgrade process |
|---|
| 48 | # -- 1.x --> 2.x |
|---|
| 49 | # -- 2.x --> 2.x+1 |
|---|
| 50 | # -- on upgrade, overwrite existing ? backup ? |
|---|
| 51 | |
|---|
| 52 | # Define centreon version |
|---|
| 53 | version="2.0-b6" |
|---|
| 54 | |
|---|
| 55 | # Debug |
|---|
| 56 | #set -x |
|---|
| 57 | |
|---|
| 58 | #---- |
|---|
| 59 | ## Usage informations for install.sh |
|---|
| 60 | ## @Sdtout Usage informations |
|---|
| 61 | #---- |
|---|
| 62 | function usage() { |
|---|
| 63 | local program=$0 |
|---|
| 64 | echo -e "$(gettext "Usage: $program -f <file>")" |
|---|
| 65 | echo -e " -i\t$(gettext "install centreon")" |
|---|
| 66 | echo -e " -f\t$(gettext "file with all variable")" |
|---|
| 67 | echo -e " -u\t$(gettext "upgrade centreon with specify your directory with instCent* files")" |
|---|
| 68 | echo -e " -v\t$(gettext "verbose mode")" |
|---|
| 69 | exit 1 |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | # define where is a centreon source |
|---|
| 73 | BASE_DIR=$(dirname $0) |
|---|
| 74 | ## set directory |
|---|
| 75 | BASE_DIR=$( cd $BASE_DIR; pwd ) |
|---|
| 76 | export BASE_DIR |
|---|
| 77 | if [ -z "${BASE_DIR#/}" ] ; then |
|---|
| 78 | echo -e "I think it is not right to have Centreon source on slash" |
|---|
| 79 | exit 1 |
|---|
| 80 | fi |
|---|
| 81 | INSTALL_DIR="$BASE_DIR/libinstall" |
|---|
| 82 | export INSTALL_DIR |
|---|
| 83 | INSTALL_VARS_DIR="$BASE_DIR/varinstall" |
|---|
| 84 | export INSTALL_VARS_DIR |
|---|
| 85 | |
|---|
| 86 | # define a locale directory for use gettext (LC_MESSAGE) |
|---|
| 87 | TEXTDOMAINDIR=$BASE_DIR/locale |
|---|
| 88 | export TEXTDOMAINDIR |
|---|
| 89 | TEXTDOMAIN=install.sh |
|---|
| 90 | export TEXTDOMAIN |
|---|
| 91 | |
|---|
| 92 | # init variables |
|---|
| 93 | line="------------------------------------------------------------------------" |
|---|
| 94 | export line |
|---|
| 95 | |
|---|
| 96 | ## log default vars |
|---|
| 97 | . $INSTALL_VARS_DIR/vars |
|---|
| 98 | |
|---|
| 99 | ## Test if gettext was installed |
|---|
| 100 | # I use PATH variable to find |
|---|
| 101 | found="0" |
|---|
| 102 | OLDIFS="$IFS" |
|---|
| 103 | IFS=: |
|---|
| 104 | for p in $PATH ; do |
|---|
| 105 | [ -x "$p/gettext" ] && found="1" |
|---|
| 106 | done |
|---|
| 107 | IFS=$OLDIFS |
|---|
| 108 | if [ $found -eq 1 ] ; then |
|---|
| 109 | . $INSTALL_DIR/gettext.sh |
|---|
| 110 | else |
|---|
| 111 | # if not, use my gettext dummy :p |
|---|
| 112 | PATH="$PATH:$INSTALL_DIR" |
|---|
| 113 | fi |
|---|
| 114 | |
|---|
| 115 | ## load all functions used in this script |
|---|
| 116 | . $INSTALL_DIR/functions |
|---|
| 117 | |
|---|
| 118 | ## Define a default log file |
|---|
| 119 | LOG_FILE=${LOG_FILE:=log\/install_centreon.log} |
|---|
| 120 | |
|---|
| 121 | ## Valid if you are root |
|---|
| 122 | USERID=`id -u` |
|---|
| 123 | if [ "$USERID" != "0" ]; then |
|---|
| 124 | echo -e "$(gettext "You must exec with root user")" |
|---|
| 125 | exit 1 |
|---|
| 126 | fi |
|---|
| 127 | |
|---|
| 128 | _tmp_install_opts="0" |
|---|
| 129 | silent_install="0" |
|---|
| 130 | upgrade="0" |
|---|
| 131 | user_install_vars="" |
|---|
| 132 | inst_upgrade_dir="" |
|---|
| 133 | use_upgrade_files="0" |
|---|
| 134 | |
|---|
| 135 | #define cinstall options |
|---|
| 136 | cinstall_opts="" |
|---|
| 137 | |
|---|
| 138 | ## Getopts :) |
|---|
| 139 | # When you use options, by default I set silent_install to 1. |
|---|
| 140 | while getopts "if:u:hv" Options |
|---|
| 141 | do |
|---|
| 142 | case ${Options} in |
|---|
| 143 | i ) silent_install="0" |
|---|
| 144 | _tmp_install_opts="1" |
|---|
| 145 | ;; |
|---|
| 146 | f ) silent_install="1" |
|---|
| 147 | user_install_vars="${OPTARG}" |
|---|
| 148 | _tmp_install_opts="1" |
|---|
| 149 | ;; |
|---|
| 150 | u ) silent_install="1" |
|---|
| 151 | inst_upgrade_dir="${OPTARG%/}" |
|---|
| 152 | cinstall_opts="$cinstall_opts -f" |
|---|
| 153 | upgrade="1" |
|---|
| 154 | _tmp_install_opts="1" |
|---|
| 155 | ;; |
|---|
| 156 | v ) cinstall_opts="$cinstall_opts -v" |
|---|
| 157 | # need one variable to parse debug log |
|---|
| 158 | ;; |
|---|
| 159 | \?|h) usage ; exit 0 ;; |
|---|
| 160 | * ) usage ; exit 1 ;; |
|---|
| 161 | esac |
|---|
| 162 | done |
|---|
| 163 | |
|---|
| 164 | if [ "$_tmp_install_opts" -eq 0 ] ; then |
|---|
| 165 | usage |
|---|
| 166 | exit 1 |
|---|
| 167 | fi |
|---|
| 168 | |
|---|
| 169 | #Export variable for all programs |
|---|
| 170 | export silent_install user_install_vars CENTREON_CONF cinstall_opts inst_upgrade_dir |
|---|
| 171 | |
|---|
| 172 | ## init LOG_FILE |
|---|
| 173 | # backup old log file... |
|---|
| 174 | [ ! -d "$LOG_DIR" ] && mkdir -p "$LOG_DIR" |
|---|
| 175 | if [ -e "$LOG_FILE" ] ; then |
|---|
| 176 | mv "$LOG_FILE" "$LOG_FILE.`date +%Y%m%d-%H%M%S`" |
|---|
| 177 | fi |
|---|
| 178 | # Clean (and create) my log file |
|---|
| 179 | ${CAT} << __EOL__ > "$LOG_FILE" |
|---|
| 180 | __EOL__ |
|---|
| 181 | |
|---|
| 182 | # Init GREP,CAT,SED,CHMOD,CHOWN variables |
|---|
| 183 | define_specific_binary_vars |
|---|
| 184 | |
|---|
| 185 | ${CAT} << __EOT__ |
|---|
| 186 | ############################################################################### |
|---|
| 187 | # # |
|---|
| 188 | # Centreon (www.centreon.com) # |
|---|
| 189 | # Thanks for using Centreon # |
|---|
| 190 | # # |
|---|
| 191 | # v$version # |
|---|
| 192 | # # |
|---|
| 193 | # infos@oreon-project.org # |
|---|
| 194 | # # |
|---|
| 195 | # Make sure you have installed and configured # |
|---|
| 196 | # sudo - sed - php - apache - rrdtool - mysql # |
|---|
| 197 | # # |
|---|
| 198 | ############################################################################### |
|---|
| 199 | __EOT__ |
|---|
| 200 | |
|---|
| 201 | ## Test all binaries |
|---|
| 202 | BINARIES="rm cp mv ${CHMOD} ${CHOWN} echo more mkdir find ${GREP} ${CAT} ${SED}" |
|---|
| 203 | |
|---|
| 204 | echo "$line" |
|---|
| 205 | echo -e "\t$(gettext "Checking all needed binaries")" |
|---|
| 206 | echo "$line" |
|---|
| 207 | |
|---|
| 208 | binary_fail="0" |
|---|
| 209 | # For the moment, I check if all binary exists in path. |
|---|
| 210 | # After, I must look a solution to use complet path by binary |
|---|
| 211 | for binary in $BINARIES; do |
|---|
| 212 | if [ ! -e ${binary} ] ; then |
|---|
| 213 | pathfind "$binary" |
|---|
| 214 | if [ "$?" -eq 0 ] ; then |
|---|
| 215 | echo_success "${binary}" "$ok" |
|---|
| 216 | else |
|---|
| 217 | echo_failure "${binary}" "$fail" |
|---|
| 218 | log "ERR" "$(gettext "\$binary not found in \$PATH")" |
|---|
| 219 | binary_fail=1 |
|---|
| 220 | fi |
|---|
| 221 | else |
|---|
| 222 | echo_success "${binary}" "$ok" |
|---|
| 223 | fi |
|---|
| 224 | done |
|---|
| 225 | |
|---|
| 226 | # Script stop if one binary wasn't found |
|---|
| 227 | if [ "$binary_fail" -eq 1 ] ; then |
|---|
| 228 | echo_info "$(gettext "Please check fail binary and retry")" |
|---|
| 229 | exit 1 |
|---|
| 230 | fi |
|---|
| 231 | |
|---|
| 232 | # When you exec this script without file, you must valid a GPL licence. |
|---|
| 233 | if [ "$silent_install" -ne 1 ] ; then |
|---|
| 234 | echo -e "\n$(gettext "You will now read Centreon Licence.\\n\\tPress enter to continue.")" |
|---|
| 235 | read |
|---|
| 236 | tput clear |
|---|
| 237 | more "$BASE_DIR/LICENSE" |
|---|
| 238 | |
|---|
| 239 | yes_no_default "$(gettext "Do you accept GPL license ?")" |
|---|
| 240 | if [ "$?" -ne 0 ] ; then |
|---|
| 241 | echo_info "$(gettext "You do not agree to GPL license ? Okay... have a nice day.")" |
|---|
| 242 | exit 1 |
|---|
| 243 | else |
|---|
| 244 | log "INFO" "$(gettext "You accepted GPL license")" |
|---|
| 245 | fi |
|---|
| 246 | else |
|---|
| 247 | if [ "$upgrade" -eq 0 ] ; then |
|---|
| 248 | . $user_install_vars |
|---|
| 249 | fi |
|---|
| 250 | fi |
|---|
| 251 | |
|---|
| 252 | # Check if is an upgrade or new install |
|---|
| 253 | # Use this on silent install ??? |
|---|
| 254 | # Check for old configfile |
|---|
| 255 | # use for centreon1.x upgrade |
|---|
| 256 | #### Move on upgrade specific script. |
|---|
| 257 | #if [ ! -z "`ls $CENTREON_CONF_1_4 2>/dev/null`" -a "$silent_install" -ne 1 ] ; then |
|---|
| 258 | # is_single "$CENTREON_CONF_1_4" |
|---|
| 259 | # if [ "$?" -eq 1 ] ; then |
|---|
| 260 | # echo -e "$(gettext "Please select a good centreon config file")" |
|---|
| 261 | # select_in_array "CENTREON_CONF" "${CENTREON_CONF_1_4[@]}" |
|---|
| 262 | # fi |
|---|
| 263 | #fi |
|---|
| 264 | |
|---|
| 265 | if [ "$upgrade" -eq 1 ] ; then |
|---|
| 266 | # Test if instCent* file exist |
|---|
| 267 | if [ "$(ls $inst_upgrade_dir/instCent* | wc -l )" -ge 1 ] ; then |
|---|
| 268 | inst_upgrade_dir=${inst_upgrade_dir%/} |
|---|
| 269 | echo "$line" |
|---|
| 270 | echo -e "\t$(gettext "Detecting old installation")" |
|---|
| 271 | echo "$line" |
|---|
| 272 | echo -e "\n\n" |
|---|
| 273 | echo_success "$(gettext "Finding configuration file in:") $inst_upgrade_dir" "$ok" |
|---|
| 274 | log "INFO" "$(gettext "Old configuration found in ") $(ls $inst_upgrade_dir/instCent*)" |
|---|
| 275 | echo_info "$(gettext "You seem to have an existing Centreon.")\n" |
|---|
| 276 | yes_no_default "$(gettext "Do you want to use the last Centreon install parameters ?")" "$yes" |
|---|
| 277 | if [ "$?" -eq 0 ] ; then |
|---|
| 278 | echo_passed "\n$(gettext "Using: ") $(ls $inst_upgrade_dir/instCent*)" |
|---|
| 279 | use_upgrade_files="1" |
|---|
| 280 | fi |
|---|
| 281 | fi |
|---|
| 282 | fi |
|---|
| 283 | |
|---|
| 284 | if [ "$silent_install" -ne 1 ] ; then |
|---|
| 285 | echo "$line" |
|---|
| 286 | echo -e "\t$(gettext "Please choose what you want to install")" |
|---|
| 287 | echo "$line" |
|---|
| 288 | fi |
|---|
| 289 | |
|---|
| 290 | ## init install process |
|---|
| 291 | # I prefer split install script. |
|---|
| 292 | # 0 = do not install |
|---|
| 293 | # 1 = install |
|---|
| 294 | # 2 = question in console |
|---|
| 295 | [ -z $PROCESS_CENTREON_WWW ] && PROCESS_CENTREON_WWW="2" |
|---|
| 296 | ## For a moment, isn't possible to install standalone CentStorage daemon |
|---|
| 297 | ## without CentWeb |
|---|
| 298 | [ -z $PROCESS_CENTSTORAGE ] && PROCESS_CENTSTORAGE="0" |
|---|
| 299 | [ -z $PROCESS_CENTCORE ] && PROCESS_CENTCORE="2" |
|---|
| 300 | [ -z $PROCESS_CENTREON_PLUGINS ] && PROCESS_CENTREON_PLUGINS="2" |
|---|
| 301 | [ -z $PROCESS_CENTREON_SNMP_TRAPS ] && PROCESS_CENTREON_SNMP_TRAPS="2" |
|---|
| 302 | |
|---|
| 303 | ## resquest centreon_www |
|---|
| 304 | if [ "$PROCESS_CENTREON_WWW" -eq 2 ] ; then |
|---|
| 305 | yes_no_default "$(gettext "Do you want to install") : Centreon Web Front" |
|---|
| 306 | if [ "$?" -eq 0 ] ; then |
|---|
| 307 | PROCESS_CENTREON_WWW="1" |
|---|
| 308 | log "INFO" "$(gettext "You chose to install") : Centreon Web Front" |
|---|
| 309 | ## CentStorage dependancy |
|---|
| 310 | PROCESS_CENTSTORAGE="1" |
|---|
| 311 | fi |
|---|
| 312 | fi |
|---|
| 313 | |
|---|
| 314 | ## resquest centreon_centstorage |
|---|
| 315 | # CentWeb/CentStorage dependancy |
|---|
| 316 | [ "$PROCESS_CENTREON_WWW" -eq 1 ] && PROCESS_CENTSTORAGE="1" |
|---|
| 317 | if [ "$PROCESS_CENTSTORAGE" -eq 2 ] ; then |
|---|
| 318 | yes_no_default "$(gettext "Do you want to install") : Centreon CentStorage" |
|---|
| 319 | if [ "$?" -eq 0 ] ; then |
|---|
| 320 | PROCESS_CENTSTORAGE="1" |
|---|
| 321 | log "INFO" "$(gettext "You chose to install") : Centreon CentStorage" |
|---|
| 322 | fi |
|---|
| 323 | fi |
|---|
| 324 | |
|---|
| 325 | ## resquest centreon_centcore |
|---|
| 326 | if [ "$PROCESS_CENTCORE" -eq 2 ] ; then |
|---|
| 327 | yes_no_default "$(gettext "Do you want to install") : Centreon CentCore" |
|---|
| 328 | if [ "$?" -eq 0 ] ; then |
|---|
| 329 | PROCESS_CENTCORE="1" |
|---|
| 330 | log "INFO" "$(gettext "You chose to install") : Centreon CentCore" |
|---|
| 331 | fi |
|---|
| 332 | fi |
|---|
| 333 | |
|---|
| 334 | ## resquest centreon_plugins |
|---|
| 335 | if [ "$PROCESS_CENTREON_PLUGINS" -eq 2 ] ; then |
|---|
| 336 | yes_no_default "$(gettext "Do you want to install") : Centreon Nagios Plugins" |
|---|
| 337 | if [ "$?" -eq 0 ] ; then |
|---|
| 338 | PROCESS_CENTREON_PLUGINS="1" |
|---|
| 339 | log "INFO" "$(gettext "You chose to install") : Centreon Nagios Plugins" |
|---|
| 340 | fi |
|---|
| 341 | fi |
|---|
| 342 | |
|---|
| 343 | ## resquest centreon_snmp_traps |
|---|
| 344 | if [ "$PROCESS_CENTREON_SNMP_TRAPS" -eq 2 ] ; then |
|---|
| 345 | yes_no_default "$(gettext "Do you want to install") : Centreon Snmp Traps process" |
|---|
| 346 | if [ "$?" -eq 0 ] ; then |
|---|
| 347 | PROCESS_CENTREON_SNMP_TRAPS="1" |
|---|
| 348 | log "INFO" "$(gettext "You chose to install") : Centreon Snmp Traps process" |
|---|
| 349 | fi |
|---|
| 350 | fi |
|---|
| 351 | |
|---|
| 352 | ## Start Centreon Web Front install |
|---|
| 353 | if [ "$PROCESS_CENTREON_WWW" -eq 1 ] ; then |
|---|
| 354 | if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentWeb.conf" ] ; then |
|---|
| 355 | log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentWeb.conf" |
|---|
| 356 | |
|---|
| 357 | . $inst_upgrade_dir/instCentWeb.conf |
|---|
| 358 | fi |
|---|
| 359 | . $INSTALL_DIR/CentWeb.sh |
|---|
| 360 | fi |
|---|
| 361 | |
|---|
| 362 | ## Start CentStorage install |
|---|
| 363 | if [ "$PROCESS_CENTSTORAGE" -eq 1 ] ; then |
|---|
| 364 | if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentStorage.conf" ] ; then |
|---|
| 365 | log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentStorage.conf" |
|---|
| 366 | |
|---|
| 367 | . $inst_upgrade_dir/instCentStorage.conf |
|---|
| 368 | fi |
|---|
| 369 | . $INSTALL_DIR/CentStorage.sh |
|---|
| 370 | fi |
|---|
| 371 | |
|---|
| 372 | ## Start CentCore install |
|---|
| 373 | if [ "$PROCESS_CENTCORE" -eq 1 ] ; then |
|---|
| 374 | if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentCore.conf" ] ; then |
|---|
| 375 | log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentCore.conf" |
|---|
| 376 | |
|---|
| 377 | . $inst_upgrade_dir/instCentCore.conf |
|---|
| 378 | fi |
|---|
| 379 | . $INSTALL_DIR/CentCore.sh |
|---|
| 380 | fi |
|---|
| 381 | |
|---|
| 382 | ## Start CentPlugins install |
|---|
| 383 | if [ "$PROCESS_CENTREON_PLUGINS" -eq 1 ] ; then |
|---|
| 384 | if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentPlugins.conf" ] ; then |
|---|
| 385 | log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentPlugins.conf" |
|---|
| 386 | |
|---|
| 387 | . $inst_upgrade_dir/instCentPlugins.conf |
|---|
| 388 | fi |
|---|
| 389 | . $INSTALL_DIR/CentPlugins.sh |
|---|
| 390 | fi |
|---|
| 391 | |
|---|
| 392 | ${CAT} << __EOT__ |
|---|
| 393 | ############################################################################### |
|---|
| 394 | # # |
|---|
| 395 | # Go to the URL : http://your-server/centreon/ # |
|---|
| 396 | # to finish the setup # |
|---|
| 397 | # # |
|---|
| 398 | # Report bugs at http://trac.centreon.com # |
|---|
| 399 | # # |
|---|
| 400 | # Thanks for using Centreon. # |
|---|
| 401 | # ----------------------- # |
|---|
| 402 | # Contact : infos@centreon.com # |
|---|
| 403 | # http://www.centreon.com # |
|---|
| 404 | # # |
|---|
| 405 | ############################################################################### |
|---|
| 406 | __EOT__ |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | exit 0 |
|---|