remove 6.5 KB

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