PageRenderTime 64ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/install.sh

https://gitlab.com/florianocomercial/centreon
Shell | 461 lines | 269 code | 49 blank | 143 comment | 72 complexity | 44db43c5186d7eed3d6bcd5f670f1b6a MD5 | raw file
  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: 11632 $
  41. # SVN: $Author$
  42. # SVN: $Date: 2011-02-08 18:04:05 +0100 (mar., 08 févr. 2011) $
  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. # Define centreon version
  52. version="2.7.4"
  53. # Debug
  54. #set -x
  55. #----
  56. ## Usage informations for install.sh
  57. ## @Sdtout Usage informations
  58. #----
  59. function usage() {
  60. local program=$0
  61. echo -e "$(gettext "Usage: $program -f <file>")"
  62. echo -e " -i\t$(gettext "install centreon")"
  63. echo -e " -f\t$(gettext "file with all variable")"
  64. echo -e " -u\t$(gettext "upgrade centreon with specify your directory with instCent* files")"
  65. echo -e " -v\t$(gettext "verbose mode")"
  66. exit 1
  67. }
  68. # define where is a centreon source
  69. BASE_DIR=$(dirname $0)
  70. ## set directory
  71. BASE_DIR=$( cd $BASE_DIR; pwd )
  72. export BASE_DIR
  73. if [ -z "${BASE_DIR#/}" ] ; then
  74. echo -e "I think it is not right to have Centreon source on slash"
  75. exit 1
  76. fi
  77. INSTALL_DIR="$BASE_DIR/libinstall"
  78. export INSTALL_DIR
  79. INSTALL_VARS_DIR="$BASE_DIR/varinstall"
  80. export INSTALL_VARS_DIR
  81. PERL_LIB_DIR=`eval "\`perl -V:installvendorlib\`"; echo $installvendorlib`
  82. # for freebsd
  83. if [ "$PERL_LIB_DIR" = "" -o "$PERL_LIB_DIR" = "UNKNOWN" ]; then
  84. PERL_LIB_DIR=`eval "\`perl -V:installsitelib\`"; echo $installsitelib`
  85. fi
  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. # init variables
  92. line="------------------------------------------------------------------------"
  93. export line
  94. ## log default vars
  95. . $INSTALL_VARS_DIR/vars
  96. ## Test if gettext was installed
  97. # I use PATH variable to find
  98. found="0"
  99. OLDIFS="$IFS"
  100. IFS=:
  101. for p in $PATH ; do
  102. [ -x "$p/gettext" ] && found="1"
  103. done
  104. IFS=$OLDIFS
  105. if [ $found -eq 1 ] ; then
  106. . $INSTALL_DIR/gettext.sh
  107. else
  108. # if not, use my gettext dummy :p
  109. PATH="$PATH:$INSTALL_DIR"
  110. fi
  111. ## load all functions used in this script
  112. . $INSTALL_DIR/functions
  113. ## Use TRAPs to call clean_and_exit when user press
  114. ## CRTL+C or exec kill -TERM.
  115. trap clean_and_exit SIGINT SIGTERM
  116. ## Define a default log file
  117. LOG_FILE=${LOG_FILE:=log\/install_centreon.log}
  118. ## Valid if you are root
  119. if [ "${FORCE_NO_ROOT:-0}" -ne 0 ]; then
  120. USERID=$(id -u)
  121. if [ "$USERID" != "0" ]; then
  122. echo -e "$(gettext "You must exec with root user")"
  123. exit 1
  124. fi
  125. fi
  126. _tmp_install_opts="0"
  127. silent_install="0"
  128. upgrade="0"
  129. user_install_vars=""
  130. inst_upgrade_dir=""
  131. use_upgrade_files="0"
  132. #define cinstall options
  133. cinstall_opts=""
  134. ## Getopts :)
  135. # When you use options, by default I set silent_install to 1.
  136. while getopts "if:u:hv" Options
  137. do
  138. case ${Options} in
  139. i ) silent_install="0"
  140. _tmp_install_opts="1"
  141. ;;
  142. f ) silent_install="1"
  143. user_install_vars="${OPTARG}"
  144. _tmp_install_opts="1"
  145. ;;
  146. u ) silent_install="1"
  147. inst_upgrade_dir="${OPTARG%/}"
  148. cinstall_opts="$cinstall_opts -f"
  149. upgrade="1"
  150. _tmp_install_opts="1"
  151. ;;
  152. v ) cinstall_opts="$cinstall_opts -v"
  153. # need one variable to parse debug log
  154. ;;
  155. \?|h) usage ; exit 0 ;;
  156. * ) usage ; exit 1 ;;
  157. esac
  158. done
  159. if [ "$_tmp_install_opts" -eq 0 ] ; then
  160. usage
  161. exit 1
  162. fi
  163. #Export variable for all programs
  164. export silent_install user_install_vars CENTREON_CONF cinstall_opts inst_upgrade_dir
  165. ## init LOG_FILE
  166. # backup old log file...
  167. [ ! -d "$LOG_DIR" ] && mkdir -p "$LOG_DIR"
  168. if [ -e "$LOG_FILE" ] ; then
  169. mv "$LOG_FILE" "$LOG_FILE.`date +%Y%m%d-%H%M%S`"
  170. fi
  171. # Clean (and create) my log file
  172. ${CAT} << __EOL__ > "$LOG_FILE"
  173. __EOL__
  174. # Init GREP,CAT,SED,CHMOD,CHOWN variables
  175. define_specific_binary_vars
  176. ${CAT} << __EOT__
  177. ###############################################################################
  178. # #
  179. # Centreon (www.centreon.com) #
  180. # Thanks for using Centreon #
  181. # #
  182. # v$version #
  183. # #
  184. # infos@centreon.com #
  185. # #
  186. # Make sure you have installed and configured #
  187. # sudo - sed - php - apache - rrdtool - mysql #
  188. # #
  189. ###############################################################################
  190. __EOT__
  191. ## Test all binaries
  192. BINARIES="rm cp mv ${CHMOD} ${CHOWN} echo more mkdir find ${GREP} ${CAT} ${SED}"
  193. echo "$line"
  194. echo -e "\t$(gettext "Checking all needed binaries")"
  195. echo "$line"
  196. binary_fail="0"
  197. # For the moment, I check if all binary exists in path.
  198. # After, I must look a solution to use complet path by binary
  199. for binary in $BINARIES; do
  200. if [ ! -e ${binary} ] ; then
  201. pathfind "$binary"
  202. if [ "$?" -eq 0 ] ; then
  203. echo_success "${binary}" "$ok"
  204. else
  205. echo_failure "${binary}" "$fail"
  206. log "ERR" "$(gettext "\$binary not found in \$PATH")"
  207. binary_fail=1
  208. fi
  209. else
  210. echo_success "${binary}" "$ok"
  211. fi
  212. done
  213. # Script stop if one binary wasn't found
  214. if [ "$binary_fail" -eq 1 ] ; then
  215. echo_info "$(gettext "Please check fail binary and retry")"
  216. exit 1
  217. fi
  218. # When you exec this script without file, you must valid a GPL licence.
  219. if [ "$silent_install" -ne 1 ] ; then
  220. echo -e "\n$(gettext "You will now read Centreon Licence.\\n\\tPress enter to continue.")"
  221. read
  222. tput clear
  223. more "$BASE_DIR/LICENSE"
  224. yes_no_default "$(gettext "Do you accept GPL license ?")"
  225. if [ "$?" -ne 0 ] ; then
  226. echo_info "$(gettext "You do not agree to GPL license ? Okay... have a nice day.")"
  227. exit 1
  228. else
  229. log "INFO" "$(gettext "You accepted GPL license")"
  230. fi
  231. else
  232. if [ "$upgrade" -eq 0 ] ; then
  233. . $user_install_vars
  234. fi
  235. fi
  236. # Check if is an upgrade or new install
  237. # Use this on silent install ???
  238. # Check for old configfile
  239. # use for centreon1.x upgrade
  240. #### Move on upgrade specific script.
  241. #if [ ! -z "`ls $CENTREON_CONF_1_4 2>/dev/null`" -a "$silent_install" -ne 1 ] ; then
  242. # is_single "$CENTREON_CONF_1_4"
  243. # if [ "$?" -eq 1 ] ; then
  244. # echo -e "$(gettext "Please select a good centreon config file")"
  245. # select_in_array "CENTREON_CONF" "${CENTREON_CONF_1_4[@]}"
  246. # fi
  247. #fi
  248. if [ "$upgrade" -eq 1 ] ; then
  249. # Test if instCent* file exist
  250. if [ "$(ls $inst_upgrade_dir/instCent* | wc -l )" -ge 1 ] ; then
  251. inst_upgrade_dir=${inst_upgrade_dir%/}
  252. echo "$line"
  253. echo -e "\t$(gettext "Detecting old installation")"
  254. echo "$line"
  255. echo_success "$(gettext "Finding configuration file in:") $inst_upgrade_dir" "$ok"
  256. log "INFO" "$(gettext "Old configuration found in ") $(ls $inst_upgrade_dir/instCent*)"
  257. echo_info "$(gettext "You seem to have an existing Centreon.")\n"
  258. yes_no_default "$(gettext "Do you want to use the last Centreon install parameters ?")" "$yes"
  259. if [ "$?" -eq 0 ] ; then
  260. echo_passed "\n$(gettext "Using: ") $(ls $inst_upgrade_dir/instCent*)"
  261. use_upgrade_files="1"
  262. fi
  263. fi
  264. fi
  265. if [ "$silent_install" -ne 1 ] ; then
  266. echo "$line"
  267. echo -e "\t$(gettext "Please choose what you want to install")"
  268. echo "$line"
  269. fi
  270. ## init install process
  271. # I prefer split install script.
  272. # 0 = do not install
  273. # 1 = install
  274. # 2 = question in console
  275. [ -z $PROCESS_CENTREON_WWW ] && PROCESS_CENTREON_WWW="2"
  276. ## For a moment, isn't possible to install standalone CentStorage daemon
  277. ## without CentWeb
  278. [ -z $PROCESS_CENTSTORAGE ] && PROCESS_CENTSTORAGE="0"
  279. [ -z $PROCESS_CENTCORE ] && PROCESS_CENTCORE="2"
  280. [ -z $PROCESS_CENTREON_PLUGINS ] && PROCESS_CENTREON_PLUGINS="2"
  281. [ -z $PROCESS_CENTREON_SNMP_TRAPS ] && PROCESS_CENTREON_SNMP_TRAPS="2"
  282. ## install centreon perl lib
  283. if [ ! -d "$PERL_LIB_DIR/centreon/" ] ; then
  284. mkdir "$PERL_LIB_DIR/centreon/"
  285. log "INFO" "$(gettext "Created perl library directory")"
  286. fi
  287. ## resquest centreon_www
  288. if [ "$PROCESS_CENTREON_WWW" -eq 2 ] ; then
  289. yes_no_default "$(gettext "Do you want to install") : Centreon Web Front"
  290. if [ "$?" -eq 0 ] ; then
  291. PROCESS_CENTREON_WWW="1"
  292. log "INFO" "$(gettext "You chose to install") : Centreon Web Front"
  293. ## CentStorage dependency
  294. PROCESS_CENTSTORAGE="1"
  295. fi
  296. fi
  297. ## resquest centreon_centcore
  298. if [ "$PROCESS_CENTCORE" -eq 2 ] ; then
  299. yes_no_default "$(gettext "Do you want to install") : Centreon CentCore"
  300. if [ "$?" -eq 0 ] ; then
  301. PROCESS_CENTCORE="1"
  302. log "INFO" "$(gettext "You chose to install") : Centreon CentCore"
  303. fi
  304. fi
  305. ## resquest centreon_plugins
  306. if [ "$PROCESS_CENTREON_PLUGINS" -eq 2 ] ; then
  307. yes_no_default "$(gettext "Do you want to install") : Centreon Nagios Plugins"
  308. if [ "$?" -eq 0 ] ; then
  309. PROCESS_CENTREON_PLUGINS="1"
  310. log "INFO" "$(gettext "You chose to install") : Centreon Nagios Plugins"
  311. fi
  312. fi
  313. ## resquest centreon_snmp_traps
  314. if [ "$PROCESS_CENTREON_SNMP_TRAPS" -eq 2 ] ; then
  315. yes_no_default "$(gettext "Do you want to install") : CentreonTrapd process"
  316. if [ "$?" -eq 0 ] ; then
  317. PROCESS_CENTREON_SNMP_TRAPS="1"
  318. log "INFO" "$(gettext "You chose to install") : CentreonTrapd process"
  319. fi
  320. fi
  321. ## Start Centreon Web Front install
  322. if [ "$PROCESS_CENTREON_WWW" -eq 1 ] ; then
  323. if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentWeb.conf" ] ; then
  324. log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentWeb.conf"
  325. . $inst_upgrade_dir/instCentWeb.conf
  326. if [ -n "$NAGIOS_USER" ]; then
  327. echo_info "$(gettext "Convert variables for upgrade:")"
  328. MONITORINGENGINE_USER=$NAGIOS_USER
  329. [ -n "$NAGIOS_GROUP" ] && MONITORINGENGINE_GROUP=$NAGIOS_GROUP
  330. [ -n "$NAGIOS_ETC" ] && MONITORINGENGINE_ETC=$NAGIOS_ETC
  331. [ -n "$NAGIOS_BINARY" ] && MONITORINGENGINE_BINARY=$NAGIOS_BINARY
  332. [ -n "$NAGIOS_INIT_SCRIPT" ] && MONITORINGENGINE_INIT_SCRIPT=$NAGIOS_INIT_SCRIPT
  333. fi
  334. fi
  335. . $INSTALL_DIR/CentWeb.sh
  336. fi
  337. ## Start CentStorage install
  338. if [ "$PROCESS_CENTSTORAGE" -eq 1 ] ; then
  339. if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentStorage.conf" ] ; then
  340. log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentStorage.conf"
  341. . $inst_upgrade_dir/instCentStorage.conf
  342. if [ -n "$NAGIOS_USER" ]; then
  343. echo_info "$(gettext "Convert variables for upgrade:")"
  344. MONITORINGENGINE_USER=$NAGIOS_USER
  345. [ -n "$NAGIOS_GROUP" ] && MONITORINGENGINE_GROUP=$NAGIOS_GROUP
  346. fi
  347. fi
  348. . $INSTALL_DIR/CentStorage.sh
  349. fi
  350. ## Start CentCore install
  351. if [ "$PROCESS_CENTCORE" -eq 1 ] ; then
  352. if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentCore.conf" ] ; then
  353. log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentCore.conf"
  354. . $inst_upgrade_dir/instCentCore.conf
  355. if [ -n "$NAGIOS_USER" ]; then
  356. echo_info "$(gettext "Convert variables for upgrade:")"
  357. MONITORINGENGINE_USER=$NAGIOS_USER
  358. [ -n "$NAGIOS_GROUP" ] && MONITORINGENGINE_GROUP=$NAGIOS_GROUP
  359. [ -n "$NAGIOS_ETC" ] && MONITORINGENGINE_ETC=$NAGIOS_ETC
  360. fi
  361. fi
  362. . $INSTALL_DIR/CentCore.sh
  363. fi
  364. ## Start CentPlugins install
  365. if [ "$PROCESS_CENTREON_PLUGINS" -eq 1 ] ; then
  366. if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentPlugins.conf" ] ; then
  367. log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentPlugins.conf"
  368. . $inst_upgrade_dir/instCentPlugins.conf
  369. if [ -n "$NAGIOS_USER" ]; then
  370. echo_info "$(gettext "Convert variables for upgrade:")"
  371. MONITORINGENGINE_USER=$NAGIOS_USER
  372. [ -n "$NAGIOS_GROUP" ] && MONITORINGENGINE_GROUP=$NAGIOS_GROUP
  373. [ -n "$NAGIOS_ETC" ] && MONITORINGENGINE_ETC=$NAGIOS_ETC
  374. [ -n "$NAGIOS_PLUGIN" ] && PLUGIN_DIR=$NAGIOS_PLUGIN
  375. fi
  376. fi
  377. . $INSTALL_DIR/CentPlugins.sh
  378. fi
  379. ## Start CentPluginsTraps install
  380. if [ "$PROCESS_CENTREON_SNMP_TRAPS" -eq 1 ] ; then
  381. if [ "$use_upgrade_files" -eq 1 -a -e "$inst_upgrade_dir/instCentPlugins.conf" ] ; then
  382. log "INFO" "$(gettext "Load variables:") $inst_upgrade_dir/instCentPlugins.conf"
  383. . $inst_upgrade_dir/instCentPlugins.conf
  384. if [ -n "$NAGIOS_USER" ]; then
  385. echo_info "$(gettext "Convert variables for upgrade:")"
  386. MONITORINGENGINE_USER=$NAGIOS_USER
  387. [ -n "$NAGIOS_GROUP" ] && MONITORINGENGINE_GROUP=$NAGIOS_GROUP
  388. [ -n "$NAGIOS_ETC" ] && MONITORINGENGINE_ETC=$NAGIOS_ETC
  389. [ -n "$NAGIOS_PLUGIN" ] && PLUGIN_DIR=$NAGIOS_PLUGIN
  390. fi
  391. fi
  392. . $INSTALL_DIR/CentPluginsTraps.sh
  393. fi
  394. ## Purge working directories
  395. purge_centreon_tmp_dir "silent"
  396. server=$(hostname -f)
  397. ${CAT} << __EOT__
  398. ###############################################################################
  399. # #
  400. # Go to the URL : http://$server/centreon/ #
  401. # to finish the setup #
  402. # #
  403. # Report bugs at https://github.com/centreon/centreon/issues #
  404. # #
  405. # Thanks for using Centreon. #
  406. # ----------------------- #
  407. # Contact : infos@centreon.com #
  408. # http://www.centreon.com #
  409. # #
  410. ###############################################################################
  411. __EOT__
  412. exit 0