upgrade 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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="1:4.0.4-1+stretch"
  14. export domain=$(ynh_app_setting_get "$app" domain)
  15. export path_url=$(ynh_app_setting_get "$app" path)
  16. #admin=$(ynh_app_setting_get "$app" admin) #not used
  17. is_public=$(ynh_app_setting_get "$app" is_public)
  18. final_path=$(ynh_app_setting_get "$app" final_path)
  19. #language=$(ynh_app_setting_get "$app" language) #not used
  20. db_name=$(ynh_app_setting_get "$app" db_name)
  21. db_user=$(ynh_app_setting_get "$app" db_user)
  22. db_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
  23. #=================================================
  24. # ENSURE DOWNWARD COMPATIBILITY
  25. #=================================================
  26. # Fix is_public as a boolean value
  27. if [ "$is_public" = "Yes" ]; then
  28. ynh_app_setting_set "$app" is_public 1
  29. is_public=1
  30. elif [ "$is_public" = "No" ]; then
  31. ynh_app_setting_set "$app" is_public 0
  32. is_public=0
  33. fi
  34. # If db_name doesn't exist, create it
  35. if [ -z "$db_name" ]; then
  36. db_name=$(ynh_sanitize_dbid "$app")
  37. ynh_app_setting_set "$app" db_name "$db_name"
  38. fi
  39. # If final_path doesn't exist, create it
  40. if [ -z "$final_path" ]; then
  41. final_path=/var/www/$app
  42. ynh_app_setting_set "$app" final_path "$final_path"
  43. fi
  44. export mysqlconn="mysql -u $db_user -p $db_pwd $db_name"
  45. #=================================================
  46. # Enable default admin temporaly
  47. #=================================================
  48. enable_admin_user
  49. #=================================================
  50. # Import Yunohost template
  51. #=================================================
  52. import_template
  53. #=================================================
  54. # Link Yunohost template to the ZAbbix Server Host
  55. #=================================================
  56. link_template
  57. #=================================================
  58. # Disable default admin for security issue
  59. #=================================================
  60. disable_admin_user
  61. #=================================================
  62. # Disable default guest for security issue
  63. #=================================================
  64. disable_guest_user
  65. #=================================================
  66. # CHECK THE PATH
  67. #=================================================
  68. # Normalize the URL path syntax
  69. path_url=$(ynh_normalize_url_path "$path_url")
  70. #=================================================
  71. # STANDARD UPGRADE STEPS
  72. #=================================================
  73. ynh_print_info "Check if new zabbix version is available on repo"
  74. ynh_package_update
  75. #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED
  76. ynh_remove_logrotate
  77. zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Installed: \K(.*)")
  78. zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Candidate: \K(.*)")
  79. zabbixFrontendInstalledVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Installed: \K(.*)")
  80. zabbixFrontendCandidateVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Candidate: \K(.*)")
  81. zabbixagentInstalledVersion=$(apt-cache policy zabbix-agent | grep -Po "Installed: \K(.*)")
  82. zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | grep -Po "Candidate: \K(.*)")
  83. if [ "$trustedversion" == "$zabbixServerCandidateVersion" ]
  84. then
  85. if [ "$zabbixServerInstalledVersion" != "$zabbixServerCandidateVersion" ] || [ "$zabbixFrontendInstalledVersion" != "$zabbixFrontendCandidateVersion" ] || [ "$zabbixagentInstalledVersion" != "$zabbixagentCandidateVersion" ]
  86. then
  87. #=================================================
  88. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  89. #=================================================
  90. # Backup the current version of the app
  91. ynh_backup_before_upgrade
  92. ynh_clean_setup () {
  93. # restore it if the upgrade fails
  94. ynh_restore_upgradebackup
  95. }
  96. # Exit if an error occurs during the execution of the script
  97. ynh_abort_if_errors
  98. cp -rp /etc/zabbix /tmp/
  99. cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
  100. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  101. DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php
  102. ar x ./*.deb
  103. tar xzf control.tar.gz
  104. ynh_replace_string "apache2 | httpd, " "" control
  105. tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control
  106. ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz
  107. dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb
  108. rm -fr zabbix-*.deb
  109. apt-get -y --only-upgrade install zabbix-server-mysql zabbix-agent
  110. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  111. rm /usr/share/zabbix/conf/zabbix.conf.php
  112. cp -rpf /tmp/zabbix /etc/
  113. cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
  114. rm -fr /tmp/zabbix*
  115. else
  116. ynh_print_info "No update from repo ! (Already up to date)"
  117. fi
  118. else
  119. ynh_print_info "No update from repo ! (Trusted version)"
  120. fi
  121. #=================================================
  122. # RE-ENABLE SSOWAT
  123. #=================================================
  124. ynh_print_info "re-enable SSOWAT"
  125. # Make app private if necessary
  126. if [ $is_public -eq 0 ]
  127. then
  128. # unprotected_uris allows SSO credentials to be passed anyway.
  129. ynh_app_setting_delete "$app" unprotected_uris
  130. else
  131. ynh_app_setting_set "$app" unprotected_uris "/"
  132. fi
  133. systemctl reload nginx
  134. yunohost app ssowatconf