remove 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. ynh_script_progression --message="Removing snmpd service integration..."
  25. yunohost service remove snmpd
  26. ynh_script_progression --message="Removing Zabbix-server service integration..."
  27. yunohost service remove zabbix-server
  28. ynh_script_progression --message="Removing Zabbix-agent service integration..."
  29. yunohost service remove zabbix-agent
  30. #=================================================
  31. # STOP AND REMOVE SERVICE
  32. #=================================================
  33. ynh_script_progression --message="Stopping and removing the systemd service..."
  34. # Remove the dedicated systemd config
  35. ynh_systemd_action --service_name=$app-server --action="stop" --log_path="/var/log/$app/${app}_server.log"
  36. ynh_systemd_action --service_name=$app-agent --action="stop" --log_path="/var/log/$app/${app}_agent.log"
  37. systemctl disable zabbix-server --quiet
  38. systemctl disable zabbix-agent --quiet
  39. ynh_exec_warn_less killall zabbix_server
  40. ynh_exec_warn_less killall zabbix_agentd
  41. #=================================================
  42. # REMOVE THE MYSQL DATABASE
  43. #=================================================
  44. ynh_script_progression --message="Removing the MySQL database..."
  45. # Remove a database if it exists, along with the associated user
  46. ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
  47. #=================================================
  48. # REMOVE PHP-FPM CONFIGURATION
  49. #=================================================
  50. ynh_script_progression --message="Removing PHP-FPM configuration..."
  51. # Remove the dedicated PHP-FPM config
  52. ynh_remove_fpm_config
  53. #=================================================
  54. # REMOVE DEPENDENCIES
  55. #=================================================
  56. ynh_script_progression --message="Removing dependencies..."
  57. #Remove config file detection
  58. delete_initZabbixConf
  59. DEBIAN_FRONTEND=noninteractive apt-get purge zabbix-release -y
  60. ynh_remove_app_dependencies
  61. ynh_remove_extra_repo --name=$app
  62. #=================================================
  63. # REMOVE APP MAIN DIR
  64. #=================================================
  65. ynh_script_progression --message="Removing app main directory..."
  66. # Remove the app directory securely
  67. ynh_secure_remove --file="$final_path"
  68. ynh_secure_remove --file="/usr/share/$app"
  69. #=================================================
  70. # REMOVE NGINX CONFIGURATION
  71. #=================================================
  72. ynh_script_progression --message="Removing NGINX web server configuration..."
  73. # Remove the dedicated NGINX config
  74. ynh_remove_nginx_config
  75. #=================================================
  76. # CLOSE A PORT
  77. #=================================================
  78. if yunohost firewall list | grep -q "\- $port$"
  79. then
  80. ynh_script_progression --message="Closing port $port..."
  81. ynh_exec_warn_less yunohost firewall disallow TCP $port
  82. fi
  83. #=================================================
  84. # SPECIFIC REMOVE
  85. #=================================================
  86. # REMOVE VARIOUS FILES
  87. #=================================================
  88. ynh_script_progression --message="Removing various files..."
  89. # Remove a directory securely
  90. ynh_secure_remove --file="/etc/$app"
  91. # Remove the log files
  92. ynh_secure_remove --file="/var/log/$app"
  93. ynh_secure_remove --file="/run/$app"
  94. ynh_secure_remove --file="/etc/sudoers.d/$app"
  95. #REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1)
  96. nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free)
  97. if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ]
  98. then
  99. ynh_print_info --message="Removing snmp-mibs-downloader (non-free package)"
  100. cp /var/lib/dpkg/status{,.$(date "+%m%d%y")}
  101. ynh_replace_string --match_string=" snmp-mibs-downloader," --replace_string="" --target_file=/var/lib/dpkg/status
  102. DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y
  103. if [ -f /etc/apt/sources.list.d/non-free.list ]
  104. then
  105. ynh_secure_remove --file="/etc/apt/sources.list.d/non-free.list"
  106. fi
  107. fi
  108. #=================================================
  109. # GENERIC FINALIZATION
  110. #=================================================
  111. # REMOVE DEDICATED USER
  112. #=================================================
  113. ynh_script_progression --message="Removing the dedicated system user..."
  114. # Delete a system user
  115. ynh_system_user_delete --username=$app
  116. #=================================================
  117. # END OF SCRIPT
  118. #=================================================
  119. ynh_script_progression --message="Removal of $app completed"