Loop through dependencies as with install, offer user a choice to keep or remove them.

This commit is contained in:
Promofaux 2016-02-11 16:26:57 +00:00
parent 6ff2b04dfb
commit 5eff32f578

View file

@ -10,11 +10,29 @@
# the Free Software Foundation, either version 2 of the License, or # the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
spinner() {
local pid=$1
spin='-\|/'
i=0
while $SUDO kill -0 $pid 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "\b${spin:$i:1}"
sleep .1
done
printf "\b"
}
echo ":::"
echo "::: Sorry to see you go :(..."
echo ":::"
# Must be root to uninstall # Must be root to uninstall
if [[ $EUID -eq 0 ]];then if [[ $EUID -eq 0 ]];then
echo "You are root." echo "You are root."
else else
echo "sudo will be used for the install." echo "::: sudo will be used for the uninstall."
# Check if it is actually installed # Check if it is actually installed
# If it isn't, exit because the unnstall cannot complete # If it isn't, exit because the unnstall cannot complete
if [[ $(dpkg-query -s sudo) ]];then if [[ $(dpkg-query -s sudo) ]];then
@ -27,9 +45,25 @@ fi
######### SCRIPT ########### ######### SCRIPT ###########
$SUDO apt-get -y remove --purge dnsutils bc toilet #Check with user which dependencies to remove. They may be using some of them elsewhere
$SUDO apt-get -y remove --purge dnsmasq echo ":::"
$SUDO apt-get -y remove --purge lighttpd php5-common php5-cgi php5 echo "::: Removing dependencies..."
dependencies=( dnsutils bc toilet figlet dnsmasq lighttpd php5-common php5-cgi php5 git curl unzip wget )
for i in "${dependencies[@]}"
do
:
if [ $(dpkg-query -W -f='${Status}' $i 2>/dev/null | grep -c "ok installed") -eq 1 ]; then
while true; do
read -p "::: Do you wish to remove this dependency from your system? [$i] (y/n): " yn
case $yn in
[Yy]* ) echo -n "::: removing $i....";$SUDO apt-get -y -qq remove $i > /dev/null & spinner $!; echo " done."; break;;
[Nn]* ) echo "::: Keeping $i installed"; break;;
* ) echo "::: Please answer yes or no.";;
esac
done
echo ":::"
fi
done
# Only web directories/files that are created by pihole should be removed. # Only web directories/files that are created by pihole should be removed.
echo -n "::: Removing the Pi-hole Web server files..." echo -n "::: Removing the Pi-hole Web server files..."
@ -44,12 +78,13 @@ $SUDO rm -rf /etc/.pihole
echo " done." echo " done."
# If the web directory is empty after removing these files, then the parent html folder can be removed. # 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 #if [[ ! "$(ls -A /var/www/html)" ]]; then
$SUDO rm -rf /var/www/html # $SUDO rm -rf /var/www/html
fi #fi
echo "::: Removing dnsmasq config files..." echo -n "::: Removing pi-hole dnsmasq config file..."
$SUDO rm /etc/dnsmasq.d/01-pihole.conf $SUDO rm /etc/dnsmasq.d/01-pihole.conf
echo " done."
# Attempt to preserve backwards compatibility with older versions # Attempt to preserve backwards compatibility with older versions
# to guarantee no additional changes were made to /etc/crontab after # to guarantee no additional changes were made to /etc/crontab after
@ -64,16 +99,20 @@ fi
# Attempt to preserve backwards compatibility with older versions # Attempt to preserve backwards compatibility with older versions
if [[ -f /etc/cron.d/pihole ]];then if [[ -f /etc/cron.d/pihole ]];then
echo "Removing cron.d/pihole..." echo -n "::: Removing pi-hole cron jobs..."
$SUDO rm /etc/cron.d/pihole $SUDO rm /etc/cron.d/pihole
echo " done."
fi fi
echo "Removing config files and scripts..." echo -n "::: Removing config files and scripts..."
$SUDO rm /etc/dnsmasq.conf $SUDO rm -rf /etc/.pihole/
$SUDO rm -rf /etc/lighttpd/ #$SUDO rm -rf /etc/lighttpd/
$SUDO rm /var/log/pihole.log $SUDO rm /var/log/pihole.log
$SUDO rm /usr/local/bin/gravity.sh $SUDO rm /usr/local/bin/gravity.sh
$SUDO rm /usr/local/bin/chronometer.sh $SUDO rm /usr/local/bin/chronometer.sh
$SUDO rm /usr/local/bin/whitelist.sh $SUDO rm /usr/local/bin/whitelist.sh
$SUDO rm /usr/local/bin/blacklist.sh
$SUDO rm /usr/local/bin/piholeLogFlush.sh $SUDO rm /usr/local/bin/piholeLogFlush.sh
$SUDO rm -rf /etc/pihole/ $SUDO rm -rf /etc/pihole/
$SUDO rm /usr/local/bin/uninstall.sh
echo " done."