remove 4.5 KB

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