install 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. # Exit if an error occurs during the execution of the script
  13. ynh_abort_if_errors
  14. #=================================================
  15. # RETRIEVE ARGUMENTS FROM THE MANIFEST
  16. #=================================================
  17. export domain=$YNH_APP_ARG_DOMAIN
  18. export path_url=$YNH_APP_ARG_PATH
  19. admin=$YNH_APP_ARG_ADMIN
  20. is_public=$YNH_APP_ARG_IS_PUBLIC
  21. language=$YNH_APP_ARG_LANGUAGE
  22. app=$YNH_APP_INSTANCE_NAME
  23. #=================================================
  24. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  25. #=================================================
  26. ynh_script_progression --message="Validating installation parameters..."
  27. final_path=/var/www/$app
  28. test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
  29. # Register (book) web path
  30. ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
  31. #=================================================
  32. # STORE SETTINGS FROM MANIFEST
  33. #=================================================
  34. ynh_script_progression --message="Storing installation settings..."
  35. ynh_app_setting_set --app=$app --key=domain --value=$domain
  36. ynh_app_setting_set --app=$app --key=path --value=$path_url
  37. ynh_app_setting_set --app=$app --key=admin --value=$admin
  38. ynh_app_setting_set --app=$app --key=language --value=$language
  39. #=================================================
  40. # STANDARD MODIFICATIONS
  41. #=================================================
  42. # INSTALL DEPENDENCIES
  43. #=================================================
  44. ynh_script_progression --message="Installing dependencies..."
  45. pid=$(pgrep -f '/usr/bin/python3 /usr/bin/unattended-upgrade --download-only' || true)
  46. if [ ! -z "$pid" ] ;then
  47. ynh_script_progression --message="Check and wait end of unattended-upgrade of package_check" -w 1
  48. tail --pid=$pid -f /dev/null
  49. fi
  50. ynh_script_progression --message="Remove Zabbix if already installed" -w 1
  51. apt-get purge zabbix* -y
  52. if compgen -G "/var/cache/apt/archives/zabbix-server-mysql*" > /dev/null; then
  53. ynh_secure_remove /var/cache/apt/archives/zabbix-server-mysql*
  54. fi
  55. ynh_script_progression --message="Install Zabbix repository" -w 3
  56. install_zabbix_repo
  57. ynh_script_progression --message="Update and install dependencies" -w 5
  58. #ynh_package_update no need cause ynh_install_app_dependencies after
  59. ynh_install_app_dependencies $pkg_dependencies
  60. dpkg -i --force-confmiss /var/cache/apt/archives/zabbix-server-mysql*
  61. ynh_replace_string --match_string="# fr_FR.UTF-8 UTF-8" --replace_string="fr_FR.UTF-8 UTF-8" --target_file=/etc/locale.gen
  62. locale-gen
  63. ln -s /usr/share/zabbix "$final_path"
  64. if [ -f "$final_path/conf/zabbix.conf.php" ];then
  65. ynh_secure_remove --file="$final_path/conf/zabbix.conf.php"
  66. fi
  67. #=================================================
  68. # CREATE A MYSQL DATABASE
  69. #=================================================
  70. ynh_script_progression --message="Creating a MySQL database..."
  71. declare db_pwd
  72. db_name=$(ynh_sanitize_dbid --db_name=$app)
  73. db_user=$db_name
  74. ynh_app_setting_set --app=$app --key=db_name --value=$db_name
  75. ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
  76. export mysqlconn="mysql -u$db_user -p$db_pwd $db_name"
  77. mysql --user=$db_user --password=$db_pwd --database=zabbix -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
  78. ynh_script_progression --message="Import default data in database..." -w 25
  79. zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn
  80. convert_ZabbixDB
  81. #sso integration
  82. $mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
  83. if [ "$language" == "fr" ];then
  84. lang="fr_FR"
  85. else
  86. lang="en_GB"
  87. fi
  88. #admin creation
  89. surname=$(ynh_user_get_info "$admin" lastname)
  90. name=$(ynh_user_get_info "$admin" firstname)
  91. $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', '$lang', '30s', 3, 'default', 0, '', 0, 50);"
  92. $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);"
  93. #users creation in zabbix database
  94. i=4
  95. for user in $(ynh_user_list);
  96. do
  97. if [ "$user" != "$admin" ];then
  98. surname=$(ynh_user_get_info "$user" lastname)
  99. name=$(ynh_user_get_info "$user" firstname)
  100. $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', '$lang', '30s', 1, 'default', 0, '', 0, 50);"
  101. i=$((i+1))
  102. fi
  103. done
  104. disable_guest_user
  105. set_mediatype_default_yunohost
  106. #=================================================
  107. # DOWNLOAD, CHECK AND UNPACK SOURCE
  108. #=================================================
  109. ynh_script_progression --message="Setting up source files..."
  110. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  111. #=================================================
  112. # NGINX CONFIGURATION
  113. #=================================================
  114. ynh_script_progression --message="Configuring NGINX web server..."
  115. # Create a dedicated NGINX config
  116. ynh_add_nginx_config
  117. #=================================================
  118. # PHP-FPM CONFIGURATION
  119. #=================================================
  120. ynh_script_progression --message="Configuring PHP-FPM..."
  121. # Create a dedicated PHP-FPM config
  122. ynh_add_fpm_config
  123. #=================================================
  124. # SPECIFIC SETUP
  125. #=================================================
  126. # ...
  127. #=================================================
  128. #=================================================
  129. # SETUP APPLICATION WITH CURL
  130. #=================================================
  131. # Reload SSOwat config
  132. yunohost app ssowatconf
  133. # Reload Nginx
  134. systemctl reload nginx
  135. #=================================================
  136. # ADD A CONFIGURATION
  137. #=================================================
  138. ynh_script_progression --message="Adding a configuration file..."
  139. confServerPath=$(find /var/cache/yunohost/ -name "usr_share_zabbix_conf_zabbix.conf.php")
  140. cp --remove-destination "$confServerPath" /usr/share/zabbix/conf/zabbix.conf.php
  141. ynh_replace_string --match_string="db_name" --replace_string="$db_name" --target_file=/usr/share/zabbix/conf/zabbix.conf.php
  142. ynh_replace_string --match_string="db_user" --replace_string="$db_user" --target_file=/usr/share/zabbix/conf/zabbix.conf.php
  143. ynh_replace_string --match_string="db_pwd" --replace_string="$db_pwd" --target_file=/usr/share/zabbix/conf/zabbix.conf.php
  144. chown -R www-data. /usr/share/zabbix
  145. ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_name" --target_file=/etc/zabbix/zabbix_server.conf
  146. ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file=/etc/zabbix/zabbix_server.conf
  147. ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file=/etc/zabbix/zabbix_server.conf
  148. systemctl enable zabbix-agent --quiet && systemctl restart zabbix-agent
  149. change_timeoutAgent
  150. systemctl enable zabbix-server --quiet && systemctl restart zabbix-server
  151. #=================================================
  152. # INSTALL hook to verify if conf file is broken (after an update for example)
  153. #=================================================
  154. update_initZabbixConf
  155. #=================================================
  156. # RELOAD NGINX AND PHP-FPM
  157. #=================================================
  158. systemctl reload nginx
  159. ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
  160. # Reload SSOwat config
  161. yunohost app ssowatconf
  162. #=================================================
  163. # Import Yunohost template
  164. #=================================================
  165. ynh_script_progression --message="Importing last template Yunohost in Zabbix" -w 5
  166. import_template
  167. #=================================================
  168. # Link Yunohost template to the ZAbbix Server Host
  169. #=================================================
  170. ynh_script_progression --message="Importing last template Yunohost in Zabbix" -w 5
  171. link_template
  172. #=================================================
  173. # disable default admin
  174. #=================================================
  175. disable_admin_user
  176. #=================================================
  177. # GENERIC FINALIZATION
  178. #=================================================
  179. # INTEGRATE SERVICE IN YUNOHOST
  180. #=================================================
  181. ynh_script_progression --message="Integrating service in YunoHost..."
  182. yunohost service add snmpd --description="Management of SNMP Daemon"
  183. yunohost service add zabbix-server --description="Management Zabbix server daemon : Collect, agregate, compute and notify"
  184. yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server"
  185. #=================================================
  186. # START SYSTEMD SERVICE
  187. #=================================================
  188. ynh_script_progression --message="Starting a systemd service..."
  189. ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
  190. # Reload SSOwat config
  191. yunohost app ssowatconf
  192. #test if zabbix server is started
  193. check_proc_zabbixagent
  194. #test if zabbix agent is started
  195. check_proc_zabbixserver
  196. #=================================================
  197. # SETUP SSOWAT
  198. #=================================================
  199. ynh_script_progression --message="Configuring permissions..."
  200. # Make app public if necessary
  201. if [ $is_public -eq 1 ]
  202. then
  203. # Everyone can access the app.
  204. # The "main" permission is automatically created before the install script.
  205. ynh_permission_update --permission="main" --add="visitors"
  206. fi
  207. #=================================================
  208. # RELOAD NGINX
  209. #=================================================
  210. ynh_script_progression --message="Reloading NGINX web server..."
  211. ynh_systemd_action --service_name=nginx --action=reload
  212. #=================================================
  213. # END OF SCRIPT
  214. #=================================================
  215. ynh_script_progression --message="Installation of $app completed"