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
|
|
|
|
# (c) 2015, 2016 by Jacob Salmela
|
|
|
|
# Network-wide ad blocking via your Raspberry Pi
|
|
|
|
# http://pi-hole.net
|
|
|
|
# Completely uninstalls Pi-hole
|
2015-12-06 14:31:49 +00:00
|
|
|
#
|
|
|
|
# Pi-hole is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
2016-01-16 19:56:08 +00:00
|
|
|
# Must be root to uninstall
|
|
|
|
if [[ $EUID -eq 0 ]];then
|
2016-03-27 17:31:05 +00:00
|
|
|
echo "::: You are root."
|
2016-01-16 19:56:08 +00:00
|
|
|
else
|
2016-03-27 17:31:05 +00:00
|
|
|
echo "::: Sudo will be used for the uninstall."
|
2016-01-16 20:10:03 +00:00
|
|
|
# Check if it is actually installed
|
|
|
|
# If it isn't, exit because the unnstall cannot complete
|
|
|
|
if [[ $(dpkg-query -s sudo) ]];then
|
|
|
|
export SUDO="sudo"
|
|
|
|
else
|
2016-03-27 17:31:05 +00:00
|
|
|
echo "::: Please install sudo or run this as root."
|
2016-01-16 20:10:03 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-01-16 19:56:08 +00:00
|
|
|
fi
|
|
|
|
|
2016-03-27 17:31:05 +00:00
|
|
|
spinner()
|
|
|
|
{
|
|
|
|
local pid=$1
|
|
|
|
local delay=0.50
|
2016-04-03 20:45:00 +00:00
|
|
|
local spinstr='/-\|'
|
2016-03-27 17:31:05 +00:00
|
|
|
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
|
|
|
local temp=${spinstr#?}
|
|
|
|
printf " [%c] " "$spinstr"
|
|
|
|
local spinstr=$temp${spinstr%"$temp"}
|
|
|
|
sleep $delay
|
|
|
|
printf "\b\b\b\b\b\b"
|
|
|
|
done
|
|
|
|
printf " \b\b\b\b"
|
|
|
|
}
|
|
|
|
|
2016-03-26 20:18:53 +00:00
|
|
|
function removeAndPurge {
|
|
|
|
# Purge dependencies
|
2016-03-27 17:31:05 +00:00
|
|
|
echo ":::"
|
2016-03-28 15:24:13 +00:00
|
|
|
# Nate 3/28/2016 - Removed `php5-cgi` and `php5` as they are removed with php5-common
|
|
|
|
dependencies=( dnsutils bc toilet figlet dnsmasq lighttpd php5-common git curl unzip wget )
|
2016-03-27 17:31:05 +00:00
|
|
|
for i in "${dependencies[@]}"; do
|
2016-03-28 15:24:13 +00:00
|
|
|
if [ "$(dpkg-query -W --showformat='${Status}\n' "$i" 2> /dev/null | grep -c "ok installed")" -eq 1 ]; then
|
2016-03-27 17:31:05 +00:00
|
|
|
while true; do
|
2016-03-28 15:24:13 +00:00
|
|
|
read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn
|
2016-03-27 17:31:05 +00:00
|
|
|
case $yn in
|
2016-03-28 21:20:23 +00:00
|
|
|
[Yy]* ) printf ":::\tRemoving %s..." "$i"; $SUDO apt-get -y remove --purge "$i" &> /dev/null & spinner $!; printf "done!\n"; break;;
|
2016-05-06 01:17:28 +00:00
|
|
|
[Nn]* ) printf ":::\tSkipping %s\n" "$i"; break;;
|
2016-04-04 05:59:24 +00:00
|
|
|
* ) printf "::: You must answer yes or no!\n";;
|
2016-03-27 17:31:05 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
else
|
2016-03-28 15:24:13 +00:00
|
|
|
printf ":::\tPackage %s not installed... Not removing.\n" "$i"
|
2016-03-27 17:31:05 +00:00
|
|
|
fi
|
|
|
|
done
|
2016-03-26 20:18:53 +00:00
|
|
|
|
|
|
|
# Remove dependency config files
|
2016-03-27 17:31:05 +00:00
|
|
|
echo "::: Removing dnsmasq config files..."
|
2016-03-26 21:50:05 +00:00
|
|
|
$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null
|
|
|
|
|
2016-03-27 06:53:48 +00:00
|
|
|
# Take care of any additional package cleaning
|
2016-03-28 21:20:23 +00:00
|
|
|
printf "::: Auto removing remaining dependencies..."
|
|
|
|
$SUDO apt-get -y autoremove &> /dev/null & spinner $!; printf "done!\n";
|
|
|
|
printf "::: Auto cleaning remaining dependencies..."
|
|
|
|
$SUDO apt-get -y autoclean &> /dev/null & spinner $!; printf "done!\n";
|
2016-03-27 06:53:48 +00:00
|
|
|
|
2016-03-26 21:50:05 +00:00
|
|
|
# Call removeNoPurge to remove PiHole specific files
|
|
|
|
removeNoPurge
|
2016-03-26 20:18:53 +00:00
|
|
|
}
|
2016-01-16 19:56:08 +00:00
|
|
|
|
2016-03-26 20:18:53 +00:00
|
|
|
function removeNoPurge {
|
2016-03-27 17:31:05 +00:00
|
|
|
echo ":::"
|
2016-03-26 20:18:53 +00:00
|
|
|
# Only web directories/files that are created by pihole should be removed.
|
2016-03-27 17:31:05 +00:00
|
|
|
echo "::: Removing the Pi-hole Web server files..."
|
2016-03-26 20:18:53 +00:00
|
|
|
$SUDO rm -rf /var/www/html/admin &> /dev/null
|
|
|
|
$SUDO rm -rf /var/www/html/pihole &> /dev/null
|
|
|
|
$SUDO rm /var/www/html/index.lighttpd.orig &> /dev/null
|
2016-01-16 19:56:08 +00:00
|
|
|
|
2016-03-26 20:18:53 +00:00
|
|
|
# If the web directory is empty after removing these files, then the parent html folder can be removed.
|
2016-03-26 21:50:05 +00:00
|
|
|
if [ -d "/var/www/html" ]; then
|
|
|
|
if [[ ! "$(ls -A /var/www/html)" ]]; then
|
|
|
|
$SUDO rm -rf /var/www/html &> /dev/null
|
|
|
|
fi
|
2016-03-26 20:18:53 +00:00
|
|
|
fi
|
2016-01-16 19:56:08 +00:00
|
|
|
|
2016-03-26 20:18:53 +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
|
2016-03-27 17:31:05 +00:00
|
|
|
echo "::: Initial Pi-hole cron detected. Restoring the default system cron..."
|
2016-03-26 20:18:53 +00:00
|
|
|
$SUDO mv /etc/crontab /etc/crontab.pihole
|
|
|
|
$SUDO mv /etc/crontab.orig /etc/crontab
|
|
|
|
$SUDO service cron restart
|
|
|
|
fi
|
2016-01-16 19:56:08 +00:00
|
|
|
|
2016-03-26 20:18:53 +00:00
|
|
|
# Attempt to preserve backwards compatibility with older versions
|
|
|
|
if [[ -f /etc/cron.d/pihole ]];then
|
2016-03-27 17:31:05 +00:00
|
|
|
echo "::: Removing cron.d/pihole..."
|
2016-03-26 20:18:53 +00:00
|
|
|
$SUDO rm /etc/cron.d/pihole &> /dev/null
|
|
|
|
fi
|
|
|
|
|
2016-03-27 17:31:05 +00:00
|
|
|
echo "::: Removing config files and scripts..."
|
2016-03-28 22:08:19 +00:00
|
|
|
if [ ! "$(dpkg-query -W --showformat='${Status}\n' lighttpd 2> /dev/null | grep -c "ok installed")" -eq 1 ]; then
|
|
|
|
$SUDO rm -rf /etc/lighttpd/ &> /dev/null
|
|
|
|
else
|
|
|
|
if [ -f /etc/lighttpd/lighttpd.conf.orig ]; then
|
|
|
|
$SUDO mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf
|
|
|
|
fi
|
|
|
|
fi
|
2016-04-01 01:25:54 +00:00
|
|
|
|
2016-03-28 15:24:13 +00:00
|
|
|
$SUDO rm /etc/dnsmasq.d/adList.conf &> /dev/null
|
2016-03-31 01:23:24 +00:00
|
|
|
$SUDO rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null
|
2016-03-26 21:50:05 +00:00
|
|
|
$SUDO rm -rf /var/log/*pihole* &> /dev/null
|
2016-03-26 20:18:53 +00:00
|
|
|
$SUDO rm -rf /etc/pihole/ &> /dev/null
|
2016-03-26 21:50:05 +00:00
|
|
|
$SUDO rm -rf /etc/.pihole/ &> /dev/null
|
2016-03-28 15:24:13 +00:00
|
|
|
$SUDO rm -rf /opt/pihole/ &> /dev/null
|
2016-04-02 22:58:10 +00:00
|
|
|
$SUDO rm /usr/local/bin/pihole &> /dev/null
|
2016-04-02 23:52:03 +00:00
|
|
|
$SUDO rm /etc/bash_completion.d/pihole
|
2016-03-27 17:31:05 +00:00
|
|
|
|
|
|
|
echo ":::"
|
|
|
|
printf "::: Finished removing PiHole from your system. Sorry to see you go!\n"
|
|
|
|
printf "::: Reach out to us at https://github.com/pi-hole/pi-hole/issues if you need help\n"
|
2016-04-04 05:59:24 +00:00
|
|
|
printf "::: Reinstall by simpling running\n:::\n:::\tcurl -L https://install.pi-hole.net | bash\n:::\n::: at any time!\n:::\n"
|
2016-03-28 21:20:23 +00:00
|
|
|
printf "::: PLEASE RESET YOUR DNS ON YOUR ROUTER/CLIENTS TO RESTORE INTERNET CONNECTIVITY!\n"
|
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 ###########
|
2016-03-27 17:31:05 +00:00
|
|
|
echo "::: Preparing to remove packages, be sure that each may be safely removed depending on your operating system."
|
|
|
|
echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)"
|
2016-03-26 20:18:53 +00:00
|
|
|
while true; do
|
2016-03-28 21:20:23 +00:00
|
|
|
read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package) [y/n]: " yn
|
2016-03-26 20:18:53 +00:00
|
|
|
case $yn in
|
|
|
|
[Yy]* ) removeAndPurge; break;;
|
|
|
|
|
|
|
|
[Nn]* ) removeNoPurge; break;;
|
|
|
|
esac
|
|
|
|
done
|
2016-03-27 06:53:48 +00:00
|
|
|
|
2016-03-27 17:31:05 +00:00
|
|
|
|