remove 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  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="Load settings" --weight=2
  13. app=$YNH_APP_INSTANCE_NAME
  14. domain=$(ynh_app_setting_get $app domain)
  15. port=$(ynh_app_setting_get $app port)
  16. #=================================================
  17. # STANDARD REMOVE
  18. #=================================================
  19. # REMOVE SERVICE FROM ADMIN PANEL
  20. #=================================================
  21. # Check if the service is declared in YunoHost
  22. if ynh_exec_fully_quiet yunohost service status pihole-FTL
  23. then
  24. ynh_print_info "Remove pihole-FTL service" >&2
  25. yunohost service remove pihole-FTL
  26. fi
  27. #=================================================
  28. # STOP PIHOLE-FTL SERVICE
  29. #=================================================
  30. ynh_script_progression --message="Stop and remove the service"
  31. ynh_systemd_action --action=stop --service_name=pihole-FTL
  32. ynh_exec_warn_less systemctl disable pihole-FTL
  33. rm -f "/etc/init.d/pihole-FTL" "/usr/bin/pihole-FTL" "/var/run/pihole-FTL.pid" "/var/run/pihole-FTL.port"
  34. #=================================================
  35. # REMOVE DEPENDENCIES
  36. #=================================================
  37. ynh_script_progression --message="Remove dependencies" --weight=7
  38. # Remove metapackage and its dependencies
  39. ynh_remove_app_dependencies
  40. #=================================================
  41. # REMOVE THE DIRECTORIES OF THE APP
  42. #=================================================
  43. ynh_script_progression --message="Remove app main directories"
  44. # Remove storage directory
  45. ynh_secure_remove "/etc/pihole"
  46. # Remove app directory
  47. ynh_secure_remove "/opt/pihole"
  48. # Remove admin panel directory
  49. ynh_secure_remove "/var/www/pihole"
  50. # Remove local clone of the repository
  51. ynh_secure_remove "/etc/.pihole"
  52. #=================================================
  53. # REMOVE NGINX CONFIGURATION
  54. #=================================================
  55. ynh_script_progression --message="Remove nginx configuration"
  56. # Remove the dedicated nginx config
  57. ynh_remove_nginx_config
  58. #=================================================
  59. # REMOVE PHP-FPM CONFIGURATION
  60. #=================================================
  61. ynh_script_progression --message="Remove php-fpm configuration" --weight=2
  62. # Remove the dedicated php-fpm config
  63. ynh_remove_fpm_config
  64. #=================================================
  65. # CLOSE PORTS
  66. #=================================================
  67. ynh_script_progression --message="Close ports" --weight=13
  68. if yunohost firewall list | grep -q "\- $port$"
  69. then
  70. ynh_print_info "Close port $port" >&2
  71. ynh_exec_quiet yunohost firewall disallow TCP $port
  72. fi
  73. if yunohost firewall list | grep -q "\- 67$"
  74. then
  75. ynh_print_info "Close port 67" >&2
  76. ynh_exec_quiet yunohost firewall disallow UDP 67
  77. fi
  78. #=================================================
  79. # SPECIFIC REMOVE
  80. #=================================================
  81. # REMOVE CRON FILE
  82. #=================================================
  83. ynh_secure_remove "/etc/cron.d/pihole"
  84. #=================================================
  85. # REMOVE OTHER FILES
  86. #=================================================
  87. # Remove logs
  88. ynh_secure_remove "/var/log/pihole.log"
  89. ynh_secure_remove "/var/log/pihole-FTL.log"
  90. # Remove main script
  91. ynh_secure_remove "/usr/local/bin/pihole"
  92. ynh_secure_remove "/etc/bash_completion.d/pihole"
  93. # Remove sudoer file
  94. ynh_secure_remove "/etc/sudoers.d/pihole"
  95. #=================================================
  96. # REMOVE DNSMASQ CONFIG
  97. #=================================================
  98. ynh_script_progression --message="Remove Dnsmasq config" --weight=2
  99. ynh_systemd_action --action=stop --service_name=dnsmasq
  100. rm -f "/etc/dnsmasq.d/01-pihole.conf"
  101. rm -f "/etc/dnsmasq.d/02-pihole-dhcp.conf"
  102. rm -f "/etc/dnsmasq.d/03-pihole-wildcard.conf"
  103. rm -f "/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
  104. ynh_replace_string "#pihole# " "" /etc/dnsmasq.conf
  105. #=================================================
  106. # CLEAN /etc/hosts
  107. #=================================================
  108. ynh_script_progression --message="Clean /etc/hosts"
  109. # Uncomment lines in /etc/hosts
  110. sed -i "s/#Commented by pihole# //g" /etc/hosts
  111. # And remove extra lines, added by PiHole
  112. sed -i "/#Added by pihole#/d" /etc/hosts
  113. #=================================================
  114. # RESTART DNSMASQ
  115. #=================================================
  116. ynh_script_progression --message="Restart Dnsmasq"
  117. ynh_systemd_action --action=restart --service_name=dnsmasq
  118. #=================================================
  119. # REMOVE CONF_REGEN HOOK
  120. #=================================================
  121. ynh_secure_remove /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
  122. #=================================================
  123. # GENERIC FINALISATION
  124. #=================================================
  125. # REMOVE DEDICATED USER
  126. #=================================================
  127. ynh_script_progression --message="Remove the dedicated user" --weight=2
  128. ynh_system_user_delete $app
  129. #=================================================
  130. # END OF SCRIPT
  131. #=================================================
  132. ynh_script_progression --message="Deletion completed" --last