upgrade 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.0.3-1+stretch"
  14. domain=$(ynh_app_setting_get $app domain)
  15. path_url=$(ynh_app_setting_get $app path)
  16. admin=$(ynh_app_setting_get $app admin)
  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)
  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. #=================================================
  45. # Disable default admin for security issue
  46. #=================================================
  47. haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9")
  48. if [ "$haveDefaultAdminDisabled" -eq 0 ] ;then
  49. echo "Disable default admin"
  50. #disable default admin
  51. lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`")
  52. lastid=$(($lastid + 1 ))
  53. mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);"
  54. else
  55. echo "default admin already disabled"
  56. fi
  57. #=================================================
  58. # CHECK THE PATH
  59. #=================================================
  60. # Normalize the URL path syntax
  61. path_url=$(ynh_normalize_url_path $path_url)
  62. #=================================================
  63. # STANDARD UPGRADE STEPS
  64. #=================================================
  65. ynh_package_update
  66. zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Installed: \K(.*)")
  67. zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Candidate: \K(.*)")
  68. zabbixFrontendInstalledVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Installed: \K(.*)")
  69. zabbixFrontendCandidateVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Candidate: \K(.*)")
  70. zabbixagentInstalledVersion=$(apt-cache policy zabbix-agent | grep -Po "Installed: \K(.*)")
  71. zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | grep -Po "Candidate: \K(.*)")
  72. if [ "$trustedversion" == "$zabbixServerCandidateVersion" ]
  73. then
  74. if [ "$zabbixServerInstalledVersion" != "$zabbixServerCandidateVersion" -o "$zabbixFrontendInstalledVersion" != "$zabbixFrontendCandidateVersion" -o "$zabbixagentInstalledVersion" != "$zabbixagentCandidateVersion" ]
  75. then
  76. #=================================================
  77. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  78. #=================================================
  79. # Backup the current version of the app
  80. ynh_backup_before_upgrade
  81. ynh_clean_setup () {
  82. # restore it if the upgrade fails
  83. ynh_restore_upgradebackup
  84. }
  85. # Exit if an error occurs during the execution of the script
  86. ynh_abort_if_errors
  87. cp -rp /etc/zabbix /tmp/
  88. cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
  89. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  90. DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php
  91. ar x *.deb
  92. tar xzf control.tar.gz
  93. sed -i 's/apache2 | httpd, //' control
  94. tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control
  95. ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz
  96. dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb
  97. rm -fr zabbix-*.deb
  98. apt-get -y --only-upgrade install zabbix-server-mysql zabbix-agent
  99. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  100. rm /usr/share/zabbix/conf/zabbix.conf.php
  101. cp -rpf /tmp/zabbix /etc/
  102. cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
  103. rm -fr /tmp/zabbix*
  104. systemctl reload nginx
  105. else
  106. ynh_print_info "Nothing to update ! (Already up to date)"
  107. fi
  108. else
  109. ynh_print_info "Nothing to update ! (Trusted version)"
  110. fi