From 95e3a5944d355f8eea6cba5cede4c60885bcf579 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 17 Aug 2017 19:53:43 +0100 Subject: [PATCH 1/8] Initial overhaul of uninstall script sourcing `distro_check()` from `basic-install.sh` Totally untested as yet... Signed-off-by: Adam Warner --- automated install/uninstall.sh | 38 ++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 336bb953..f2c42f24 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -36,6 +36,24 @@ else fi fi +readonly PI_HOLE_FILES_DIR="/etc/.pihole" +source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" +# setupVars set in basic-install.sh +source "${setupVars}" + +# distro_check() sourced from basic-install.sh +distro_check + +# Install packages used by the Pi-hole +if [[ "${INSTALL_WEB}" == true ]]; then + # Install the Web dependencies + DEPS=("${PIHOLE_DEPS[@]}" "${PIHOLE_WEB_DEPS[@]}") +# Otherwise, +else + # just install the Core dependencies + DEPS=("${PIHOLE_DEPS[@]}") +fi + # Compatability if [ -x "$(command -v rpm)" ]; then # Fedora Family @@ -45,7 +63,6 @@ if [ -x "$(command -v rpm)" ]; then PKG_MANAGER="yum" fi PKG_REMOVE="${PKG_MANAGER} remove -y" - PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common git curl unzip wget findutils ) package_check() { rpm -qa | grep ^$1- > /dev/null } @@ -56,7 +73,6 @@ elif [ -x "$(command -v apt-get)" ]; then # Debian Family PKG_MANAGER="apt-get" PKG_REMOVE="${PKG_MANAGER} -y remove --purge" - PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd php5-common git curl unzip wget ) package_check() { dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" } @@ -72,7 +88,7 @@ fi removeAndPurge() { # Purge dependencies echo "" - for i in "${PIHOLE_DEPS[@]}"; do + for i in "${DEPS[@]}"; do package_check ${i} > /dev/null if [[ "$?" -eq 0 ]]; then while true; do @@ -94,12 +110,12 @@ removeAndPurge() { # Remove dnsmasq config files ${SUDO} rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null echo -e " ${TICK} Removing dnsmasq config files" - + # Take care of any additional package cleaning echo -ne " ${INFO} Removing & cleaning remaining dependencies..." package_cleanup &> /dev/null echo -e "${OVER} ${TICK} Removed & cleaned up remaining dependencies" - + # Call removeNoPurge to remove Pi-hole specific files removeNoPurge } @@ -145,7 +161,7 @@ removeNoPurge() { ${SUDO} mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf fi fi - + ${SUDO} rm /etc/dnsmasq.d/adList.conf &> /dev/null ${SUDO} rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null ${SUDO} rm -rf /var/log/*pihole* &> /dev/null @@ -156,23 +172,23 @@ removeNoPurge() { ${SUDO} rm /etc/bash_completion.d/pihole &> /dev/null ${SUDO} rm /etc/sudoers.d/pihole &> /dev/null echo -e " ${TICK} Removed config files" - + # 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 - + ${SUDO} rm /etc/init.d/pihole-FTL ${SUDO} rm /usr/bin/pihole-FTL - + echo -e "${OVER} ${TICK} Removed pihole-FTL" fi - + # If the pihole user exists, then remove if id "pihole" &> /dev/null; then ${SUDO} userdel -r pihole 2> /dev/null From 3c250944952cf9ab622c3f015af300ce640ce0e9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 17 Aug 2017 19:56:36 +0100 Subject: [PATCH 2/8] No need to declare `PKG_MANAGER`, as it's already declared in basic-install Signed-off-by: Adam Warner --- automated install/uninstall.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index f2c42f24..aee0869a 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -57,11 +57,6 @@ fi # Compatability if [ -x "$(command -v rpm)" ]; then # Fedora Family - if [ -x "$(command -v dnf)" ]; then - PKG_MANAGER="dnf" - else - PKG_MANAGER="yum" - fi PKG_REMOVE="${PKG_MANAGER} remove -y" package_check() { rpm -qa | grep ^$1- > /dev/null @@ -71,7 +66,6 @@ if [ -x "$(command -v rpm)" ]; then } elif [ -x "$(command -v apt-get)" ]; then # Debian Family - PKG_MANAGER="apt-get" PKG_REMOVE="${PKG_MANAGER} -y remove --purge" package_check() { dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" From 07e5e8e67aef0cc6678aab2d59fc080102b4378c Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 17 Aug 2017 20:03:19 +0100 Subject: [PATCH 3/8] need to include `PH_TEST="true"` so that the install script isn't run when sourcing it.. doh Signed-off-by: Adam Warner --- automated install/uninstall.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index aee0869a..d1dda225 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -37,6 +37,7 @@ else fi readonly PI_HOLE_FILES_DIR="/etc/.pihole" +PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # setupVars set in basic-install.sh source "${setupVars}" From 54f4f6d2d76fce90dbc77de4f8f4cffb61af036e Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 17 Aug 2017 20:17:49 +0100 Subject: [PATCH 4/8] Add "${INSTALLER_DEPS[@]}" to package array add `-f` to rm commands so that `set -e` is not kicked Signed-off-by: Adam Warner --- automated install/uninstall.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index d1dda225..ffc14c9e 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -48,11 +48,11 @@ distro_check # Install packages used by the Pi-hole if [[ "${INSTALL_WEB}" == true ]]; then # Install the Web dependencies - DEPS=("${PIHOLE_DEPS[@]}" "${PIHOLE_WEB_DEPS[@]}") + DEPS=("${INSTALLER_DEPS[@]}" "${PIHOLE_DEPS[@]}" "${PIHOLE_WEB_DEPS[@]}") # Otherwise, else # just install the Core dependencies - DEPS=("${PIHOLE_DEPS[@]}") + DEPS=("${INSTALLER_DEPS[@]}" "${PIHOLE_DEPS[@]}") fi # Compatability @@ -103,7 +103,7 @@ removeAndPurge() { done # Remove dnsmasq config files - ${SUDO} rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null + ${SUDO} rm -f /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null echo -e " ${TICK} Removing dnsmasq config files" # Take care of any additional package cleaning @@ -120,7 +120,7 @@ removeNoPurge() { echo -ne " ${INFO} Removing Web Interface..." ${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 + ${SUDO} rm -f /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 [ -d "/var/www/html" ]; then @@ -143,7 +143,7 @@ removeNoPurge() { # Attempt to preserve backwards compatibility with older versions if [[ -f /etc/cron.d/pihole ]];then - ${SUDO} rm /etc/cron.d/pihole &> /dev/null + ${SUDO} rm -f /etc/cron.d/pihole &> /dev/null echo -e " ${TICK} Removed /etc/cron.d/pihole" fi @@ -157,15 +157,15 @@ removeNoPurge() { fi fi - ${SUDO} rm /etc/dnsmasq.d/adList.conf &> /dev/null - ${SUDO} rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null + ${SUDO} rm -f /etc/dnsmasq.d/adList.conf &> /dev/null + ${SUDO} rm -f /etc/dnsmasq.d/01-pihole.conf &> /dev/null ${SUDO} rm -rf /var/log/*pihole* &> /dev/null ${SUDO} rm -rf /etc/pihole/ &> /dev/null ${SUDO} rm -rf /etc/.pihole/ &> /dev/null ${SUDO} rm -rf /opt/pihole/ &> /dev/null - ${SUDO} rm /usr/local/bin/pihole &> /dev/null - ${SUDO} rm /etc/bash_completion.d/pihole &> /dev/null - ${SUDO} rm /etc/sudoers.d/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" # Remove FTL @@ -178,8 +178,8 @@ removeNoPurge() { service pihole-FTL stop fi - ${SUDO} rm /etc/init.d/pihole-FTL - ${SUDO} rm /usr/bin/pihole-FTL + ${SUDO} rm -f /etc/init.d/pihole-FTL + ${SUDO} rm -f /usr/bin/pihole-FTL echo -e "${OVER} ${TICK} Removed pihole-FTL" fi From 1b3428626491e372aa2d1e2b4a04560efbb09741 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 17 Aug 2017 20:33:53 +0100 Subject: [PATCH 5/8] verbiage Signed-off-by: Adam Warner --- automated install/uninstall.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index ffc14c9e..88eca716 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -209,7 +209,13 @@ else echo -e " ${INFO} Be sure to confirm if any dependencies should not be removed" fi while true; do - read -rp " ${QST} Do you wish to go through each dependency for removal? [Y/n] " yn + echo -e "${COL_YELLOW} ${INFO} The following dependencies may have been added to the system by Pi-hole install:" + echo -n " " + for i in "${DEPS[@]}"; do + echo -n "${i} " + done + echo "${COL_NC}" + read -rp " ${QST} Do you wish to go through each dependency for removal? (Choosing No will leave all dependencies installed)[Y/n] " yn case ${yn} in [Yy]* ) removeAndPurge; break;; [Nn]* ) removeNoPurge; break;; From e938132c53af84575c5efa8cf2351a48274126c1 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 17 Aug 2017 21:02:10 +0100 Subject: [PATCH 6/8] accidentally a space Signed-off-by: Adam Warner --- automated install/uninstall.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 88eca716..47a3aa5c 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -214,8 +214,8 @@ while true; do for i in "${DEPS[@]}"; do echo -n "${i} " done - echo "${COL_NC}" - read -rp " ${QST} Do you wish to go through each dependency for removal? (Choosing No will leave all dependencies installed)[Y/n] " yn + echo "${COL_NC}"git pu + read -rp " ${QST} Do you wish to go through each dependency for removal? (Choosing No will leave all dependencies installed) [Y/n] " yn case ${yn} in [Yy]* ) removeAndPurge; break;; [Nn]* ) removeNoPurge; break;; From 939c99cdbf57252d0bee07c3d453ccfb835cef25 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 23 Aug 2017 11:48:11 +0100 Subject: [PATCH 7/8] accidentally an entire group of letters. --- automated install/uninstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 47a3aa5c..cd4670b8 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -214,7 +214,7 @@ while true; do for i in "${DEPS[@]}"; do echo -n "${i} " done - echo "${COL_NC}"git pu + echo "${COL_NC}" read -rp " ${QST} Do you wish to go through each dependency for removal? (Choosing No will leave all dependencies installed) [Y/n] " yn case ${yn} in [Yy]* ) removeAndPurge; break;; From 909bc92c01646271cbb634adcaf5426784347b34 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 21 Sep 2017 00:22:47 +1000 Subject: [PATCH 8/8] Tweak wording to fit on 80 character screen * Also move colour after $INFO --- automated install/uninstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index cfc60bee..2f4f4f9f 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -208,7 +208,7 @@ else echo -e " ${INFO} Be sure to confirm if any dependencies should not be removed" fi while true; do - echo -e "${COL_YELLOW} ${INFO} The following dependencies may have been added to the system by Pi-hole install:" + echo -e " ${INFO} ${COL_YELLOW}The following dependencies may have been added by the Pi-hole install:" echo -n " " for i in "${DEPS[@]}"; do echo -n "${i} "