upgrade 6.5 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. #=================================================
  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. # DISABLED SSOWAT
  47. #=================================================
  48. ynh_print_info "disable SSOWAT temporaly"
  49. ynh_app_setting_set "$app" unprotected_uris "/"
  50. #=================================================
  51. # Enable default admin temporaly
  52. #=================================================
  53. enable_admin_user
  54. #=================================================
  55. # Import Yunohost template
  56. #=================================================
  57. import_template
  58. #=================================================
  59. # Link Yunohost template to the ZAbbix Server Host
  60. #=================================================
  61. link_template
  62. #=================================================
  63. # Disable default admin for security issue
  64. #=================================================
  65. disable_admin_user
  66. #=================================================
  67. # Disable default guest for security issue
  68. #=================================================
  69. disable_guest_user
  70. #=================================================
  71. # CHECK THE PATH
  72. #=================================================
  73. # Normalize the URL path syntax
  74. path_url=$(ynh_normalize_url_path "$path_url")
  75. #REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1)
  76. nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free)
  77. if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then
  78. ynh_print_info "Removing snmp-mibs-downloader (non-free package)"
  79. sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status
  80. DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y
  81. if [ -f /etc/apt/sources.list.d/non-free.list ];then
  82. ynh_secure_remove /etc/apt/sources.list.d/non-free.list
  83. fi
  84. fi
  85. #=================================================
  86. # STANDARD UPGRADE STEPS
  87. #=================================================
  88. ynh_print_info "Check if new zabbix version is available on repo"
  89. ynh_package_update
  90. #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED
  91. ynh_remove_logrotate
  92. zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | sed -n '2p' | grep -Po ".*: \K(.*)")
  93. zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | sed -n '3p' | grep -Po ".*: \K(.*)")
  94. zabbixFrontendInstalledVersion=$(apt-cache policy zabbix-frontend-php | sed -n '2p' | grep -Po ".*: \K(.*)")
  95. zabbixFrontendCandidateVersion=$(apt-cache policy zabbix-frontend-php | sed -n '3p' | grep -Po ".*: \K(.*)")
  96. zabbixagentInstalledVersion=$(apt-cache policy zabbix-agent | sed -n '2p' | grep -Po ".*: \K(.*)")
  97. zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | sed -n '3p' | grep -Po ".*: \K(.*)")
  98. if [ "$trustedversion" == "$zabbixServerCandidateVersion" ]
  99. then
  100. if [ "$zabbixServerInstalledVersion" != "$zabbixServerCandidateVersion" ] || [ "$zabbixFrontendInstalledVersion" != "$zabbixFrontendCandidateVersion" ] || [ "$zabbixagentInstalledVersion" != "$zabbixagentCandidateVersion" ]
  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. cp -rp /etc/zabbix /tmp/
  114. cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
  115. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  116. ynh_print_info "Update and install dependencies"
  117. ynh_package_update
  118. 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
  119. ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php
  120. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  121. rm /usr/share/zabbix/conf/zabbix.conf.php
  122. cp -rpf /tmp/zabbix /etc/
  123. cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
  124. rm -fr /tmp/zabbix*
  125. else
  126. ynh_print_info "No update from repo ! (Already up to date)"
  127. fi
  128. else
  129. ynh_print_info "No update from repo ! (Trusted version)"
  130. fi
  131. #=================================================
  132. # RE-ENABLE SSOWAT
  133. #=================================================
  134. ynh_print_info "re-enable SSOWAT"
  135. # Make app private if necessary
  136. if [ $is_public -eq 0 ]
  137. then
  138. # unprotected_uris allows SSO credentials to be passed anyway.
  139. ynh_app_setting_delete "$app" unprotected_uris
  140. else
  141. ynh_app_setting_set "$app" unprotected_uris "/"
  142. fi
  143. systemctl reload nginx
  144. yunohost app ssowatconf