upgrade 8.9 KB

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