remove 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 "Loading installation 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 "Removing $app service"
  28. yunohost service remove $app
  29. fi
  30. #=================================================
  31. # STOP AND REMOVE SERVICE
  32. #=================================================
  33. ynh_print_info "Stopping and removing the systemd service"
  34. # Remove the dedicated systemd config
  35. ynh_remove_systemd_config
  36. #=================================================
  37. # REMOVE THE MYSQL DATABASE
  38. #=================================================
  39. ynh_print_info "Removing 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 "Removing dependencies"
  46. # Remove metapackage and its dependencies
  47. ynh_remove_app_dependencies
  48. #=================================================
  49. # REMOVE APP MAIN DIR
  50. #=================================================
  51. ynh_print_info "Removing 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 "Removing nginx web server configuration"
  58. # Remove the dedicated nginx config
  59. ynh_remove_nginx_config
  60. #=================================================
  61. # REMOVE PHP-FPM CONFIGURATION
  62. #=================================================
  63. ynh_print_info "Removing 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 "Removing logrotate configuration"
  70. # Remove the app-specific logrotate config
  71. ynh_remove_logrotate
  72. #=================================================
  73. # CLOSE A PORT
  74. #=================================================
  75. if yunohost firewall list | grep -q "\- $port$"
  76. then
  77. ynh_print_info "Closing port $port"
  78. ynh_exec_warn_less yunohost firewall disallow TCP $port
  79. fi
  80. #=================================================
  81. # SPECIFIC REMOVE
  82. #=================================================
  83. # REMOVE THE CRON FILE
  84. #=================================================
  85. # Remove a cron file
  86. ynh_secure_remove "/etc/cron.d/$app"
  87. # Remove a directory securely
  88. ynh_secure_remove "/etc/$app/"
  89. # Remove the log files
  90. ynh_secure_remove "/var/log/$app/"
  91. #=================================================
  92. # GENERIC FINALIZATION
  93. #=================================================
  94. # REMOVE DEDICATED USER
  95. #=================================================
  96. ynh_print_info "Removing the dedicated system user"
  97. # Delete a system user
  98. ynh_system_user_delete $app
  99. #=================================================
  100. # END OF SCRIPT
  101. #=================================================
  102. ynh_print_info "Removal of $app completed"