upgrade 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. # LOAD SETTINGS
  11. #=================================================
  12. app=$YNH_APP_INSTANCE_NAME
  13. trustedversion="4.4-1+stretch"
  14. forceupdate=0
  15. export domain=$(ynh_app_setting_get "$app" domain)
  16. export path_url=$(ynh_app_setting_get "$app" path)
  17. #admin=$(ynh_app_setting_get "$app" admin) #not used
  18. is_public=$(ynh_app_setting_get "$app" is_public)
  19. final_path=$(ynh_app_setting_get "$app" final_path)
  20. #language=$(ynh_app_setting_get "$app" language) #not used
  21. db_name=$(ynh_app_setting_get "$app" db_name)
  22. db_user=$(ynh_app_setting_get "$app" db_user)
  23. db_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
  24. #=================================================
  25. # ENSURE DOWNWARD COMPATIBILITY
  26. #=================================================
  27. # Fix is_public as a boolean value
  28. if [ "$is_public" = "Yes" ]; then
  29. ynh_app_setting_set "$app" is_public 1
  30. is_public=1
  31. elif [ "$is_public" = "No" ]; then
  32. ynh_app_setting_set "$app" is_public 0
  33. is_public=0
  34. fi
  35. # If db_name doesn't exist, create it
  36. if [ -z "$db_name" ]; then
  37. db_name=$(ynh_sanitize_dbid "$app")
  38. ynh_app_setting_set "$app" db_name "$db_name"
  39. fi
  40. # If final_path doesn't exist, create it
  41. if [ -z "$final_path" ]; then
  42. final_path=/var/www/$app
  43. ynh_app_setting_set "$app" final_path "$final_path"
  44. fi
  45. export mysqlconn="mysql -u$db_user -p$db_pwd $db_name"
  46. #=================================================
  47. # DISABLED SSOWAT
  48. #=================================================
  49. ynh_print_info "disable SSOWAT temporaly"
  50. ynh_app_setting_set "$app" unprotected_uris "/"
  51. systemctl reload nginx
  52. yunohost app ssowatconf
  53. #=================================================
  54. # Enable default admin temporaly
  55. #=================================================
  56. enable_admin_user
  57. #=================================================
  58. # Import Yunohost template
  59. #=================================================
  60. import_template
  61. #=================================================
  62. # Link Yunohost template to the ZAbbix Server Host
  63. #=================================================
  64. link_template
  65. #=================================================
  66. # Disable default admin for security issue
  67. #=================================================
  68. disable_admin_user
  69. #=================================================
  70. # Disable default guest for security issue
  71. #=================================================
  72. disable_guest_user
  73. #Patch timeout too short for zabbix agent if needed
  74. change_timeoutAgent
  75. #patch if zabbix-release installed
  76. if [ "$(dpkg -l zabbix-release 2>/dev/null | wc -l)" -ne 0 ];then
  77. DEBIAN_FRONTEND=noninteractive apt purge zabbix-release -y
  78. install_zabbix_repo
  79. fi
  80. #patch if zabbix-release has Candidate version but no Installed version
  81. if [ -f "/etc/apt/sources.list.d/zabbix.list" ];then
  82. if [ "$(grep -c "4.2" /etc/apt/sources.list.d/zabbix.list)" -eq 1 ];then
  83. install_zabbix_repo
  84. forceupdate=1
  85. fi
  86. fi
  87. #patch to remove old zabbix-client service
  88. if [ ! -z "$(yunohost service status | grep zabbix-client)" ];then
  89. ynh_print_info "remove zabbix-client old service"
  90. yunohost service remove zabbix-client
  91. fi
  92. #=================================================
  93. # STANDARD UPGRADE STEPS
  94. #=================================================
  95. #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED
  96. ynh_remove_logrotate
  97. ynh_print_info "Check if new zabbix version is available on repo"
  98. ynh_package_update
  99. zabbixReleaseInstalledVersion=$(apt-cache policy zabbix-release | sed -n '2p' | grep -Po ".* \K(.*)")
  100. if [[ "$trustedversion" > "$zabbixReleaseInstalledVersion" ]] || [[ "$forceupdate" == "1" ]]
  101. then
  102. #=================================================
  103. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  104. #=================================================
  105. # Backup the current version of the app
  106. ynh_backup_before_upgrade
  107. ynh_clean_setup () {
  108. # restore it if the upgrade fails
  109. ynh_restore_upgradebackup
  110. }
  111. # Exit if an error occurs during the execution of the script
  112. ynh_abort_if_errors
  113. #=================================================
  114. # Migrate legacy permissions to new system
  115. #=================================================
  116. if ynh_legacy_permissions_exists
  117. then
  118. ynh_legacy_permissions_delete_all
  119. ynh_app_setting_delete --app=$app --key=is_public
  120. fi
  121. yunohost service stop zabbix-server
  122. yunohost service stop zabbix-agent
  123. cp -rp /etc/zabbix /tmp/
  124. cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
  125. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  126. ynh_package_remove zabbix-server-mysql zabbix-frontend-php
  127. ynh_print_info "Update zabbix via apt package"
  128. ynh_install_app_dependencies $pkg_dependencies
  129. ynh_secure_remove /usr/share/zabbix/conf/zabbix.conf.php
  130. cp -rpf /tmp/zabbix /etc/
  131. cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
  132. ynh_secure_remove /tmp/zabbix*
  133. #If needed.
  134. yunohost service add snmpd -d "Management of SNMP Daemon"
  135. yunohost service add zabbix-server -d "Management Zabbix server daemon : Collect, agregate, compute and notify"
  136. yunohost service add zabbix-agent -d "Management Zabbix agent daemon : send informations about this host to the server"
  137. yunohost service start zabbix-server
  138. yunohost service start zabbix-agent
  139. #test if zabbix server is started
  140. check_proc_zabbixagent
  141. #test if zabbix agent is started
  142. check_proc_zabbixserver
  143. else
  144. ynh_print_info "No repo update ! (Trusted version)"
  145. fi
  146. #=================================================
  147. # INSTALL hook to verify if conf file is broken (after an update for example)
  148. #=================================================
  149. update_initZabbixConf
  150. #=================================================
  151. # Update db to utf8
  152. #=================================================
  153. convert_ZabbixDB
  154. #=================================================
  155. # Add settings for yunohost mail server
  156. #=================================================
  157. set_mediatype_default_yunohost
  158. #=================================================
  159. # Update php-fpm confi
  160. #=================================================
  161. ynh_print_info "Update php-fpm config"
  162. # Remove the dedicated php-fpm config
  163. ynh_remove_fpm_config
  164. # Create a dedicated php-fpm config
  165. ynh_add_fpm_config
  166. #=================================================
  167. # Update nginx config
  168. #=================================================
  169. ynh_print_info "Update nginx config"
  170. # Remove the dedicated nginx config
  171. ynh_remove_nginx_config
  172. # Create a dedicated nginx config
  173. ynh_add_nginx_config
  174. #=================================================
  175. # RE-ENABLE SSOWAT
  176. #=================================================
  177. ynh_print_info "re-enable SSOWAT"
  178. # Make app private if necessary
  179. if [ $is_public -eq 0 ]
  180. then
  181. # unprotected_uris allows SSO credentials to be passed anyway.
  182. ynh_app_setting_delete "$app" unprotected_uris
  183. else
  184. ynh_app_setting_set "$app" unprotected_uris "/"
  185. fi
  186. ynh_add_nginx_config
  187. systemctl reload nginx
  188. yunohost app ssowatconf