remove 6.2 KB

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