remove 6.3 KB

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