upgrade 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. ynh_script_progression --message="Loading installation settings..."
  13. app=$YNH_APP_INSTANCE_NAME
  14. domain=$(ynh_app_setting_get --app=$app --key=domain)
  15. path_url=$(ynh_app_setting_get --app=$app --key=path)
  16. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  17. db_name=$(ynh_app_setting_get --app=$app --key=db_name)
  18. db_user=$(ynh_app_setting_get --app=$app --key=db_user)
  19. db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
  20. language=$(ynh_app_setting_get --app=$app --key=language)
  21. trustedversion="5.0-1+stretch"
  22. is_public=$(ynh_permission_has_user --permission=main --user=visitors && echo 1 || echo 0)
  23. #=================================================
  24. # CHECK VERSION
  25. #=================================================
  26. ynh_script_progression --message="Checking version..."
  27. upgrade_type=$(ynh_check_app_version_changed)
  28. #=================================================
  29. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  30. #=================================================
  31. ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
  32. # Backup the current version of the app
  33. ynh_backup_before_upgrade
  34. ynh_clean_setup () {
  35. ynh_clean_check_starting
  36. # Restore it if the upgrade fails
  37. ynh_restore_upgradebackup
  38. }
  39. # Exit if an error occurs during the execution of the script
  40. ynh_abort_if_errors
  41. #=================================================
  42. # STANDARD UPGRADE STEPS
  43. #=================================================
  44. # STOP SYSTEMD SERVICE
  45. #=================================================
  46. ynh_script_progression --message="Stopping a systemd service..."
  47. ynh_systemd_action --service_name=$app-server --action="stop" --log_path="/var/log/$app/${app}_server.log"
  48. ynh_systemd_action --service_name=$app-agent --action="stop" --log_path="/var/log/$app/${app}_agent.log"
  49. #=================================================
  50. # ENSURE DOWNWARD COMPATIBILITY
  51. #=================================================
  52. ynh_script_progression --message="Ensuring downward compatibility..."
  53. # If db_name doesn't exist, create it
  54. if [ -z "$db_name" ]; then
  55. db_name=$(ynh_sanitize_dbid --db_name=$app)
  56. ynh_app_setting_set --app=$app --key=db_name --value=$db_name
  57. fi
  58. # If final_path doesn't exist, create it
  59. if [ -z "$final_path" ]; then
  60. final_path=/var/www/$app
  61. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  62. fi
  63. if [ "$language" == "fr" ]
  64. then
  65. language="fr_FR"
  66. ynh_app_setting_set --app=$app --key=language --value=$language
  67. fi
  68. if [ "$language" == "en" ]
  69. then
  70. language="en_GB"
  71. ynh_app_setting_set --app=$app --key=language --value=$language
  72. fi
  73. export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
  74. # patch if zabbix-release installed
  75. if [ "$(dpkg -l zabbix-release 2>/dev/null | wc -l)" -ne 0 ]
  76. 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" ]
  82. then
  83. if [ "$(grep -c "4.2" /etc/apt/sources.list.d/zabbix.list)" -eq 1 ]
  84. then
  85. install_zabbix_repo
  86. upgrade_type="UPGRADE_APP"
  87. fi
  88. fi
  89. # patch to remove old zabbix-client service
  90. if [ ! -z "$(yunohost service status | grep zabbix-client)" ]
  91. then
  92. ynh_script_progression --message="remove zabbix-client old service"
  93. yunohost service remove zabbix-client
  94. fi
  95. ynh_remove_logrotate
  96. # Check if new zabbix version is available on repo"
  97. ynh_package_update
  98. zabbixReleaseInstalledVersion=$(apt-cache policy zabbix-release | sed -n '2p' | grep -Po ".* \K(.*)")
  99. if [[ "$trustedversion" > "$zabbixReleaseInstalledVersion" ]]
  100. then
  101. upgrade_type="UPGRADE_APP"
  102. fi
  103. if [ -f "/etc/zabbix/web/zabbix.conf.php" ]
  104. then
  105. ynh_secure_remove --file="/etc/zabbix/web/zabbix.conf.php"
  106. fi
  107. ynh_add_config --template="../conf/etc_zabbix_web_zabbix.conf.php" --destination="/etc/zabbix/web/zabbix.conf.php"
  108. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  109. chown $app:www-data "/etc/zabbix/web/zabbix.conf.php"
  110. if [ -f "/usr/share/zabbix/conf/zabbix.conf.php" ]
  111. then
  112. ynh_secure_remove --file="/usr/share/zabbix/conf/zabbix.conf.php"
  113. fi
  114. ln -s "/etc/zabbix/web/zabbix.conf.php" "/usr/share/zabbix/conf/zabbix.conf.php"
  115. #=================================================
  116. # NGINX CONFIGURATION
  117. #=================================================
  118. ynh_script_progression --message="Upgrading NGINX web server configuration..."
  119. # Create a dedicated NGINX config
  120. ynh_add_nginx_config
  121. #=================================================
  122. # UPGRADE DEPENDENCIES
  123. #=================================================
  124. if [ "$upgrade_type" == "UPGRADE_APP" ]
  125. then
  126. ynh_script_progression --message="Upgrading dependencies..."
  127. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  128. ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
  129. fi
  130. #=================================================
  131. # RESTORE THE APP MAIN DIR
  132. #=================================================
  133. ynh_script_progression --message="Restoring the app main directory..."
  134. chmod 750 "/usr/share/zabbix"
  135. chmod -R o-rwx "/usr/share/zabbix"
  136. chown -R $app:www-data "/usr/share/zabbix"
  137. #=================================================
  138. # PHP-FPM CONFIGURATION
  139. #=================================================
  140. ynh_script_progression --message="Upgrading PHP-FPM configuration..."
  141. # Create a dedicated PHP-FPM config
  142. ynh_add_fpm_config --package="$extra_php_dependencies"
  143. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  144. #=================================================
  145. # SPECIFIC UPGRADE
  146. #=================================================
  147. # CUSTOMIZE DATABASE
  148. #=================================================
  149. ynh_script_progression --message="Customize the database..."
  150. convert_ZabbixDB
  151. set_mediatype_default_yunohost
  152. #=================================================
  153. # SETUP APPLICATION WITH CURL
  154. #=================================================
  155. ynh_script_progression --message="Setuping application with CURL..."
  156. # Set the app as temporarily public for curl call
  157. ynh_script_progression --message="Configuring SSOwat..."
  158. # Making the app public for curl
  159. if [ $is_public -eq 0 ]
  160. then
  161. ynh_permission_update --permission="main" --add="visitors"
  162. fi
  163. enable_admin_user
  164. import_template
  165. link_template
  166. disable_admin_user
  167. disable_guest_user
  168. # Remove the public access
  169. ynh_permission_update --permission="main" --remove="visitors"
  170. #=================================================
  171. # SETUP SYSTEMD
  172. #=================================================
  173. ynh_script_progression --message="Upgrading systemd configuration..."
  174. change_timeoutAgent
  175. systemctl enable zabbix-agent --quiet
  176. systemctl enable zabbix-server --quiet
  177. update_initZabbixConf
  178. #=================================================
  179. # GENERIC FINALIZATION
  180. #=================================================
  181. # INTEGRATE SERVICE IN YUNOHOST
  182. #=================================================
  183. ynh_script_progression --message="Integrating service in YunoHost..."
  184. yunohost service add snmpd --description="Management of SNMP Daemon"
  185. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  186. 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"
  187. #=================================================
  188. # START SYSTEMD SERVICE
  189. #=================================================
  190. ynh_script_progression --message="Starting a systemd service..."
  191. # Start a systemd service
  192. ynh_systemd_action --service_name=$app-server --action="restart" --log_path="/var/log/$app/${app}_server.log"
  193. ynh_systemd_action --service_name=$app-agent --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  194. #=================================================
  195. # SETUP SSOWAT
  196. #=================================================
  197. ynh_script_progression --message="Configuring permissions..."
  198. # Make app public if necessary
  199. if [ $is_public -eq 1 ]
  200. then
  201. # Everyone can access the app.
  202. # The "main" permission is automatically created before the install script.
  203. ynh_permission_update --permission="main" --add="visitors"
  204. fi
  205. #=================================================
  206. # RELOAD NGINX
  207. #=================================================
  208. ynh_script_progression --message="Reloading NGINX web server..."
  209. ynh_systemd_action --service_name=nginx --action=reload
  210. #=================================================
  211. # END OF SCRIPT
  212. #=================================================
  213. ynh_script_progression --message="Upgrade of $app completed"