remove 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/bash
  2. #=================================================
  3. # IMPORT GENERIC HELPERS
  4. #=================================================
  5. source _common.sh
  6. source /usr/share/yunohost/helpers
  7. #=================================================
  8. # REMOVE SYSTEM CONFIGURATIONS
  9. #=================================================
  10. ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
  11. # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
  12. if ynh_exec_warn_less yunohost service status "pihole-FTL" >/dev/null; then
  13. yunohost service remove "pihole-FTL"
  14. fi
  15. ynh_systemd_action --service_name="pihole-FTL" --action="stop"
  16. # Restore dnsmasq as main DNS resolver
  17. # Move dnsmasq back to its original place
  18. #if [ -e "/usr/sbin/dnsmasq.backup_by_pihole" ]
  19. #then # Remove dnsmasq only if we have its backup
  20. # ynh_secure_remove --file="/usr/sbin/dnsmasq"
  21. # mv /usr/sbin/dnsmasq.backup_by_pihole /usr/sbin/dnsmasq
  22. #fi
  23. # Move back the service configuration for dnsmasq
  24. #ynh_secure_remove --file="/etc/systemd/system/dnsmasq.service"
  25. #mv /lib/systemd/system/.dnsmasq.service.backup_by_pihole /lib/systemd/system/dnsmasq.service
  26. #mv /etc/init.d/.dnsmasq.backup_by_pihole /etc/init.d/dnsmasq
  27. systemctl unmask dnsmasq.service
  28. #ynh_exec_warn_less systemctl enable dnsmasq --quiet
  29. # Reload systemd config
  30. systemctl daemon-reload
  31. ynh_secure_remove --file="/etc/init.d/pihole-FTL"
  32. ynh_secure_remove --file="/usr/bin/pihole-FTL"
  33. ynh_secure_remove --file="/var/run/pihole-FTL.pid"
  34. ynh_secure_remove --file="/var/run/pihole-FTL.port"
  35. # Remove the dedicated NGINX config
  36. ynh_remove_nginx_config
  37. # Remove the dedicated PHP-FPM config
  38. ynh_remove_fpm_config
  39. #=================================================
  40. # CLOSE A PORT
  41. #=================================================
  42. if yunohost firewall list | grep -q "\- $port$"; then
  43. ynh_script_progression --message="Closing port $port..." --weight=1
  44. ynh_exec_warn_less yunohost firewall disallow TCP "$port"
  45. fi
  46. if yunohost firewall list | grep -q "\- 67$"; then
  47. ynh_script_progression --message="Closing port 67..." --weight=1
  48. ynh_exec_warn_less yunohost firewall disallow UDP 67
  49. fi
  50. #=================================================
  51. # REMOVE VARIOUS FILES
  52. #=================================================
  53. ynh_script_progression --message="Removing various files..." --weight=1
  54. # Remove a cron file
  55. ynh_secure_remove --file="/etc/cron.d/$app"
  56. # Remove the log files
  57. ynh_secure_remove --file="/var/log/$app"
  58. # Remove main script
  59. ynh_secure_remove --file="$PI_HOLE_BIN_DIR/pihole"
  60. ynh_secure_remove --file="/etc/bash_completion.d/pihole"
  61. # Remove sudoer file
  62. ynh_secure_remove --file="/etc/sudoers.d/pihole"
  63. # Remove storage directory
  64. ynh_secure_remove --file="$PI_HOLE_CONFIG_DIR"
  65. # Remove app directory
  66. ynh_secure_remove --file="$PI_HOLE_INSTALL_DIR"
  67. # Remove local clone of the repository
  68. ynh_secure_remove --file="$PI_HOLE_LOCAL_REPO"
  69. #=================================================
  70. # REMOVE DNSMASQ CONFIG
  71. #=================================================
  72. ynh_script_progression --message="Removing Dnsmasq config..." --weight=2
  73. ynh_secure_remove --file="/etc/dnsmasq.d/03-pihole-wildcard.conf"
  74. #=================================================
  75. # CLEAN /etc/hosts
  76. #=================================================
  77. ynh_script_progression --message="Clean /etc/hosts" --weight=1
  78. # Uncomment lines in /etc/hosts
  79. ynh_replace_string --match_string="#Commented by pihole# " --replace_string="" --target_file=/etc/hosts
  80. # And remove extra lines, added by PiHole
  81. sed -i "/#Added by pihole#/d" /etc/hosts
  82. #=================================================
  83. # REMOVE CONF_REGEN HOOK
  84. #=================================================
  85. ynh_script_progression --message="Removing conf_regen hook..." --weight=1
  86. ynh_systemd_action --service_name=dnsmasq --action=stop
  87. ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
  88. ynh_exec_warn_less yunohost tools regen-conf dnsmasq
  89. #=================================================
  90. # RESTART DNSMASQ
  91. #=================================================
  92. ynh_script_progression --message="Restarting Dnsmasq..." --weight=1
  93. ynh_systemd_action --service_name=dnsmasq --action=restart
  94. #=================================================
  95. # REMOVE DEDICATED USER
  96. #=================================================
  97. # Dirty hack to remove correctly the user
  98. killall -u "$app"
  99. #=================================================
  100. # END OF SCRIPT
  101. #=================================================
  102. ynh_script_progression --message="Removal of $app completed" --last