upgrade 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.5-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. nonfree=$(ynh_app_setting_get "$app" nonfree)
  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. # Enable default admin temporaly
  48. #=================================================
  49. enable_admin_user
  50. #=================================================
  51. # Import Yunohost template
  52. #=================================================
  53. import_template
  54. #=================================================
  55. # Link Yunohost template to the ZAbbix Server Host
  56. #=================================================
  57. link_template
  58. #=================================================
  59. # Disable default admin for security issue
  60. #=================================================
  61. disable_admin_user
  62. #=================================================
  63. # Disable default guest for security issue
  64. #=================================================
  65. disable_guest_user
  66. #=================================================
  67. # CHECK THE PATH
  68. #=================================================
  69. # Normalize the URL path syntax
  70. path_url=$(ynh_normalize_url_path "$path_url")
  71. #=================================================
  72. # STANDARD UPGRADE STEPS
  73. #=================================================
  74. ynh_print_info "Check if new zabbix version is available on repo"
  75. ynh_package_update
  76. #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED
  77. ynh_remove_logrotate
  78. zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Installed: \K(.*)")
  79. zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Candidate: \K(.*)")
  80. zabbixFrontendInstalledVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Installed: \K(.*)")
  81. zabbixFrontendCandidateVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Candidate: \K(.*)")
  82. zabbixagentInstalledVersion=$(apt-cache policy zabbix-agent | grep -Po "Installed: \K(.*)")
  83. zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | grep -Po "Candidate: \K(.*)")
  84. if [ "$trustedversion" == "$zabbixServerCandidateVersion" ]
  85. then
  86. if [ "$zabbixServerInstalledVersion" != "$zabbixServerCandidateVersion" ] || [ "$zabbixFrontendInstalledVersion" != "$zabbixFrontendCandidateVersion" ] || [ "$zabbixagentInstalledVersion" != "$zabbixagentCandidateVersion" ]
  87. then
  88. #=================================================
  89. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  90. #=================================================
  91. # Backup the current version of the app
  92. ynh_backup_before_upgrade
  93. ynh_clean_setup () {
  94. # restore it if the upgrade fails
  95. ynh_restore_upgradebackup
  96. }
  97. # Exit if an error occurs during the execution of the script
  98. ynh_abort_if_errors
  99. cp -rp /etc/zabbix /tmp/
  100. cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
  101. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  102. ynh_print_info "Install non-free repository with pinning"
  103. if [ $nonfree ];then
  104. echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list
  105. nonfreefilerepo=$(find /var/cache/yunohost/ -name "non-free_policy")
  106. packagenonfreefilerepo=$(find /var/cache/yunohost/ -name "snmp-mibs-downloader_nonfree")
  107. cp $nonfreefilerepo /etc/apt/preferences.d/
  108. cp $packagenonfreefilerepo /etc/apt/preferences.d/
  109. fi
  110. ynh_print_info "Update and install dependencies"
  111. ynh_package_update
  112. if [ $nonfree ];then
  113. ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype jq
  114. else
  115. ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq
  116. fi
  117. ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php
  118. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  119. rm /usr/share/zabbix/conf/zabbix.conf.php
  120. cp -rpf /tmp/zabbix /etc/
  121. cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
  122. rm -fr /tmp/zabbix*
  123. else
  124. ynh_print_info "No update from repo ! (Already up to date)"
  125. fi
  126. else
  127. ynh_print_info "No update from repo ! (Trusted version)"
  128. fi
  129. #=================================================
  130. # RE-ENABLE SSOWAT
  131. #=================================================
  132. ynh_print_info "re-enable SSOWAT"
  133. # Make app private if necessary
  134. if [ $is_public -eq 0 ]
  135. then
  136. # unprotected_uris allows SSO credentials to be passed anyway.
  137. ynh_app_setting_delete "$app" unprotected_uris
  138. else
  139. ynh_app_setting_set "$app" unprotected_uris "/"
  140. fi
  141. systemctl reload nginx
  142. yunohost app ssowatconf