remove 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #=================================================
  38. # CLOSE A PORT
  39. #=================================================
  40. if yunohost firewall list | grep -q "\- $port$"; then
  41. ynh_script_progression --message="Closing port $port..." --weight=1
  42. ynh_exec_warn_less yunohost firewall disallow TCP "$port"
  43. fi
  44. if yunohost firewall list | grep -q "\- 67$"; then
  45. ynh_script_progression --message="Closing port 67..." --weight=1
  46. ynh_exec_warn_less yunohost firewall disallow UDP 67
  47. fi
  48. #=================================================
  49. # REMOVE VARIOUS FILES
  50. #=================================================
  51. ynh_script_progression --message="Removing various files..." --weight=1
  52. # Remove a cron file
  53. ynh_secure_remove --file="/etc/cron.d/$app"
  54. # Remove main script
  55. ynh_secure_remove --file="$PI_HOLE_BIN_DIR/pihole"
  56. ynh_secure_remove --file="/etc/bash_completion.d/pihole"
  57. # Remove sudoer file
  58. ynh_secure_remove --file="/etc/sudoers.d/pihole"
  59. # Remove storage directory
  60. ynh_secure_remove --file="$PI_HOLE_CONFIG_DIR"
  61. # Remove app directory
  62. ynh_secure_remove --file="$PI_HOLE_INSTALL_DIR"
  63. # Remove local clone of the repository
  64. ynh_secure_remove --file="$PI_HOLE_LOCAL_REPO"
  65. #=================================================
  66. # REMOVE DNSMASQ CONFIG
  67. #=================================================
  68. ynh_script_progression --message="Removing Dnsmasq config..." --weight=2
  69. ynh_secure_remove --file="/etc/dnsmasq.d/03-pihole-wildcard.conf"
  70. #=================================================
  71. # CLEAN /etc/hosts
  72. #=================================================
  73. ynh_script_progression --message="Clean /etc/hosts" --weight=1
  74. # Uncomment lines in /etc/hosts
  75. ynh_replace_string --match_string="#Commented by pihole# " --replace_string="" --target_file=/etc/hosts
  76. # And remove extra lines, added by PiHole
  77. sed -i "/#Added by pihole#/d" /etc/hosts
  78. #=================================================
  79. # REMOVE CONF_REGEN HOOK
  80. #=================================================
  81. ynh_script_progression --message="Removing conf_regen hook..." --weight=1
  82. ynh_systemd_action --service_name=dnsmasq --action=stop
  83. ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
  84. ynh_exec_warn_less yunohost tools regen-conf dnsmasq
  85. #=================================================
  86. # RESTART DNSMASQ
  87. #=================================================
  88. ynh_script_progression --message="Restarting Dnsmasq..." --weight=1
  89. ynh_systemd_action --service_name=dnsmasq --action="restart"
  90. #=================================================
  91. # REMOVE DEDICATED USER
  92. #=================================================
  93. # Dirty hack to remove correctly the user
  94. killall -u "$app"
  95. #=================================================
  96. # END OF SCRIPT
  97. #=================================================
  98. ynh_script_progression --message="Removal of $app completed" --last