remove 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/bin/bash
  2. # PirateBox app for YunoHost
  3. # Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  4. # Contribute at https://github.com/labriqueinternet/piratebox_ynh
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #=================================================
  19. # GENERIC START
  20. #=================================================
  21. # IMPORT GENERIC HELPERS
  22. #=================================================
  23. source _common.sh
  24. source /usr/share/yunohost/helpers
  25. #=================================================
  26. # LOAD SETTINGS
  27. #=================================================
  28. ynh_script_progression --message="Loading installation settings..." --time --weight=1
  29. app=$YNH_APP_INSTANCE_NAME
  30. domain=$(ynh_app_setting_get --app=$app --key=domain)
  31. web_port=$(ynh_app_setting_get --app=$app --key=web_port)
  32. dns_port=$(ynh_app_setting_get --app=$app --key=dns_port)
  33. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  34. final_path_admin=$(ynh_app_setting_get --app=$app --key=final_path_admin)
  35. final_path_tmp=$(ynh_app_setting_get --app=$app --key=final_path_tmp)
  36. #=================================================
  37. # STANDARD REMOVE
  38. #=================================================
  39. # REMOVE SERVICE FROM ADMIN PANEL
  40. #=================================================
  41. # Remove a service from the admin panel, added by `yunohost service add`
  42. if ynh_exec_warn_less yunohost service status $app >/dev/null
  43. then
  44. ynh_script_progression --message="Removing $app service..." --time --weight=1
  45. yunohost service remove $app
  46. fi
  47. #=================================================
  48. # STOP AND REMOVE SERVICE
  49. #=================================================
  50. ynh_script_progression --message="Stopping and removing the systemd service..." --time --weight=1
  51. # Remove the dedicated systemd config
  52. ynh_remove_systemd_config "ynh-piratebox"
  53. #=================================================
  54. # REMOVE DEPENDENCIES
  55. #=================================================
  56. ynh_script_progression --message="Removing dependencies..." --time --weight=1
  57. # Remove metapackage and its dependencies
  58. ynh_remove_app_dependencies
  59. #=================================================
  60. # REMOVE APP MAIN DIR
  61. #=================================================
  62. ynh_script_progression --message="Removing app main directory..." --time --weight=1
  63. # Remove the app directory securely
  64. ynh_secure_remove --file="$final_path"
  65. ynh_secure_remove --file="$final_path_admin"
  66. ynh_secure_remove --file="$final_path_tmp"
  67. # Delete fakedns
  68. ynh_secure_remove --file="/usr/local/bin/piratebox_fakedns"
  69. ynh_secure_remove "/etc/sudoers.d/${app}_ynh"
  70. #=================================================
  71. # REMOVE NGINX CONFIGURATION
  72. #=================================================
  73. ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1
  74. # Remove the dedicated nginx config
  75. ynh_secure_remove --file="/etc/nginx/captive-piratebox.conf"
  76. ynh_remove_nginx_config
  77. #=================================================
  78. # REMOVE PHP-FPM CONFIGURATION
  79. #=================================================
  80. ynh_script_progression --message="Removing php-fpm configuration..." --time --weight=1
  81. # Remove the dedicated php-fpm config
  82. ynh_secure_remove --file="/etc/php/7.0/fpm/pool.d/captive-piratebox.conf"
  83. ynh_remove_fpm_config
  84. #=================================================
  85. # CLOSE A PORT
  86. #=================================================
  87. if yunohost firewall list | grep -q "\- $web_port$"
  88. then
  89. ynh_script_progression --message="Closing port $web_port..."
  90. ynh_exec_warn_less yunohost firewall disallow TCP $web_port
  91. fi
  92. if yunohost firewall list | grep -q "\- $dns_port$"
  93. then
  94. ynh_script_progression --message="Closing port $dns_port..."
  95. ynh_exec_warn_less yunohost firewall disallow UDP $dns_port
  96. fi
  97. #=================================================
  98. # SPECIFIC REMOVE
  99. #=================================================
  100. # REMOVE FILES
  101. #=================================================
  102. # Remove the log files
  103. ynh_secure_remove --file="/var/log/$app/"
  104. #=================================================
  105. # GENERIC FINALIZATION
  106. #=================================================
  107. # REMOVE DEDICATED USER
  108. #=================================================
  109. ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1
  110. # Delete a system user
  111. ynh_system_user_delete --username=$app
  112. #=================================================
  113. # END OF SCRIPT
  114. #=================================================
  115. ynh_script_progression --message="Removal of $app completed" --time --last