remove 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. domain=$(ynh_app_setting_get "$app" domain)
  14. port=$(ynh_app_setting_get "$app" port)
  15. db_name=$(ynh_app_setting_get "$app" db_name)
  16. db_user=$db_name
  17. #final_path=$(ynh_app_setting_get "$app" final_path) #not used
  18. #=================================================
  19. # REMOVE SERVICE FROM ADMIN PANEL
  20. #=================================================
  21. # Remove a service from the admin panel, added by `yunohost service add`
  22. yunohost service remove snmpd
  23. yunohost service remove zabbix-server
  24. yunohost service remove zabbix-agent
  25. #=================================================
  26. # REMOVE PHP-FPM CONFIGURATION
  27. #=================================================
  28. # Remove the dedicated php-fpm config
  29. ynh_remove_fpm_config
  30. #=================================================
  31. # REMOVE DEPENDENCIES
  32. #=================================================
  33. timeout 5 systemctl stop zabbix-server || killall zabbix_server
  34. systemctl disable zabbix-server --quiet
  35. killall zabbix_server
  36. timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd
  37. systemctl disable zabbix-agent --quiet
  38. killall zabbix_agentd
  39. #Remove config file detection
  40. delete_initZabbixConf
  41. DEBIAN_FRONTEND=noninteractive apt-get purge zabbix-release -y
  42. ynh_remove_app_dependencies
  43. #force removing if ynh_remove_app_dependencies not work (old zabbix version)
  44. for zabbix_pkg in $(apt list --installed | grep -Po "\K(zabbix-.*)(?=/)")
  45. do
  46. DEBIAN_FRONTEND=noninteractive apt-get purge --allow-change-held-packages "$zabbix_pkg" -y
  47. done
  48. #=================================================
  49. # REMOVE THE MYSQL DATABASE
  50. #=================================================
  51. # Remove a database if it exists, along with the associated user
  52. ynh_mysql_remove_db "$db_user" "$db_name"
  53. #=================================================
  54. # REMOVE NGINX CONFIGURATION
  55. #=================================================
  56. # Remove the dedicated nginx config
  57. ynh_remove_nginx_config
  58. #=================================================
  59. # REMOVE LOGROTATE CONFIGURATION
  60. #=================================================
  61. # Remove the app-specific logrotate config
  62. ynh_remove_logrotate
  63. #=================================================
  64. # CLOSE A PORT
  65. #=================================================
  66. if yunohost firewall list | grep -q "\- $port$"
  67. then
  68. echo "Close port $port" >&2
  69. yunohost firewall disallow TCP "$port" 2>&1
  70. fi
  71. #=================================================
  72. # SPECIFIC REMOVE
  73. #=================================================
  74. # REMOVE THE CRON FILE
  75. #=================================================
  76. remove_zabbix_repo
  77. if [ -d /var/www/zabbix ] ;then ynh_secure_remove /var/www/zabbix;fi
  78. # Remove a directory securely
  79. if [ -d /etc/zabbix ] ;then ynh_secure_remove "/etc/zabbix";fi
  80. # Remove the log files
  81. if [ -d /var/log/zabbix ] ;then ynh_secure_remove "/var/log/zabbix";fi
  82. # Remove the pid/socket files
  83. if [ -d /run/zabbix ] ;then ynh_secure_remove "/run/zabbix";fi
  84. # Remove the sudoers file
  85. if [ -f /etc/sudoers.d/zabbix ] ;then ynh_secure_remove "/etc/sudoers.d/zabbix";fi
  86. #REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1)
  87. nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free)
  88. if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then
  89. ynh_print_info "Removing snmp-mibs-downloader (non-free package)"
  90. cp /var/lib/dpkg/status{,.$(date "+%m%d%y")}
  91. ynh_replace_string --match_string=" snmp-mibs-downloader," --replace_string="" --target_file=/var/lib/dpkg/status
  92. DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y
  93. if [ -f /etc/apt/sources.list.d/non-free.list ];then
  94. ynh_secure_remove /etc/apt/sources.list.d/non-free.list
  95. fi
  96. fi
  97. #=================================================
  98. # GENERIC FINALIZATION
  99. #=================================================
  100. # REMOVE DEDICATED USER
  101. #=================================================
  102. # Delete a system user
  103. ynh_system_user_delete zabbix