remove 4.7 KB

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