remove 4.5 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. 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. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  19. #=================================================
  20. # STANDARD REMOVE
  21. #=================================================
  22. # REMOVE SERVICE INTEGRATION IN YUNOHOST
  23. #=================================================
  24. # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
  25. yunohost service remove snmpd
  26. yunohost service remove zabbix-server
  27. yunohost service remove zabbix-agent
  28. #=================================================
  29. # STOP AND REMOVE SERVICE
  30. #=================================================
  31. ynh_script_progression --message="Stopping and removing the systemd service..."
  32. # Remove the dedicated systemd config
  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. #=================================================
  40. # REMOVE THE MYSQL DATABASE
  41. #=================================================
  42. ynh_script_progression --message="Removing the MySQL database..."
  43. # Remove a database if it exists, along with the associated user
  44. ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
  45. #=================================================
  46. # REMOVE APP MAIN DIR
  47. #=================================================
  48. ynh_script_progression --message="Removing app main directory..."
  49. # Remove the app directory securely
  50. ynh_secure_remove --file="$final_path"
  51. #=================================================
  52. # REMOVE NGINX CONFIGURATION
  53. #=================================================
  54. ynh_script_progression --message="Removing NGINX web server configuration..."
  55. # Remove the dedicated NGINX config
  56. ynh_remove_nginx_config
  57. #=================================================
  58. # REMOVE PHP-FPM CONFIGURATION
  59. #=================================================
  60. ynh_script_progression --message="Removing PHP-FPM configuration..."
  61. # Remove the dedicated PHP-FPM config
  62. ynh_remove_fpm_config
  63. #=================================================
  64. # REMOVE DEPENDENCIES
  65. #=================================================
  66. ynh_script_progression --message="Removing dependencies..."
  67. # Remove config file detection
  68. delete_initZabbixConf
  69. DEBIAN_FRONTEND=noninteractive apt-get purge zabbix-release -y
  70. # Remove metapackage and its dependencies
  71. ynh_remove_app_dependencies
  72. # Force removing if ynh_remove_app_dependencies not work (old zabbix version)
  73. for zabbix_pkg in $(apt list --installed | grep -Po "\K(zabbix-.*)(?=/)")
  74. do
  75. DEBIAN_FRONTEND=noninteractive apt-get purge --allow-change-held-packages "$zabbix_pkg" -y
  76. done
  77. remove_zabbix_repo
  78. #=================================================
  79. # SPECIFIC REMOVE
  80. #=================================================
  81. # REMOVE VARIOUS FILES
  82. #=================================================
  83. ynh_script_progression --message="Removing various files..."
  84. # Remove a directory securely
  85. if [ -d /etc/zabbix ] ;then ynh_secure_remove --file="/etc/$app";fi
  86. # Remove the log files
  87. if [ -d /var/log/zabbix ] ;then ynh_secure_remove --file="/var/log/$app";fi
  88. # Remove the pid/socket files
  89. if [ -d /run/zabbix ] ;then ynh_secure_remove --file="/run/zabbix";fi
  90. # Remove the sudoers file
  91. if [ -f /etc/sudoers.d/zabbix ] ;then ynh_secure_remove --file="/etc/sudoers.d/zabbix";fi
  92. #=================================================
  93. # GENERIC FINALIZATION
  94. #=================================================
  95. # REMOVE DEDICATED USER
  96. #=================================================
  97. ynh_script_progression --message="Removing the dedicated system user..."
  98. # Delete a system user
  99. ynh_system_user_delete --username=$app
  100. #=================================================
  101. # END OF SCRIPT
  102. #=================================================
  103. ynh_script_progression --message="Removal of $app completed"