From bee109c7849b1ab8cd568dc2fb428d37e163e7a7 Mon Sep 17 00:00:00 2001 From: jacobsalmela Date: Sat, 16 Jan 2016 13:56:08 -0600 Subject: [PATCH] better uninstall More from JoshKastang. This closes #153 as it is the last step from his ideas. --- automated install/uninstall.sh | 67 ++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 563d8d07..a518fa0f 100644 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -8,20 +8,57 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +# Must be root to uninstall +if [[ $EUID -eq 0 ]];then + echo "You are root." +else + echo "sudo will be used for the install." + export SUDO="sudo" +fi + ######### SCRIPT ########### -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 -sudo rm -rf /var/www/html -sudo rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig -sudo rm /etc/crontab -sudo mv /etc/crontab.orig /etc/crontab -sudo rm /etc/dnsmasq.conf -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/ +$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 + +# 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 + +echo "Removing dnsmasq config files..." +$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig + +# 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 /etc/dnsmasq.conf +$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/