install 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # MANAGE SCRIPT FAILURE
  11. #=================================================
  12. ynh_clean_setup () {
  13. ynh_clean_check_starting
  14. }
  15. # Exit if an error occurs during the execution of the script
  16. ynh_abort_if_errors
  17. #=================================================
  18. # RETRIEVE ARGUMENTS FROM THE MANIFEST
  19. #=================================================
  20. domain=$YNH_APP_ARG_DOMAIN
  21. path_url=$YNH_APP_ARG_PATH
  22. admin=$YNH_APP_ARG_ADMIN
  23. is_public=$YNH_APP_ARG_IS_PUBLIC
  24. language=$YNH_APP_ARG_LANGUAGE
  25. app=$YNH_APP_INSTANCE_NAME
  26. #=================================================
  27. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  28. #=================================================
  29. ynh_script_progression --message="Validating installation parameters..."
  30. remove_previous_zabbix
  31. final_path=/var/www/$app
  32. test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
  33. # Register (book) web path
  34. ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
  35. #=================================================
  36. # STORE SETTINGS FROM MANIFEST
  37. #=================================================
  38. ynh_script_progression --message="Storing installation settings..."
  39. ynh_app_setting_set --app=$app --key=domain --value=$domain
  40. ynh_app_setting_set --app=$app --key=path --value=$path_url
  41. ynh_app_setting_set --app=$app --key=admin --value=$admin
  42. ynh_app_setting_set --app=$app --key=language --value=$language
  43. #=================================================
  44. # STANDARD MODIFICATIONS
  45. #=================================================
  46. # INSTALL DEPENDENCIES
  47. #=================================================
  48. ynh_script_progression --message="Installing dependencies..."
  49. ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
  50. ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="http://repo.zabbix.com/zabbix/5.0/debian $(lsb_release -sc) main" --package="$zabbix_pkg_dependencies" --key="https://repo.zabbix.com/zabbix-official-repo.key"
  51. ynh_replace_string --match_string="# $language.UTF-8 UTF-8" --replace_string="$language.UTF-8 UTF-8" --target_file=/etc/locale.gen
  52. locale-gen
  53. #=================================================
  54. # CREATE A MYSQL DATABASE
  55. #=================================================
  56. ynh_script_progression --message="Creating a MySQL database..."
  57. db_name=$(ynh_sanitize_dbid --db_name=$app)
  58. db_user=$db_name
  59. ynh_app_setting_set --app=$app --key=db_name --value=$db_name
  60. ynh_app_setting_set --app=$app --key=db_user --value=$db_user
  61. ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
  62. #=================================================
  63. # DOWNLOAD, CHECK AND UNPACK SOURCE
  64. #=================================================
  65. ynh_script_progression --message="Setting up source files..."
  66. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  67. ln -s "/usr/share/zabbix" "$final_path"
  68. chmod 750 "/usr/share/zabbix"
  69. chmod -R o-rwx "/usr/share/zabbix"
  70. chown -R $app:www-data "/usr/share/zabbix"
  71. #=================================================
  72. # NGINX CONFIGURATION
  73. #=================================================
  74. ynh_script_progression --message="Configuring NGINX web server..."
  75. # Create a dedicated NGINX config
  76. ynh_add_nginx_config
  77. #=================================================
  78. # PHP-FPM CONFIGURATION
  79. #=================================================
  80. ynh_script_progression --message="Configuring PHP-FPM..."
  81. # Create a dedicated PHP-FPM config
  82. ynh_add_fpm_config --package="$extra_php_dependencies"
  83. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  84. #=================================================
  85. # SPECIFIC SETUP
  86. #=================================================
  87. # IMPORT DEFAULT DATA
  88. #=================================================
  89. ynh_script_progression --message="Import default data in database..."
  90. export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
  91. $mysqlconn -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
  92. zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn
  93. convert_ZabbixDB
  94. #sso integration
  95. $mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
  96. #admin creation
  97. surname=$(ynh_user_get_info "$admin" lastname)
  98. name=$(ynh_user_get_info "$admin" firstname)
  99. $mysqlconn -e "INSERT INTO \`users\` (\`userid\`,\`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES (3,'$admin', '$admin', '$admin', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$language', '30s', 3, 'default', 0, '', 0, 50);"
  100. $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);"
  101. #users creation in zabbix database
  102. i=4
  103. for user in $(ynh_user_list);
  104. do
  105. if [ "$user" != "$admin" ]
  106. then
  107. surname=$(ynh_user_get_info --username="$user" --key=lastname)
  108. name=$(ynh_user_get_info --username="$user" --key=firstname)
  109. $mysqlconn -e "INSERT INTO \`users\` (\`userid\`, \`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES ($i,'$user', '$name', '$surname', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$language', '30s', 1, 'default', 0, '', 0, 50);"
  110. i=$((i+1))
  111. fi
  112. done
  113. disable_guest_user
  114. set_mediatype_default_yunohost
  115. #=================================================
  116. # ADD A CONFIGURATION
  117. #=================================================
  118. ynh_script_progression --message="Adding a configuration file..."
  119. ynh_add_config --template="../conf/etc_zabbix_web_zabbix.conf.php" --destination="/etc/zabbix/web/zabbix.conf.php"
  120. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  121. chown $app:www-data "/etc/zabbix/web/zabbix.conf.php"
  122. ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_name" --target_file=/etc/zabbix/zabbix_server.conf
  123. ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file=/etc/zabbix/zabbix_server.conf
  124. ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file=/etc/zabbix/zabbix_server.conf
  125. #=================================================
  126. # SETUP SYSTEMD
  127. #=================================================
  128. ynh_script_progression --message="Configuring a systemd service..."
  129. change_timeoutAgent
  130. systemctl enable zabbix-agent --quiet
  131. systemctl enable zabbix-server --quiet
  132. update_initZabbixConf
  133. #=================================================
  134. # SETUP APPLICATION WITH CURL
  135. #=================================================
  136. ynh_script_progression --message="Setuping application with CURL..."
  137. # Set the app as temporarily public for curl call
  138. ynh_script_progression --message="Configuring SSOwat..."
  139. # Making the app public for curl
  140. ynh_permission_update --permission="main" --add="visitors"
  141. import_template
  142. link_template
  143. disable_admin_user
  144. # Remove the public access
  145. ynh_permission_update --permission="main" --remove="visitors"
  146. #=================================================
  147. # GENERIC FINALIZATION
  148. #=================================================
  149. # INTEGRATE SERVICE IN YUNOHOST
  150. #=================================================
  151. ynh_script_progression --message="Integrating service in YunoHost..."
  152. yunohost service add snmpd --description="Management of SNMP Daemon"
  153. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  154. yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server" --log="/var/log/$app/${app}_agent.log"
  155. #=================================================
  156. # START SYSTEMD SERVICE
  157. #=================================================
  158. ynh_script_progression --message="Starting a systemd service..."
  159. # Start a systemd service
  160. ynh_systemd_action --service_name=$app-server --action="restart" --log_path="/var/log/$app/${app}_server.log"
  161. ynh_systemd_action --service_name=$app-agent --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  162. #=================================================
  163. # SETUP SSOWAT
  164. #=================================================
  165. ynh_script_progression --message="Configuring permissions..."
  166. # Make app public if necessary
  167. if [ $is_public -eq 1 ]
  168. then
  169. # Everyone can access the app.
  170. # The "main" permission is automatically created before the install script.
  171. ynh_permission_update --permission="main" --add="visitors"
  172. fi
  173. #=================================================
  174. # RELOAD NGINX
  175. #=================================================
  176. ynh_script_progression --message="Reloading NGINX web server..."
  177. ynh_systemd_action --service_name=nginx --action=reload
  178. #=================================================
  179. # END OF SCRIPT
  180. #=================================================
  181. ynh_script_progression --message="Installation of $app completed"