upgrade 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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.2.1-1+stretch"
  14. trustedVersionRepo="4.2-1+stretch"
  15. export domain=$(ynh_app_setting_get "$app" domain)
  16. export path_url=$(ynh_app_setting_get "$app" path)
  17. #admin=$(ynh_app_setting_get "$app" admin) #not used
  18. is_public=$(ynh_app_setting_get "$app" is_public)
  19. final_path=$(ynh_app_setting_get "$app" final_path)
  20. #language=$(ynh_app_setting_get "$app" language) #not used
  21. db_name=$(ynh_app_setting_get "$app" db_name)
  22. db_user=$(ynh_app_setting_get "$app" db_user)
  23. db_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
  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. # DISABLED SSOWAT
  48. #=================================================
  49. ynh_print_info "disable SSOWAT temporaly"
  50. ynh_app_setting_set "$app" unprotected_uris "/"
  51. systemctl reload nginx
  52. yunohost app ssowatconf
  53. #=================================================
  54. # Enable default admin temporaly
  55. #=================================================
  56. enable_admin_user
  57. #=================================================
  58. # Import Yunohost template
  59. #=================================================
  60. import_template
  61. #=================================================
  62. # Link Yunohost template to the ZAbbix Server Host
  63. #=================================================
  64. link_template
  65. #=================================================
  66. # Disable default admin for security issue
  67. #=================================================
  68. disable_admin_user
  69. #=================================================
  70. # Disable default guest for security issue
  71. #=================================================
  72. disable_guest_user
  73. #=================================================
  74. # CHECK THE PATH
  75. #=================================================
  76. # Normalize the URL path syntax
  77. path_url=$(ynh_normalize_url_path "$path_url")
  78. #REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1)
  79. nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free)
  80. if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then
  81. ynh_print_info "Removing snmp-mibs-downloader (non-free package)"
  82. sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status
  83. DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y
  84. if [ -f /etc/apt/sources.list.d/non-free.list ];then
  85. ynh_secure_remove /etc/apt/sources.list.d/non-free.list
  86. fi
  87. fi
  88. #Patch timeout too short for zabbix agent if needed
  89. timeout_ok=$(grep -c "^Timeout" /etc/zabbix/zabbix_agentd.conf 2>/dev/null)
  90. if [ $timeout_ok -ne 1 ] ;then
  91. ynh_replace_string --match_string="# Timeout=3" --replace_string="# Timeout=3\nTimeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf
  92. systemctl enable zabbix-agent && systemctl restart zabbix-agent
  93. fi
  94. #patch if zabbix-release installed
  95. if [ "$(dpkg -l zabbix-release 2>/dev/null | wc -l)" -ne 0 ];then
  96. DEBIAN_FRONTEND=noninteractive apt purge zabbix-release -y
  97. ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3")
  98. source "$ynh_add_extra_apt_repos__3_path"
  99. ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.2/debian $(lsb_release -sc) main" --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 --name=zabbix
  100. fi
  101. #=================================================
  102. # STANDARD UPGRADE STEPS
  103. #=================================================
  104. #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED
  105. ynh_remove_logrotate
  106. ynh_print_info "Check if new zabbix version is available on repo"
  107. ynh_package_update
  108. zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | sed -n '2p' | grep -Po ".*: \K(.*)")
  109. zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | sed -n '3p' | grep -Po ".*: \K(.*)")
  110. zabbixFrontendInstalledVersion=$(apt-cache policy zabbix-frontend-php | sed -n '2p' | grep -Po ".*: \K(.*)")
  111. zabbixFrontendCandidateVersion=$(apt-cache policy zabbix-frontend-php | sed -n '3p' | grep -Po ".*: \K(.*)")
  112. zabbixagentInstalledVersion=$(apt-cache policy zabbix-agent | sed -n '2p' | grep -Po ".*: \K(.*)")
  113. zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | sed -n '3p' | grep -Po ".*: \K(.*)")
  114. if [ "$trustedversion" == "$zabbixServerCandidateVersion" ]
  115. then
  116. if [ "$zabbixServerInstalledVersion" != "$zabbixServerCandidateVersion" ] || [ "$zabbixFrontendInstalledVersion" != "$zabbixFrontendCandidateVersion" ] || [ "$zabbixagentInstalledVersion" != "$zabbixagentCandidateVersion" ]
  117. then
  118. #=================================================
  119. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  120. #=================================================
  121. # Backup the current version of the app
  122. ynh_backup_before_upgrade
  123. ynh_clean_setup () {
  124. # restore it if the upgrade fails
  125. ynh_restore_upgradebackup
  126. }
  127. # Exit if an error occurs during the execution of the script
  128. ynh_abort_if_errors
  129. cp -rp /etc/zabbix /tmp/
  130. cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
  131. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  132. ynh_print_info "Update and install dependencies"
  133. ynh_package_update
  134. 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 zabbix-server-mysql zabbix-agent zabbix-frontend-php
  135. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  136. rm /usr/share/zabbix/conf/zabbix.conf.php
  137. cp -rpf /tmp/zabbix /etc/
  138. cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
  139. rm -fr /tmp/zabbix*
  140. #If needed.
  141. yunohost service add snmpd -d "Management of SNMP Daemon"
  142. yunohost service add zabbix-server -d "Management Zabbix server daemon : Collect, agregate, compute and notify"
  143. yunohost service add zabbix-agent -d "Management Zabbix agent daemon : send informations about this host to the server"
  144. #test if zabbix server is started
  145. check_proc_zabbixagent
  146. #test if zabbix agent is started
  147. check_proc_zabbixserver
  148. else
  149. ynh_print_info "No update from repo ! (Already up to date)"
  150. fi
  151. else
  152. ynh_print_info "No update from repo ! (Trusted version)"
  153. fi
  154. #=================================================
  155. # RE-ENABLE SSOWAT
  156. #=================================================
  157. ynh_print_info "re-enable SSOWAT"
  158. # Make app private if necessary
  159. if [ $is_public -eq 0 ]
  160. then
  161. # unprotected_uris allows SSO credentials to be passed anyway.
  162. ynh_app_setting_delete "$app" unprotected_uris
  163. else
  164. ynh_app_setting_set "$app" unprotected_uris "/"
  165. fi
  166. systemctl reload nginx
  167. yunohost app ssowatconf