remove 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. db_name=$(ynh_app_setting_get --app=$app --key=db_name)
  16. db_user=$db_name
  17. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  18. #=================================================
  19. # STANDARD REMOVE
  20. #=================================================
  21. # REMOVE SERVICE INTEGRATION IN YUNOHOST
  22. #=================================================
  23. ynh_script_progression --message="Removing snmpd service integration..."
  24. yunohost service remove snmpd
  25. ynh_script_progression --message="Removing Zabbix-server service integration..."
  26. yunohost service remove zabbix-server
  27. ynh_script_progression --message="Removing Zabbix-agent service integration..."
  28. yunohost service remove zabbix-agent
  29. #=================================================
  30. # STOP AND REMOVE SERVICE
  31. #=================================================
  32. ynh_script_progression --message="Stopping and removing the systemd service..."
  33. # Remove the dedicated systemd config
  34. ynh_systemd_action --service_name=$app-server --action="stop" --log_path="/var/log/$app/${app}_server.log"
  35. ynh_systemd_action --service_name=$app-agent --action="stop" --log_path="/var/log/$app/${app}_agent.log"
  36. systemctl disable zabbix-server --quiet
  37. systemctl disable zabbix-agent --quiet
  38. ynh_exec_warn_less killall zabbix_server
  39. ynh_exec_warn_less killall zabbix_agentd
  40. #=================================================
  41. # REMOVE THE MYSQL DATABASE
  42. #=================================================
  43. ynh_script_progression --message="Removing the MySQL database..."
  44. # Remove a database if it exists, along with the associated user
  45. ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
  46. #=================================================
  47. # REMOVE NGINX CONFIGURATION
  48. #=================================================
  49. ynh_script_progression --message="Removing NGINX web server configuration..."
  50. # Remove the dedicated NGINX config
  51. ynh_remove_nginx_config
  52. #=================================================
  53. # REMOVE PHP-FPM CONFIGURATION
  54. #=================================================
  55. ynh_script_progression --message="Removing PHP-FPM configuration..."
  56. # Remove the dedicated PHP-FPM config
  57. ynh_remove_fpm_config
  58. #=================================================
  59. # REMOVE DEPENDENCIES
  60. #=================================================
  61. ynh_script_progression --message="Removing dependencies..."
  62. #Remove config file detection
  63. delete_initZabbixConf
  64. DEBIAN_FRONTEND=noninteractive apt-get purge zabbix-release -y
  65. ynh_remove_app_dependencies
  66. ynh_remove_extra_repo --name=$app
  67. #=================================================
  68. # REMOVE APP MAIN DIR
  69. #=================================================
  70. ynh_script_progression --message="Removing app main directory..."
  71. # Remove the app directory securely
  72. ynh_secure_remove --file="$final_path"
  73. ynh_secure_remove --file="/usr/share/$app"
  74. #=================================================
  75. # SPECIFIC REMOVE
  76. #=================================================
  77. # REMOVE VARIOUS FILES
  78. #=================================================
  79. ynh_script_progression --message="Removing various files..."
  80. # Remove a directory securely
  81. ynh_secure_remove --file="/etc/$app"
  82. # Remove the log files
  83. ynh_secure_remove --file="/var/log/$app"
  84. ynh_secure_remove --file="/run/$app"
  85. ynh_secure_remove --file="/etc/sudoers.d/$app"
  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 ]
  89. then
  90. ynh_print_info --message="Removing snmp-mibs-downloader (non-free package)"
  91. cp /var/lib/dpkg/status{,.$(date "+%m%d%y")}
  92. ynh_replace_string --match_string=" snmp-mibs-downloader," --replace_string="" --target_file=/var/lib/dpkg/status
  93. DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y
  94. if [ -f /etc/apt/sources.list.d/non-free.list ]
  95. then
  96. ynh_secure_remove --file="/etc/apt/sources.list.d/non-free.list"
  97. fi
  98. fi
  99. #=================================================
  100. # GENERIC FINALIZATION
  101. #=================================================
  102. # REMOVE DEDICATED USER
  103. #=================================================
  104. ynh_script_progression --message="Removing the dedicated system user..."
  105. # Delete a system user
  106. ynh_system_user_delete --username=$app
  107. #=================================================
  108. # END OF SCRIPT
  109. #=================================================
  110. ynh_script_progression --message="Removal of $app completed"