remove 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. ynh_remove_app_dependencies
  65. ynh_remove_extra_repo --name=$app
  66. #=================================================
  67. # REMOVE APP MAIN DIR
  68. #=================================================
  69. ynh_script_progression --message="Removing app main directory..."
  70. # Remove the app directory securely
  71. ynh_secure_remove --file="$final_path"
  72. ynh_secure_remove --file="/usr/share/$app"
  73. #=================================================
  74. # SPECIFIC REMOVE
  75. #=================================================
  76. # REMOVE VARIOUS FILES
  77. #=================================================
  78. ynh_script_progression --message="Removing various files..."
  79. # Remove a directory securely
  80. ynh_secure_remove --file="/etc/$app"
  81. # Remove the log files
  82. ynh_secure_remove --file="/var/log/$app"
  83. ynh_secure_remove --file="/run/$app"
  84. ynh_secure_remove --file="/etc/sudoers.d/$app"
  85. #REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1)
  86. nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free)
  87. if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ]
  88. then
  89. ynh_print_info --message="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 ]
  94. then
  95. ynh_secure_remove --file="/etc/apt/sources.list.d/non-free.list"
  96. fi
  97. fi
  98. #=================================================
  99. # GENERIC FINALIZATION
  100. #=================================================
  101. # REMOVE DEDICATED USER
  102. #=================================================
  103. ynh_script_progression --message="Removing the dedicated system user..."
  104. # Delete a system user
  105. ynh_system_user_delete --username=$app
  106. #=================================================
  107. # END OF SCRIPT
  108. #=================================================
  109. ynh_script_progression --message="Removal of $app completed"