Modularized uninstall for cleanliness and robust usability.

This commit is contained in:
Nate 2016-03-26 15:18:53 -05:00
parent f20a510ef4
commit e3ff644abd

104
automated install/uninstall.sh Normal file → Executable file
View file

@ -25,54 +25,66 @@ else
fi fi
fi fi
function removeAndPurge {
# Purge dependencies
echo "Purging dependencies!"
$SUDO apt-get -y remove --purge dnsutils bc toilet
$SUDO apt-get -y remove --purge dnsmasq
$SUDO apt-get -y remove --purge lighttpd php5-common php5-cgi php5
# Remove dependency config files
echo "Removing dnsmasq config files..."
$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig &> /dev/null
}
function removeNoPurge {
# Only web directories/files that are created by pihole should be removed.
echo "Removing the Pi-hole Web server files..."
$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
# If the web directory is empty after removing these files, then the parent html folder can be removed.
if [[ ! "$(ls -A /var/www/html)" ]]; then
$SUDO rm -rf /var/www/html &> /dev/null
fi
# 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
echo "Initial Pi-hole cron detected. Restoring the default system cron..."
$SUDO mv /etc/crontab /etc/crontab.pihole
$SUDO mv /etc/crontab.orig /etc/crontab
$SUDO service cron restart
fi
# Attempt to preserve backwards compatibility with older versions
if [[ -f /etc/cron.d/pihole ]];then
echo "Removing cron.d/pihole..."
$SUDO rm /etc/cron.d/pihole &> /dev/null
fi
echo "Removing config files and scripts..."
$SUDO rm -rf /etc/lighttpd/ &> /dev/null
$SUDO rm /var/log/pihole.log &> /dev/null
$SUDO rm /usr/local/bin/gravity.sh &> /dev/null
$SUDO rm /usr/local/bin/chronometer.sh &> /dev/null
$SUDO rm /usr/local/bin/whitelist.sh &> /dev/null
$SUDO rm /usr/local/bin/piholeLogFlush.sh &> /dev/null
$SUDO rm -rf /etc/pihole/ &> /dev/null
}
######### SCRIPT ########### ######### SCRIPT ###########
echo "WARNING: This is destructive if run on any non-Debian based OS" echo "WARNING: This is destructive if run on any non-Debian based OS"
echo "(SAFE TO RUN ON RASPBIAN)" echo "(SAFE TO RUN ON RASPBIAN)"
read -p "Do you wish to purge PiHole's dependencies from your OS?" -n 1 -r while true; do
echo read -p "Do you wish to purge PiHole's dependencies from your OS?" yn
if [[ $REPLY =~ ^{Yy]$ ]]; then case $yn in
$SUDO apt-get -y remove --purge dnsutils bc toilet [Yy]* ) removeAndPurge; break;;
$SUDO apt-get -y remove --purge dnsmasq
$SUDO apt-get -y remove --purge lighttpd php5-common php5-cgi php5
echo "Removing dnsmasq config files..." [Nn]* ) removeNoPurge; break;;
$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig esac
fi done
# Only web directories/files that are created by pihole should be removed.
echo "Removing the Pi-hole Web server files..."
$SUDO rm -rf /var/www/html/admin
$SUDO rm -rf /var/www/html/pihole
$SUDO rm /var/www/html/index.lighttpd.orig
# If the web directory is empty after removing these files, then the parent html folder can be removed.
if [[ ! "$(ls -A /var/www/html)" ]]; then
$SUDO rm -rf /var/www/html
fi
# 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
echo "Initial Pi-hole cron detected. Restoring the default system cron..."
$SUDO mv /etc/crontab /etc/crontab.pihole
$SUDO mv /etc/crontab.orig /etc/crontab
$SUDO service cron restart
fi
# Attempt to preserve backwards compatibility with older versions
if [[ -f /etc/cron.d/pihole ]];then
echo "Removing cron.d/pihole..."
$SUDO rm /etc/cron.d/pihole
fi
echo "Removing config files and scripts..."
$SUDO rm -rf /etc/lighttpd/
$SUDO rm /var/log/pihole.log
$SUDO rm /usr/local/bin/gravity.sh
$SUDO rm /usr/local/bin/chronometer.sh
$SUDO rm /usr/local/bin/whitelist.sh
$SUDO rm /usr/local/bin/piholeLogFlush.sh
$SUDO rm -rf /etc/pihole/