remove 6.3 KB

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