From 0f482396ee63f1f653ea707ec95925a84520dc0b Mon Sep 17 00:00:00 2001 From: James George Date: Sun, 23 Feb 2025 19:52:15 +0800 Subject: [PATCH] Update update.sh, updatecheck.sh and uninstall.sh to honour pihole.toml settings for webserver.paths.webroot and webserver.paths.webhome When uninstalling, remove web interface parent directory empty check and possible removal. Signed-off-by: James George --- advanced/Scripts/update.sh | 9 +++++++-- advanced/Scripts/updatecheck.sh | 8 +++++--- automated install/uninstall.sh | 15 +++++---------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 9ea63b4c..6fb11a2b 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -12,7 +12,6 @@ # Variables readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/web.git" -readonly ADMIN_INTERFACE_DIR="/var/www/html/admin" readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" readonly PI_HOLE_FILES_DIR="/etc/.pihole" @@ -26,12 +25,18 @@ CHECK_ONLY=false source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # shellcheck disable=SC1091 source "/opt/pihole/COL_TABLE" +# shellcheck disable=SC1091 +source "${PI_HOLE_INSTALL_DIR}/utils.sh" # is_repo() sourced from basic-install.sh # make_repo() sourced from basic-install.sh # update_repo() source from basic-install.sh # getGitFiles() sourced from basic-install.sh # FTLcheckUpdate() sourced from basic-install.sh +# getFTLConfigValue() sourced from utils.sh + +# Honour configured paths for the web application. +readonly ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome") GitCheckUpdateAvail() { local directory @@ -209,7 +214,7 @@ main() { echo "" echo -e " ${INFO} Pi-hole Web Admin files out of date, updating local repo." getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}" - echo -e " ${INFO} If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'" + echo -e " ${INFO} If you had made any changes in '${ADMIN_INTERFACE_DIR}', they have been stashed using 'git stash'" fi if [[ "${FTL_update}" == true ]]; then diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index b325ee9c..b64917a2 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -42,6 +42,8 @@ function get_remote_hash() { # shellcheck disable=SC1091 . /opt/pihole/utils.sh +readonly ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome") + # Remove the below three legacy files if they exist rm -f "/etc/pihole/GitHubVersions" rm -f "/etc/pihole/localbranches" @@ -85,13 +87,13 @@ addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}" # get Web versions -WEB_VERSION="$(get_local_version /var/www/html/admin)" +WEB_VERSION="$(get_local_version "${ADMIN_INTERFACE_DIR}")" addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}" -WEB_BRANCH="$(get_local_branch /var/www/html/admin)" +WEB_BRANCH="$(get_local_branch "${ADMIN_INTERFACE_DIR}")" addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" -WEB_HASH="$(get_local_hash /var/www/html/admin)" +WEB_HASH="$(get_local_hash "${ADMIN_INTERFACE_DIR}")" addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}" GITHUB_WEB_VERSION="$(get_remote_version web "${WEB_BRANCH}")" diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 39c13037..332adbf6 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -9,6 +9,9 @@ # Please see LICENSE file for your rights under this license. source "/opt/pihole/COL_TABLE" +source "/opt/pihole/utils.sh" + +readonly ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome") while true; do read -rp " ${QST} Are you sure you would like to remove ${COL_WHITE}Pi-hole${COL_NC}? [y/N] " answer @@ -53,17 +56,9 @@ removeMetaPackage() { } removePiholeFiles() { - # Only web directories/files that are created by Pi-hole should be removed + # Remove the web interface of Pi-hole echo -ne " ${INFO} Removing Web Interface..." - ${SUDO} rm -rf /var/www/html/admin &> /dev/null - - - # If the web directory is empty after removing these files, then the parent html directory can be removed. - if [ -d "/var/www/html" ]; then - if [[ ! "$(ls -A /var/www/html)" ]]; then - ${SUDO} rm -rf /var/www/html &> /dev/null - fi - fi + ${SUDO} rm -rf "${ADMIN_INTERFACE_DIR}" &> /dev/null echo -e "${OVER} ${TICK} Removed Web Interface" # Attempt to preserve backwards compatibility with older versions