remove 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 APP MAIN DIR
  54. #=================================================
  55. ynh_script_progression --message="Removing app main directory..." --weight=1
  56. # Remove the app directory securely
  57. ynh_secure_remove --file="$final_path"
  58. #=================================================
  59. # REMOVE NGINX CONFIGURATION
  60. #=================================================
  61. ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
  62. # Remove the dedicated NGINX config
  63. ynh_remove_nginx_config
  64. #=================================================
  65. # REMOVE PHP-FPM CONFIGURATION
  66. #=================================================
  67. ynh_script_progression --message="Removing PHP-FPM configuration..." --weight=2
  68. # Remove the dedicated PHP-FPM config
  69. ynh_remove_fpm_config
  70. #=================================================
  71. # REMOVE DEPENDENCIES
  72. #=================================================
  73. ynh_script_progression --message="Removing dependencies..." --weight=7
  74. # Remove metapackage and its dependencies
  75. ynh_remove_app_dependencies
  76. #=================================================
  77. # CLOSE A PORT
  78. #=================================================
  79. if yunohost firewall list | grep -q "\- $port$"
  80. then
  81. ynh_script_progression --message="Closing port $port..." --weight=1
  82. ynh_exec_warn_less yunohost firewall disallow TCP $port
  83. fi
  84. if yunohost firewall list | grep -q "\- 67$"
  85. then
  86. ynh_script_progression --message="Closing port 67..." --weight=1
  87. ynh_exec_warn_less yunohost firewall disallow UDP 67
  88. fi
  89. #=================================================
  90. # SPECIFIC REMOVE
  91. #=================================================
  92. # REMOVE VARIOUS FILES
  93. #=================================================
  94. ynh_script_progression --message="Removing various files..." --weight=1
  95. # Remove a cron file
  96. ynh_secure_remove --file="/etc/cron.d/$app"
  97. # Remove the log files
  98. ynh_secure_remove --file="/var/log/$app"
  99. # Remove main script
  100. ynh_secure_remove --file="$PI_HOLE_BIN_DIR/pihole"
  101. ynh_secure_remove --file="/etc/bash_completion.d/pihole"
  102. # Remove sudoer file
  103. ynh_secure_remove --file="/etc/sudoers.d/pihole"
  104. # Remove storage directory
  105. ynh_secure_remove --file="$PI_HOLE_CONFIG_DIR"
  106. # Remove app directory
  107. ynh_secure_remove --file="$PI_HOLE_INSTALL_DIR"
  108. # Remove local clone of the repository
  109. ynh_secure_remove --file="$PI_HOLE_LOCAL_REPO"
  110. #=================================================
  111. # REMOVE DNSMASQ CONFIG
  112. #=================================================
  113. ynh_script_progression --message="Removing Dnsmasq config..." --weight=2
  114. ynh_secure_remove --file="/etc/dnsmasq.d/03-pihole-wildcard.conf"
  115. #=================================================
  116. # CLEAN /etc/hosts
  117. #=================================================
  118. ynh_script_progression --message="Clean /etc/hosts" --weight=1
  119. # Uncomment lines in /etc/hosts
  120. ynh_replace_string --match_string="#Commented by pihole# " --replace_string="" --target_file=/etc/hosts
  121. # And remove extra lines, added by PiHole
  122. sed -i "/#Added by pihole#/d" /etc/hosts
  123. #=================================================
  124. # REMOVE CONF_REGEN HOOK
  125. #=================================================
  126. ynh_script_progression --message="Removing conf_regen hook..." --weight=1
  127. ynh_systemd_action --action=stop --service_name=dnsmasq
  128. ynh_secure_remove --file=/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
  129. ynh_exec_warn_less yunohost tools regen-conf dnsmasq
  130. #=================================================
  131. # RESTART DNSMASQ
  132. #=================================================
  133. ynh_script_progression --message="Restarting Dnsmasq..." --weight=1
  134. ynh_systemd_action --action=restart --service_name=dnsmasq
  135. #=================================================
  136. # GENERIC FINALIZATION
  137. #=================================================
  138. # REMOVE DEDICATED USER
  139. #=================================================
  140. ynh_script_progression --message="Removing the dedicated system user..." --weight=2
  141. # Dirty hack to remove correctly the user
  142. killall -u $app
  143. # Delete a system user
  144. ynh_system_user_delete --username=$app
  145. #=================================================
  146. # END OF SCRIPT
  147. #=================================================
  148. ynh_script_progression --message="Removal of $app completed" --last