upgrade 6.8 KB

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