| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- #!/bin/bash
- #=================================================
- # GENERIC STARTING
- #=================================================
- # IMPORT GENERIC HELPERS
- #=================================================
- source _common.sh
- source /usr/share/yunohost/helpers
- #=================================================
- # LOAD SETTINGS
- #=================================================
- ynh_script_progression --message="Loading installation settings..." --weight=2
- app=$YNH_APP_INSTANCE_NAME
- domain=$(ynh_app_setting_get --app=$app --key=domain)
- port=$(ynh_app_setting_get --app=$app --key=port)
- #=================================================
- # STANDARD REMOVE
- #=================================================
- # REMOVE SERVICE FROM ADMIN PANEL
- #=================================================
- # Check if the service is declared in YunoHost
- if ynh_exec_fully_quiet yunohost service status pihole-FTL
- then
- ynh_script_progression --message="Removing pihole-FTL service..." --weight=2
- yunohost service remove pihole-FTL
- fi
- #=================================================
- # STOP PIHOLE-FTL SERVICE
- #=================================================
- ynh_script_progression --message="Stop and remove the service"
- ynh_systemd_action --action=stop --service_name=pihole-FTL
- # Restore dnsmasq as main DNS resolver
- # Move dnsmasq back to its original place
- #if [ -e "/usr/sbin/dnsmasq.backup_by_pihole" ]
- #then # Remove dnsmasq only if we have its backup
- # ynh_secure_remove --file="/usr/sbin/dnsmasq"
- # mv /usr/sbin/dnsmasq.backup_by_pihole /usr/sbin/dnsmasq
- #fi
- # Move back the service configuration for dnsmasq
- #ynh_secure_remove --file="/etc/systemd/system/dnsmasq.service"
- #mv /lib/systemd/system/.dnsmasq.service.backup_by_pihole /lib/systemd/system/dnsmasq.service
- #mv /etc/init.d/.dnsmasq.backup_by_pihole /etc/init.d/dnsmasq
- systemctl unmask dnsmasq.service
- #ynh_exec_warn_less systemctl enable dnsmasq --quiet
- # Reload systemd config
- systemctl daemon-reload
- ynh_secure_remove --file="/etc/init.d/pihole-FTL"
- ynh_secure_remove --file="/usr/bin/pihole-FTL"
- ynh_secure_remove --file="/var/run/pihole-FTL.pid"
- ynh_secure_remove --file="/var/run/pihole-FTL.port"
- #=================================================
- # REMOVE DEPENDENCIES
- #=================================================
- ynh_script_progression --message="Removing dependencies..." --weight=7
- # Remove metapackage and its dependencies
- ynh_remove_app_dependencies
- #=================================================
- # REMOVE THE DIRECTORIES OF THE APP
- #=================================================
- ynh_script_progression --message="Removing app main directory..."
- # Remove storage directory
- ynh_secure_remove --file="/etc/pihole"
- # Remove app directory
- ynh_secure_remove --file="/opt/pihole"
- # Remove admin panel directory
- ynh_secure_remove --file="/var/www/pihole"
- # Remove local clone of the repository
- ynh_secure_remove --file="/etc/.pihole"
- #=================================================
- # REMOVE NGINX CONFIGURATION
- #=================================================
- ynh_script_progression --message="Removing NGINX web server configuration..."
- # Remove the dedicated nginx config
- ynh_remove_nginx_config
- #=================================================
- # REMOVE PHP-FPM CONFIGURATION
- #=================================================
- ynh_script_progression --message="Removing PHP-FPM configuration..." --weight=2
- # Remove the dedicated php-fpm config
- ynh_remove_fpm_config
- #=================================================
- # CLOSE PORTS
- #=================================================
- ynh_script_progression --message="Closing ports $port and 67..." --weight=13
- if yunohost firewall list | grep -q "\- $port$"
- then
- ynh_print_info "Close port $port"
- ynh_exec_quiet yunohost firewall disallow TCP $port
- fi
- if yunohost firewall list | grep -q "\- 67$"
- then
- ynh_print_info "Close port 67"
- ynh_exec_quiet yunohost firewall disallow UDP 67
- fi
- #=================================================
- # SPECIFIC REMOVE
- #=================================================
- # REMOVE CRON FILE
- #=================================================
- ynh_secure_remove --file="/etc/cron.d/pihole"
- #=================================================
- # REMOVE OTHER FILES
- #=================================================
- # Remove logs
- ynh_secure_remove --file="/var/log/pihole.log"
- ynh_secure_remove --file="/var/log/pihole-FTL.log"
- # Remove main script
- ynh_secure_remove --file="/usr/local/bin/pihole"
- ynh_secure_remove --file="/etc/bash_completion.d/pihole"
- # Remove sudoer file
- ynh_secure_remove --file="/etc/sudoers.d/pihole"
- #=================================================
- # REMOVE DNSMASQ CONFIG
- #=================================================
- ynh_script_progression --message="Removing Dnsmasq config..." --weight=2
- ynh_secure_remove --file="/etc/dnsmasq.d/03-pihole-wildcard.conf"
- #=================================================
- # CLEAN /etc/hosts
- #=================================================
- ynh_script_progression --message="Clean /etc/hosts"
- # Uncomment lines in /etc/hosts
- ynh_replace_string --match_string="#Commented by pihole# " --replace_string="" --target_file=/etc/hosts
- # And remove extra lines, added by PiHole
- sed -i "/#Added by pihole#/d" /etc/hosts
- #=================================================
- # REMOVE CONF_REGEN HOOK
- #=================================================
- ynh_systemd_action --action=stop --service_name=dnsmasq
- ynh_secure_remove --file=/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
- ynh_exec_warn_less yunohost tools regen-conf dnsmasq
- #=================================================
- # RESTART DNSMASQ
- #=================================================
- ynh_script_progression --message="Restarting Dnsmasq..."
- ynh_systemd_action --action=restart --service_name=dnsmasq
- #=================================================
- # GENERIC FINALISATION
- #=================================================
- # REMOVE DEDICATED USER
- #=================================================
- ynh_script_progression --message="Removing the dedicated system user..." --weight=2
- # Dirty hack to remove correctly the user
- killall -u $app
- ynh_system_user_delete --username=$app
- #=================================================
- # END OF SCRIPT
- #=================================================
- ynh_script_progression --message="Removal of $app completed" --last
|