2015-12-06 14:31:49 +00:00
#!/usr/bin/env bash
2016-01-30 20:12:40 +00:00
# Pi-hole: A black hole for Internet advertisements
2017-02-22 17:55:20 +00:00
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
#
2016-01-30 20:12:40 +00:00
# Completely uninstalls Pi-hole
2015-12-06 14:31:49 +00:00
#
2017-02-22 17:55:20 +00:00
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.
2017-06-21 11:49:05 +00:00
source "/opt/pihole/COL_TABLE"
2017-02-22 17:55:20 +00:00
2017-06-21 11:49:05 +00:00
while true; do
2022-04-12 18:36:49 +00:00
read -rp " ${ QST } Are you sure you would like to remove ${ COL_WHITE } Pi-hole ${ COL_NC } ? [y/N] " answer
case ${ answer } in
2018-05-31 03:14:18 +00:00
[ Yy] * ) break; ;
2020-03-08 23:53:14 +00:00
* ) echo -e " ${ OVER } ${ COL_LIGHT_GREEN } Uninstall has been canceled ${ COL_NC } " ; exit 0; ;
2018-05-31 03:14:18 +00:00
esac
2017-06-21 11:49:05 +00:00
done
2015-12-06 14:31:49 +00:00
2016-01-16 19:56:08 +00:00
# Must be root to uninstall
2017-06-21 11:49:05 +00:00
str = "Root user check"
2016-10-22 06:23:31 +00:00
if [ [ ${ EUID } -eq 0 ] ] ; then
2018-05-31 03:14:18 +00:00
echo -e " ${ TICK } ${ str } "
2016-01-16 19:56:08 +00:00
else
2018-05-31 03:14:18 +00:00
# Check if sudo is actually installed
# If it isn't, exit because the uninstall can not complete
if [ -x " $( command -v sudo) " ] ; then
export SUDO = "sudo"
else
echo -e " ${ CROSS } ${ str }
Script called with non-root privileges
2021-01-19 18:33:38 +00:00
The Pi-hole requires elevated privileges to uninstall"
2018-05-31 03:14:18 +00:00
exit 1
fi
2016-01-16 19:56:08 +00:00
fi
2017-08-17 18:53:43 +00:00
readonly PI_HOLE_FILES_DIR = "/etc/.pihole"
2022-07-06 20:58:14 +00:00
SKIP_INSTALL = "true"
2017-08-17 18:53:43 +00:00
source " ${ PI_HOLE_FILES_DIR } /automated install/basic-install.sh "
2021-08-03 20:48:26 +00:00
# package_manager_detect() sourced from basic-install.sh
package_manager_detect
2017-08-17 18:53:43 +00:00
2024-09-29 20:21:44 +00:00
removeMetaPackage( ) {
# Purge Pi-hole meta package
2018-05-31 03:14:18 +00:00
echo ""
2024-09-29 20:21:44 +00:00
echo -ne " ${ INFO } Removing Pi-hole meta package... " ;
eval " ${ SUDO } " " ${ PKG_REMOVE } " "pihole-meta" & > /dev/null;
echo -e " ${ OVER } ${ INFO } Removed Pi-hole meta package " ;
2018-05-31 03:14:18 +00:00
2016-03-26 20:18:53 +00:00
}
2016-01-16 19:56:08 +00:00
2024-09-29 20:21:44 +00:00
removePiholeFiles( ) {
2018-05-31 03:14:18 +00:00
# Only web directories/files that are created by Pi-hole should be removed
echo -ne " ${ INFO } Removing Web Interface... "
${ SUDO } rm -rf /var/www/html/admin & > /dev/null
2024-09-29 20:21:44 +00:00
2018-05-31 03:14:18 +00:00
2018-07-27 16:35:39 +00:00
# If the web directory is empty after removing these files, then the parent html directory can be removed.
2018-05-31 03:14:18 +00:00
if [ -d "/var/www/html" ] ; then
if [ [ ! " $( ls -A /var/www/html) " ] ] ; then
${ SUDO } rm -rf /var/www/html & > /dev/null
fi
2018-05-29 07:59:39 +00:00
fi
2018-05-31 03:14:18 +00:00
echo -e " ${ OVER } ${ TICK } Removed Web Interface "
2021-08-03 20:48:26 +00:00
2018-05-31 03:14:18 +00:00
# Attempt to preserve backwards compatibility with older versions
# to guarantee no additional changes were made to /etc/crontab after
# the installation of pihole, /etc/crontab.pihole should be permanently
# preserved.
if [ [ -f /etc/crontab.orig ] ] ; then
${ SUDO } mv /etc/crontab /etc/crontab.pihole
${ SUDO } mv /etc/crontab.orig /etc/crontab
${ SUDO } service cron restart
echo -e " ${ TICK } Restored the default system cron "
fi
# Attempt to preserve backwards compatibility with older versions
if [ [ -f /etc/cron.d/pihole ] ] ; then
${ SUDO } rm -f /etc/cron.d/pihole & > /dev/null
echo -e " ${ TICK } Removed /etc/cron.d/pihole "
2018-05-29 07:59:39 +00:00
fi
2018-05-31 03:14:18 +00:00
${ SUDO } rm -rf /var/log/*pihole* & > /dev/null
2022-05-15 18:22:06 +00:00
${ SUDO } rm -rf /var/log/pihole/*pihole* & > /dev/null
2018-05-31 03:14:18 +00:00
${ SUDO } rm -rf /etc/pihole/ & > /dev/null
${ SUDO } rm -rf /etc/.pihole/ & > /dev/null
${ SUDO } rm -rf /opt/pihole/ & > /dev/null
${ SUDO } rm -f /usr/local/bin/pihole & > /dev/null
${ SUDO } rm -f /etc/bash_completion.d/pihole & > /dev/null
${ SUDO } rm -f /etc/sudoers.d/pihole & > /dev/null
echo -e " ${ TICK } Removed config files "
2018-06-01 04:03:13 +00:00
# Restore Resolved
if [ [ -e /etc/systemd/resolved.conf.orig ] ] ; then
2019-04-30 20:41:12 +00:00
${ SUDO } cp -p /etc/systemd/resolved.conf.orig /etc/systemd/resolved.conf
2018-06-01 04:03:13 +00:00
systemctl reload-or-restart systemd-resolved
fi
2018-05-31 03:14:18 +00:00
# Remove FTL
if command -v pihole-FTL & > /dev/null; then
echo -ne " ${ INFO } Removing pihole-FTL... "
if [ [ -x " $( command -v systemctl) " ] ] ; then
systemctl stop pihole-FTL
else
service pihole-FTL stop
fi
2023-02-21 20:49:03 +00:00
${ SUDO } rm -f /etc/systemd/system/pihole-FTL.service
if [ [ -d '/etc/systemd/system/pihole-FTL.service.d' ] ] ; then
read -rp " ${ QST } FTL service override directory /etc/systemd/system/pihole-FTL.service.d detected. Do you wish to remove this from your system? [y/N] " answer
case $answer in
[ yY] *)
echo -ne " ${ INFO } Removing /etc/systemd/system/pihole-FTL.service.d... "
${ SUDO } rm -R /etc/systemd/system/pihole-FTL.service.d
echo -e " ${ OVER } ${ INFO } Removed /etc/systemd/system/pihole-FTL.service.d "
; ;
*) echo -e " ${ INFO } Leaving /etc/systemd/system/pihole-FTL.service.d in place. " ; ;
esac
fi
2018-05-31 03:14:18 +00:00
${ SUDO } rm -f /etc/init.d/pihole-FTL
${ SUDO } rm -f /usr/bin/pihole-FTL
echo -e " ${ OVER } ${ TICK } Removed pihole-FTL "
fi
2017-08-17 18:53:43 +00:00
2018-06-01 23:50:52 +00:00
# If the pihole manpage exists, then delete and rebuild man-db
if [ [ -f /usr/local/share/man/man8/pihole.8 ] ] ; then
2018-06-03 12:15:26 +00:00
${ SUDO } rm -f /usr/local/share/man/man8/pihole.8 /usr/local/share/man/man8/pihole-FTL.8 /usr/local/share/man/man5/pihole-FTL.conf.5
2018-06-01 23:50:52 +00:00
${ SUDO } mandb -q & >/dev/null
echo -e " ${ TICK } Removed pihole man page "
fi
2018-05-31 03:14:18 +00:00
# If the pihole user exists, then remove
if id "pihole" & > /dev/null; then
2018-05-31 03:24:09 +00:00
if ${ SUDO } userdel -r pihole 2> /dev/null; then
2018-05-31 03:14:18 +00:00
echo -e " ${ TICK } Removed 'pihole' user "
else
echo -e " ${ CROSS } Unable to remove 'pihole' user "
fi
2017-06-21 11:49:05 +00:00
fi
2020-04-03 18:07:44 +00:00
# If the pihole group exists, then remove
if getent group "pihole" & > /dev/null; then
if ${ SUDO } groupdel pihole 2> /dev/null; then
echo -e " ${ TICK } Removed 'pihole' group "
else
echo -e " ${ CROSS } Unable to remove 'pihole' group "
fi
fi
2016-04-21 01:43:01 +00:00
2018-05-31 03:24:09 +00:00
echo -e " \\n We're sorry to see you go, but thanks for checking out Pi-hole!
2020-05-13 10:49:00 +00:00
If you need help, reach out to us on GitHub, Discourse, Reddit or Twitter
2018-05-31 03:14:18 +00:00
Reinstall at any time: ${ COL_WHITE } curl -sSL https://install.pi-hole.net | bash${ COL_NC }
2017-06-21 11:49:05 +00:00
2024-09-29 20:21:44 +00:00
${ COL_LIGHT_RED } Please reset the DNS on your router/clients to restore internet connectivity${ COL_NC }
${ INFO } Pi-hole's meta package has been removed, use the ' autoremove' function from your package manager to remove unused dependencies${ COL_NC }
2018-05-31 03:14:18 +00:00
${ COL_LIGHT_GREEN } Uninstallation Complete! ${ COL_NC } "
2016-03-26 20:18:53 +00:00
}
2016-01-16 19:56:08 +00:00
2016-03-26 20:18:53 +00:00
######### SCRIPT ###########
2024-09-29 20:21:44 +00:00
removeMetaPackage
removePiholeFiles