remove 3.8 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_print_info "Load settings"
  13. app=$YNH_APP_INSTANCE_NAME
  14. domain=$(ynh_app_setting_get $app domain)
  15. port=$(ynh_app_setting_get $app port)
  16. db_name=$(ynh_app_setting_get $app db_name)
  17. db_user=$db_name
  18. final_path=$(ynh_app_setting_get $app final_path)
  19. #=================================================
  20. # STANDARD REMOVE
  21. #=================================================
  22. # REMOVE SERVICE FROM ADMIN PANEL
  23. #=================================================
  24. # Remove a service from the admin panel, added by `yunohost service add`
  25. if yunohost service status | grep -q $app
  26. then
  27. ynh_print_info "Remove $app service"
  28. yunohost service remove $app
  29. fi
  30. #=================================================
  31. # STOP AND REMOVE SERVICE
  32. #=================================================
  33. ynh_print_info "Stop and remove the service"
  34. # Remove the dedicated systemd config
  35. ynh_remove_systemd_config
  36. #=================================================
  37. # REMOVE THE MYSQL DATABASE
  38. #=================================================
  39. ynh_print_info "Remove the mysql database"
  40. # Remove a database if it exists, along with the associated user
  41. ynh_mysql_remove_db $db_user $db_name
  42. #=================================================
  43. # REMOVE DEPENDENCIES
  44. #=================================================
  45. ynh_print_info "Remove dependencies"
  46. # Remove metapackage and its dependencies
  47. ynh_remove_app_dependencies
  48. #=================================================
  49. # REMOVE APP MAIN DIR
  50. #=================================================
  51. ynh_print_info "Remove app main directory"
  52. # Remove the app directory securely
  53. ynh_secure_remove "$final_path"
  54. #=================================================
  55. # REMOVE NGINX CONFIGURATION
  56. #=================================================
  57. ynh_print_info "Remove nginx configuration"
  58. # Remove the dedicated nginx config
  59. ynh_remove_nginx_config
  60. #=================================================
  61. # REMOVE PHP-FPM CONFIGURATION
  62. #=================================================
  63. ynh_print_info "Remove php-fpm configuration"
  64. # Remove the dedicated php-fpm config
  65. ynh_remove_fpm_config
  66. #=================================================
  67. # REMOVE LOGROTATE CONFIGURATION
  68. #=================================================
  69. ynh_print_info "Remove logrotate configuration"
  70. # Remove the app-specific logrotate config
  71. ynh_remove_logrotate
  72. #=================================================
  73. # CLOSE A PORT
  74. #=================================================
  75. ynh_print_info "Close ports"
  76. if yunohost firewall list | grep -q "\- $port$"
  77. then
  78. ynh_print_info "Close port $port"
  79. ynh_exec_warn_less yunohost firewall disallow TCP $port
  80. fi
  81. #=================================================
  82. # SPECIFIC REMOVE
  83. #=================================================
  84. # REMOVE THE CRON FILE
  85. #=================================================
  86. # Remove a cron file
  87. ynh_secure_remove "/etc/cron.d/$app"
  88. # Remove a directory securely
  89. ynh_secure_remove "/etc/$app/"
  90. # Remove the log files
  91. ynh_secure_remove "/var/log/$app/"
  92. #=================================================
  93. # GENERIC FINALIZATION
  94. #=================================================
  95. # REMOVE DEDICATED USER
  96. #=================================================
  97. ynh_print_info "Remove the dedicated user"
  98. # Delete a system user
  99. ynh_system_user_delete $app
  100. #=================================================
  101. # END OF SCRIPT
  102. #=================================================
  103. ynh_print_info "Deletion completed"