From fd5b3be03f91adeed1e7124de9d4ba4dbe1e8a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 28 Sep 2024 20:49:27 +0200 Subject: [PATCH 01/30] Create meta package on the fly ... Debian MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/update.sh | 3 +- automated install/basic-install.sh | 121 +++++++++++------------------ test/test_any_automated_install.py | 42 ++-------- test/test_any_utils.py | 2 +- 4 files changed, 56 insertions(+), 112 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 2ccad27c..9240c593 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -106,7 +106,8 @@ main() { # Install packages used by this installation script (necessary if users have removed e.g. git from their systems) package_manager_detect - install_dependent_packages "${INSTALLER_DEPS[@]}" + build_dependency_package + install_dependent_packages # This is unlikely if ! is_repo "${PI_HOLE_FILES_DIR}" ; then diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4852929c..4e112f81 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -102,6 +102,18 @@ fi r=20 c=70 +# Content of Pi-hole's meta package control file +PIHOLE_META_PACKAGE_CONTROL_DEBIAN=$( + cat < +Architecture: all +Description: Pi-hole dependency meta package +Depends: grep,dnsutils,binutils,git,iproute2,dialog,ca-certificates,cron,curl,iputils-ping,psmisc,sudo,unzip,libcap2-bin,dns-root-data,libcap2,netcat-openbsd,procps,jq,lshw,bash-completion +EOM +) + ######## Undocumented Flags. Shhh ######## # These are undocumented flags; some of which we can use when repairing an installation # The runUnattended flag is one example of this @@ -362,10 +374,6 @@ test_dpkg_lock() { # Compatibility package_manager_detect() { - # pull common packages for both distributions out into a common variable - OS_CHECK_COMMON_DEPS=(grep) - PIHOLE_COMMON_DEPS=(curl psmisc sudo unzip jq); - INSTALLER_COMMON_DEPS=(git dialog ca-certificates) # First check to see if apt-get is installed. if is_command apt-get; then @@ -375,17 +383,11 @@ package_manager_detect() { # A variable to store the command used to update the package cache UPDATE_PKG_CACHE="${PKG_MANAGER} update" # The command we will use to actually install packages - PKG_INSTALL=("${PKG_MANAGER}" -qq --no-install-recommends install) + PKG_INSTALL="${PKG_MANAGER} -qq --no-install-recommends install" # grep -c will return 1 if there are no matches. This is an acceptable condition, so we OR TRUE to prevent set -e exiting the script. PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" # Update package cache update_package_cache || exit 1 - # Packages required to perform the os_check and FTL binary detection - OS_CHECK_DEPS=(dnsutils binutils) - # Packages required to run this install script - INSTALLER_DEPS=(iproute2) - # Packages required to run Pi-hole - PIHOLE_DEPS=(cron iputils-ping libcap2-bin dns-root-data libcap2 netcat-openbsd procps lshw bash-completion) # If apt-get is not found, check for rpm. elif is_command rpm; then @@ -397,7 +399,7 @@ package_manager_detect() { fi # These variable names match the ones for apt-get. See above for an explanation of what they are for. - PKG_INSTALL=("${PKG_MANAGER}" install -y) + PKG_INSTALL="${PKG_MANAGER} install -y" # CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting. PKG_COUNT="${PKG_MANAGER} check-update | grep -E '(.i686|.x86|.noarch|.arm|.src|.riscv64)' | wc -l || true" OS_CHECK_DEPS=(bind-utils) @@ -413,6 +415,24 @@ package_manager_detect() { fi } +build_dependency_package(){ + # This function will build a package that contains all the dependencies needed for Pi-hole + mkdir -p /tmp/pihole-meta + chmod 0755 /tmp/pihole-meta + + if is_command apt-get; then + # move into the directory + pushd /tmp &>/dev/null || return 1 + mkdir -p /tmp/pihole-meta/DEBIAN + chmod 0755 /tmp/pihole-meta/DEBIAN + touch /tmp/pihole-meta/DEBIAN/control + echo "${PIHOLE_META_PACKAGE_CONTROL_DEBIAN}" > /tmp/pihole-meta/DEBIAN/control + dpkg-deb --build --root-owner-group pihole-meta + # Move back into the directory the user started in + popd &> /dev/null || return 1 + fi +} + # A function for checking if a directory is a git repository is_repo() { # Use a named, local variable instead of the vague $1, which is the first argument passed to this function @@ -1390,61 +1410,20 @@ notify_package_updates_available() { } install_dependent_packages() { + # Install meta dependency package - # Install packages passed in via argument array - # No spinner - conflicts with set -e - declare -a installArray - - # Debian based package install - debconf will download the entire package list - # so we just create an array of packages not currently installed to cut down on the - # amount of download traffic. - # NOTE: We may be able to use this installArray in the future to create a list of package that were - # installed by us, and remove only the installed packages, and not the entire list. if is_command apt-get; then - # For each package, check if it's already installed (and if so, don't add it to the installArray) - for i in "$@"; do - printf " %b Checking for %s..." "${INFO}" "${i}" - if dpkg-query -W -f='${Status}' "${i}" 2>/dev/null | grep "ok installed" &>/dev/null; then - printf "%b %b Checking for %s\\n" "${OVER}" "${TICK}" "${i}" - else - printf "%b %b Checking for %s (will be installed)\\n" "${OVER}" "${INFO}" "${i}" - installArray+=("${i}") - fi - done - # If there's anything to install, install everything in the list. - if [[ "${#installArray[@]}" -gt 0 ]]; then - test_dpkg_lock - # Running apt-get install with minimal output can cause some issues with - # requiring user input (e.g password for phpmyadmin see #218) - printf " %b Processing %s install(s) for: %s, please wait...\\n" "${INFO}" "${PKG_MANAGER}" "${installArray[*]}" - printf '%*s\n' "${c}" '' | tr " " - - "${PKG_INSTALL[@]}" "${installArray[@]}" - printf '%*s\n' "${c}" '' | tr " " - - return + if [ -f /tmp/pihole-meta.deb ]; then + eval "${PKG_INSTALL}" "/tmp/pihole-meta.deb" + rm /tmp/pihole-meta.deb + else + printf " %b Error: Unable to find dependency meta package.\\n" "${COL_LIGHT_RED}" + return 1 fi - printf "\\n" - return 0 fi # Install Fedora/CentOS packages - for i in "$@"; do - # For each package, check if it's already installed (and if so, don't add it to the installArray) - printf " %b Checking for %s..." "${INFO}" "${i}" - if "${PKG_MANAGER}" -q list installed "${i}" &>/dev/null; then - printf "%b %b Checking for %s\\n" "${OVER}" "${TICK}" "${i}" - else - printf "%b %b Checking for %s (will be installed)\\n" "${OVER}" "${INFO}" "${i}" - installArray+=("${i}") - fi - done - # If there's anything to install, install everything in the list. - if [[ "${#installArray[@]}" -gt 0 ]]; then - printf " %b Processing %s install(s) for: %s, please wait...\\n" "${INFO}" "${PKG_MANAGER}" "${installArray[*]}" - printf '%*s\n' "${c}" '' | tr " " - - "${PKG_INSTALL[@]}" "${installArray[@]}" - printf '%*s\n' "${c}" '' | tr " " - - return - fi + printf "\\n" return 0 } @@ -2269,9 +2248,12 @@ main() { # Notify user of package availability notify_package_updates_available - # Install packages necessary to perform os_check - printf " %b Checking for / installing Required dependencies for OS Check...\\n" "${INFO}" - install_dependent_packages "${OS_CHECK_COMMON_DEPS[@]}" "${OS_CHECK_DEPS[@]}" + # Build dependecy package + build_dependency_package + + # Install Pi-hole dependencies + printf " %b Installing required dependencies ...\\n" "${INFO}" + install_dependent_packages # Check that the installed OS is officially supported - display warning if not os_check @@ -2286,10 +2268,6 @@ main() { exit 1 fi - # Install packages used by this installation script - printf " %b Checking for / installing Required dependencies for this install script...\\n" "${INFO}" - install_dependent_packages "${INSTALLER_COMMON_DEPS[@]}" "${INSTALLER_DEPS[@]}" - # in case of an update if [[ -f "${PI_HOLE_V6_CONFIG}" ]]; then # if it's running unattended, @@ -2331,13 +2309,6 @@ main() { # Download or update the scripts by updating the appropriate git repos clone_or_update_repos - # Install the Core dependencies - local dep_install_list=("${PIHOLE_COMMON_DEPS[@]}" "${PIHOLE_DEPS[@]}") - - # Install packages used by the actual software - printf " %b Checking for / installing Required dependencies for Pi-hole software...\\n" "${INFO}" - install_dependent_packages "${dep_install_list[@]}" - unset dep_install_list # Create the pihole user create_pihole_user diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 0930f0af..7d9a49ad 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -12,7 +12,7 @@ from .conftest import ( run_script, ) -FTL_BRANCH = "development-v6" +FTL_BRANCH = "development" def test_supported_package_manager(host): @@ -480,8 +480,8 @@ def test_os_check_fails(host): """ source /opt/pihole/basic-install.sh package_manager_detect - install_dependent_packages ${OS_CHECK_DEPS[@]} - install_dependent_packages ${INSTALLER_DEPS[@]} + build_dependency_package + install_dependent_packages cat < /etc/os-release ID=UnsupportedOS VERSION_ID="2" @@ -504,8 +504,8 @@ def test_os_check_passes(host): """ source /opt/pihole/basic-install.sh package_manager_detect - install_dependent_packages ${OS_CHECK_DEPS[@]} - install_dependent_packages ${INSTALLER_DEPS[@]} + build_dependency_package + install_dependent_packages """ ) detectOS = host.run( @@ -518,21 +518,6 @@ def test_os_check_passes(host): assert expected_stdout in detectOS.stdout -def test_package_manager_has_installer_deps(host): - """Confirms OS is able to install the required packages for the installer""" - mock_command("dialog", {"*": ("", "0")}, host) - output = host.run( - """ - source /opt/pihole/basic-install.sh - package_manager_detect - install_dependent_packages ${INSTALLER_DEPS[@]} - """ - ) - - assert "No package" not in output.stdout - assert output.rc == 0 - - def test_package_manager_has_pihole_deps(host): """Confirms OS is able to install the required packages for Pi-hole""" mock_command("dialog", {"*": ("", "0")}, host) @@ -540,24 +525,11 @@ def test_package_manager_has_pihole_deps(host): """ source /opt/pihole/basic-install.sh package_manager_detect - install_dependent_packages ${PIHOLE_DEPS[@]} + build_dependency_package + install_dependent_packages """ ) assert "No package" not in output.stdout assert output.rc == 0 - -def test_package_manager_has_web_deps(host): - """Confirms OS is able to install the required packages for web""" - mock_command("dialog", {"*": ("", "0")}, host) - output = host.run( - """ - source /opt/pihole/basic-install.sh - package_manager_detect - install_dependent_packages ${PIHOLE_WEB_DEPS[@]} - """ - ) - - assert "No package" not in output.stdout - assert output.rc == 0 diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 59745c48..46b4acca 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -105,7 +105,7 @@ def test_setFTLConfigValue_getFTLConfigValue(host): source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) - echo "development-v6" > /etc/pihole/ftlbranch + echo "development" > /etc/pihole/ftlbranch binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" From f08c54e166c7f324349483c3bdda486486eb6bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 29 Sep 2024 19:26:19 +0200 Subject: [PATCH 02/30] Create dependency package on RPM distros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 91 +++++++++++++++++++++++++++--- test/test_any_automated_install.py | 1 - 2 files changed, 82 insertions(+), 10 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4e112f81..abfb13f3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -102,8 +102,8 @@ fi r=20 c=70 -# Content of Pi-hole's meta package control file -PIHOLE_META_PACKAGE_CONTROL_DEBIAN=$( +# Content of Pi-hole's meta package control file on APT based systems +PIHOLE_META_PACKAGE_CONTROL_APT=$( cat </dev/null || return 1 + + # Prepare directory structure and control file mkdir -p /tmp/pihole-meta/DEBIAN chmod 0755 /tmp/pihole-meta/DEBIAN touch /tmp/pihole-meta/DEBIAN/control - echo "${PIHOLE_META_PACKAGE_CONTROL_DEBIAN}" > /tmp/pihole-meta/DEBIAN/control + + # Write the control file + echo "${PIHOLE_META_PACKAGE_CONTROL_APT}" > /tmp/pihole-meta/DEBIAN/control + + # Build the package dpkg-deb --build --root-owner-group pihole-meta + # Move back into the directory the user started in popd &> /dev/null || return 1 fi + + if is_command rpm; then + # move into the tmp directory + pushd /tmp &>/dev/null || return 1 + + # Prepare directory structure and spec file + mkdir -p /tmp/pihole-meta/SPECS + touch /tmp/pihole-meta/SPECS/pihole-meta.spec + echo "${PIHOLE_META_PACKAGE_CONTROL_RPM}" > /tmp/pihole-meta/SPECS/pihole-meta.spec + + # check if we need to install the build dependencies + if ! is_command rpmbuild; then + local REMOVE_RPM_BUILD=true + eval "${PKG_INSTALL}" "rpm-build" + fi + + # Build the package + rpmbuild -bb /tmp/pihole-meta/SPECS/pihole-meta.spec + + # Move the package to the /tmp directory + mv /tmp/pihole-meta/RPMS/noarch/pihole-meta*.rpm /tmp/pihole-meta.rpm + + # Remove the build dependencies when we've installed them + if [ -n "${REMOVE_RPM_BUILD}" ]; then + local PKG_REMOVE + PKG_REMOVE="${PKG_MANAGER} remove -y" + eval "${PKG_REMOVE}" "rpm-build" + fi + + # Move back into the directory the user started in + popd &> /dev/null || return 1 + fi + + # Remove the build directory + rm -rf /tmp/pihole-meta } # A function for checking if a directory is a git repository @@ -1412,18 +1475,28 @@ notify_package_updates_available() { install_dependent_packages() { # Install meta dependency package + # Install Debian/Ubuntu packages if is_command apt-get; then if [ -f /tmp/pihole-meta.deb ]; then eval "${PKG_INSTALL}" "/tmp/pihole-meta.deb" rm /tmp/pihole-meta.deb else - printf " %b Error: Unable to find dependency meta package.\\n" "${COL_LIGHT_RED}" + printf " %b Error: Unable to find Pi-hole dependency meta package.\\n" "${COL_LIGHT_RED}" return 1 fi fi # Install Fedora/CentOS packages + if is_command rpm; then + if [ -f /tmp/pihole-meta.rpm ]; then + eval "${PKG_INSTALL}" "/tmp/pihole-meta.rpm" + rm /tmp/pihole-meta.rpm + else + printf " %b Error: Unable to find Pi-hole dependency meta package.\\n" "${COL_LIGHT_RED}" + return 1 + fi + fi printf "\\n" return 0 } @@ -2248,7 +2321,7 @@ main() { # Notify user of package availability notify_package_updates_available - # Build dependecy package + # Build dependency package build_dependency_package # Install Pi-hole dependencies diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 7d9a49ad..70f554e4 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -532,4 +532,3 @@ def test_package_manager_has_pihole_deps(host): assert "No package" not in output.stdout assert output.rc == 0 - From c47f8c2cd67b727fb549efaef15d967a539dc40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 29 Sep 2024 22:21:44 +0200 Subject: [PATCH 03/30] Overhaul uninstall script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 7 +- automated install/uninstall.sh | 116 +++-------------------------- test/_centos_9.Dockerfile | 2 +- test/_debian_11.Dockerfile | 2 +- test/_debian_12.Dockerfile | 2 +- test/_fedora_39.Dockerfile | 2 +- test/_fedora_40.Dockerfile | 2 +- test/_ubuntu_20.Dockerfile | 2 +- test/_ubuntu_22.Dockerfile | 2 +- test/_ubuntu_23.Dockerfile | 2 +- test/_ubuntu_24.Dockerfile | 2 +- test/conftest.py | 5 +- test/test_any_automated_install.py | 22 ++++++ 13 files changed, 48 insertions(+), 120 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index abfb13f3..8bc55c20 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -409,6 +409,8 @@ package_manager_detect() { PKG_INSTALL="${PKG_MANAGER} -qq --no-install-recommends install" # grep -c will return 1 if there are no matches. This is an acceptable condition, so we OR TRUE to prevent set -e exiting the script. PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" + # The command we will use to remove packages (used in the uninstaller) + PKG_REMOVE="${PKG_MANAGER} -y remove --purge" # Update package cache update_package_cache || exit 1 @@ -425,7 +427,8 @@ package_manager_detect() { PKG_INSTALL="${PKG_MANAGER} install -y" # CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting. PKG_COUNT="${PKG_MANAGER} check-update | grep -E '(.i686|.x86|.noarch|.arm|.src|.riscv64)' | wc -l || true" - + # The command we will use to remove packages (used in the uninstaller) + PKG_REMOVE="${PKG_MANAGER} remove -y" # If neither apt-get or yum/dnf package managers were found else # we cannot install required packages @@ -483,8 +486,6 @@ build_dependency_package(){ # Remove the build dependencies when we've installed them if [ -n "${REMOVE_RPM_BUILD}" ]; then - local PKG_REMOVE - PKG_REMOVE="${PKG_MANAGER} remove -y" eval "${PKG_REMOVE}" "rpm-build" fi diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index ac06da73..a073c319 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -38,68 +38,25 @@ fi readonly PI_HOLE_FILES_DIR="/etc/.pihole" SKIP_INSTALL="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" -# setupVars set in basic-install.sh -source "${setupVars}" # package_manager_detect() sourced from basic-install.sh package_manager_detect -# Uninstall packages used by the Pi-hole -DEPS=("${INSTALLER_COMMON_DEPS[@]}" "${PIHOLE_COMMON_DEPS[@]}" "${OS_CHECK_COMMON_DEPS[@]}" "${INSTALLER_DEPS[@]}" "${PIHOLE_DEPS[@]}" "${OS_CHECK_DEPS[@]}") -# Compatibility -if [ -x "$(command -v apt-get)" ]; then - # Debian Family - PKG_REMOVE=("${PKG_MANAGER}" -y remove --purge) - package_check() { - dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" - } -elif [ -x "$(command -v rpm)" ]; then - # Fedora Family - PKG_REMOVE=("${PKG_MANAGER}" remove -y) - package_check() { - rpm -qa | grep "^$1-" > /dev/null - } -else - echo -e " ${CROSS} OS distribution not supported" - exit 1 -fi - -removeAndPurge() { - # Purge dependencies +removeMetaPackage() { + # Purge Pi-hole meta package echo "" - for i in "${DEPS[@]}"; do - if package_check "${i}" > /dev/null; then - while true; do - read -rp " ${QST} Do you wish to remove ${COL_WHITE}${i}${COL_NC} from your system? [Y/N] " answer - case ${answer} in - [Yy]* ) - echo -ne " ${INFO} Removing ${i}..."; - ${SUDO} "${PKG_REMOVE[@]}" "${i}" &> /dev/null; - echo -e "${OVER} ${INFO} Removed ${i}"; - break;; - [Nn]* ) echo -e " ${INFO} Skipped ${i}"; break;; - esac - done - else - echo -e " ${INFO} Package ${i} not installed" - fi - done + echo -ne " ${INFO} Removing Pi-hole meta package..."; + eval "${SUDO}" "${PKG_REMOVE}" "pihole-meta" &> /dev/null; + echo -e "${OVER} ${INFO} Removed Pi-hole meta package"; - # Remove dnsmasq config files - ${SUDO} rm -f /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/*-pihole*.conf &> /dev/null - echo -e " ${TICK} Removing dnsmasq config files" - - # Call removeNoPurge to remove Pi-hole specific files - removeNoPurge } -removeNoPurge() { +removePiholeFiles() { # Only web directories/files that are created by Pi-hole should be removed 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 -f /var/www/html/index.lighttpd.orig &> /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 @@ -126,45 +83,6 @@ removeNoPurge() { echo -e " ${TICK} Removed /etc/cron.d/pihole" fi - if package_check lighttpd > /dev/null; then - # Attempt to preserve backwards compatibility with older versions - if [[ -f /etc/lighttpd/lighttpd.conf.orig ]]; then - ${SUDO} mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf - fi - - if [[ -f /etc/lighttpd/external.conf ]]; then - ${SUDO} rm /etc/lighttpd/external.conf - fi - - # Fedora-based - if [[ -f /etc/lighttpd/conf.d/pihole-admin.conf ]]; then - ${SUDO} rm /etc/lighttpd/conf.d/pihole-admin.conf - conf=/etc/lighttpd/lighttpd.conf - tconf=/tmp/lighttpd.conf.$$ - if awk '!/^include "\/etc\/lighttpd\/conf\.d\/pihole-admin\.conf"$/{print}' \ - $conf > $tconf && mv $tconf $conf; then - : - else - rm $tconf - fi - ${SUDO} chown root:root $conf - ${SUDO} chmod 644 $conf - fi - - # Debian-based - if [[ -f /etc/lighttpd/conf-available/pihole-admin.conf ]]; then - if is_command lighty-disable-mod ; then - ${SUDO} lighty-disable-mod pihole-admin > /dev/null || true - fi - ${SUDO} rm /etc/lighttpd/conf-available/15-pihole-admin.conf - fi - - echo -e " ${TICK} Removed lighttpd configs" - fi - - ${SUDO} rm -f /etc/dnsmasq.d/adList.conf &> /dev/null - ${SUDO} rm -f /etc/dnsmasq.d/01-pihole.conf &> /dev/null - ${SUDO} rm -f /etc/dnsmasq.d/06-rfc6761.conf &> /dev/null ${SUDO} rm -rf /var/log/*pihole* &> /dev/null ${SUDO} rm -rf /var/log/pihole/*pihole* &> /dev/null ${SUDO} rm -rf /etc/pihole/ &> /dev/null @@ -234,23 +152,11 @@ removeNoPurge() { If you need help, reach out to us on GitHub, Discourse, Reddit or Twitter Reinstall at any time: ${COL_WHITE}curl -sSL https://install.pi-hole.net | bash${COL_NC} - ${COL_LIGHT_RED}Please reset the DNS on your router/clients to restore internet connectivity + ${COL_LIGHT_RED}Please reset the DNS on your router/clients to restore internet connectivity${COL_NC} + ${INFO} Pi-hole's meta package has been removed, use the 'autoremove' function from your package manager to remove unused dependencies${COL_NC} ${COL_LIGHT_GREEN}Uninstallation Complete! ${COL_NC}" } ######### SCRIPT ########### -echo -e " ${INFO} Be sure to confirm if any dependencies should not be removed" -while true; do - 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} " - 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] " answer - case ${answer} in - [Yy]* ) removeAndPurge; break;; - [Nn]* ) removeNoPurge; break;; - * ) removeAndPurge; break;; - esac -done +removeMetaPackage +removePiholeFiles diff --git a/test/_centos_9.Dockerfile b/test/_centos_9.Dockerfile index 7e3c5b3a..a5e7cf0b 100644 --- a/test/_centos_9.Dockerfile +++ b/test/_centos_9.Dockerfile @@ -8,7 +8,7 @@ ENV SCRIPTDIR=/opt/pihole RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ diff --git a/test/_debian_11.Dockerfile b/test/_debian_11.Dockerfile index cb7d27cc..b8107244 100644 --- a/test/_debian_11.Dockerfile +++ b/test/_debian_11.Dockerfile @@ -5,7 +5,7 @@ ENV SCRIPTDIR=/opt/pihole RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ diff --git a/test/_debian_12.Dockerfile b/test/_debian_12.Dockerfile index 50d709b1..7446711a 100644 --- a/test/_debian_12.Dockerfile +++ b/test/_debian_12.Dockerfile @@ -5,7 +5,7 @@ ENV SCRIPTDIR=/opt/pihole RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ diff --git a/test/_fedora_39.Dockerfile b/test/_fedora_39.Dockerfile index 1d3dbc63..5312c2db 100644 --- a/test/_fedora_39.Dockerfile +++ b/test/_fedora_39.Dockerfile @@ -6,7 +6,7 @@ ENV SCRIPTDIR=/opt/pihole RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ diff --git a/test/_fedora_40.Dockerfile b/test/_fedora_40.Dockerfile index e4879c92..20102a10 100644 --- a/test/_fedora_40.Dockerfile +++ b/test/_fedora_40.Dockerfile @@ -6,7 +6,7 @@ ENV SCRIPTDIR=/opt/pihole RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ diff --git a/test/_ubuntu_20.Dockerfile b/test/_ubuntu_20.Dockerfile index 64d4f415..75c12673 100644 --- a/test/_ubuntu_20.Dockerfile +++ b/test/_ubuntu_20.Dockerfile @@ -5,7 +5,7 @@ ENV SCRIPTDIR=/opt/pihole RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ diff --git a/test/_ubuntu_22.Dockerfile b/test/_ubuntu_22.Dockerfile index 34faa361..9206a46a 100644 --- a/test/_ubuntu_22.Dockerfile +++ b/test/_ubuntu_22.Dockerfile @@ -5,7 +5,7 @@ ENV SCRIPTDIR=/opt/pihole RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR ENV DEBIAN_FRONTEND=noninteractive diff --git a/test/_ubuntu_23.Dockerfile b/test/_ubuntu_23.Dockerfile index ea0ad245..4f88be7d 100644 --- a/test/_ubuntu_23.Dockerfile +++ b/test/_ubuntu_23.Dockerfile @@ -5,7 +5,7 @@ ENV SCRIPTDIR=/opt/pihole RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR ENV DEBIAN_FRONTEND=noninteractive diff --git a/test/_ubuntu_24.Dockerfile b/test/_ubuntu_24.Dockerfile index 4d581cd3..4cab43de 100644 --- a/test/_ubuntu_24.Dockerfile +++ b/test/_ubuntu_24.Dockerfile @@ -5,7 +5,7 @@ ENV SCRIPTDIR=/opt/pihole RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR ENV DEBIAN_FRONTEND=noninteractive diff --git a/test/conftest.py b/test/conftest.py index 164e8de5..dcf49790 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -5,9 +5,8 @@ import subprocess from textwrap import dedent IMAGE = "pytest_pihole:test_container" - -tick_box = "[\x1b[1;32m\u2713\x1b[0m]" -cross_box = "[\x1b[1;31m\u2717\x1b[0m]" +tick_box = "[✓]" +cross_box = "[✗]" info_box = "[i]" diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 70f554e4..19812122 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -532,3 +532,25 @@ def test_package_manager_has_pihole_deps(host): assert "No package" not in output.stdout assert output.rc == 0 + + +def test_meta_package_uninstall(host): + """Confirms OS is able to install and uninstall the Pi-hole meta package""" + mock_command("dialog", {"*": ("", "0")}, host) + install = host.run( + """ + source /opt/pihole/basic-install.sh + package_manager_detect + build_dependency_package + install_dependent_packages + """ + ) + assert install.rc == 0 + + uninstall = host.run( + """ + source /opt/pihole/uninstall.sh + removeMetaPackage + """ + ) + assert uninstall.rc == 0 From cd7e5abe25a76c4c7e854fd7e85f133fd9586006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 29 Sep 2024 22:45:47 +0200 Subject: [PATCH 04/30] Add TRAP to the installer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8bc55c20..e57515d5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -25,6 +25,9 @@ set -e # When using "su" an incomplete PATH could be passed: https://github.com/pi-hole/pi-hole/issues/3209 export PATH+=':/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' +# Trap any errors, then exit +trap abort INT QUIT TERM + ######## VARIABLES ######### # For better maintainability, we store as much information that can change in variables # This allows us to make a change in one place that can propagate to all instances of the variable @@ -195,6 +198,15 @@ show_ascii_berry() { " } +abort() { + echo -e "\\n\\n ${COL_LIGHT_RED}Installation was interrupted${COL_NC}\\n" + echo -e "Pi-hole's dependencies might be already installed. If you want to remove them you can try to\\n" + echo -e "a) run 'pihole uninstall' \\n" + echo -e "b) Remove the meta-package 'pihole-meta' manually \\n" + echo -e "E.g. sudo apt-get remove pihole-meta && apt-get autoremove \\n" + exit 1 +} + is_command() { # Checks to see if the given command (passed as a string argument) exists on the system. # The function returns 0 (success) if the command exists, and 1 if it doesn't. From 9478e35cb7bc45ef00480ea81a70ad095cca7daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 12 Oct 2024 14:34:21 +0200 Subject: [PATCH 05/30] Create a random temp direcotry to build the packages and remove leftovers Co-authored-by: RD WebDesign Signed-off-by: yubiuser --- automated install/basic-install.sh | 44 ++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e57515d5..75418f1c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -120,7 +120,6 @@ EOM # Content of Pi-hole's meta package control file on RPM based systems PIHOLE_META_PACKAGE_CONTROL_RPM=$( cat </dev/null || return 1 + # remove leftover package if it exists from previous runs + rm -f /tmp/pihole-meta.deb + # Prepare directory structure and control file - mkdir -p /tmp/pihole-meta/DEBIAN - chmod 0755 /tmp/pihole-meta/DEBIAN - touch /tmp/pihole-meta/DEBIAN/control + mkdir -p "${tempdir}"/DEBIAN + chmod 0755 "${tempdir}"/DEBIAN + touch "${tempdir}"/DEBIAN/control # Write the control file - echo "${PIHOLE_META_PACKAGE_CONTROL_APT}" > /tmp/pihole-meta/DEBIAN/control + echo "${PIHOLE_META_PACKAGE_CONTROL_APT}" > "${tempdir}"/DEBIAN/control # Build the package - dpkg-deb --build --root-owner-group pihole-meta + dpkg-deb --build --root-owner-group "${tempdir}" pihole-meta.deb # Move back into the directory the user started in popd &> /dev/null || return 1 @@ -479,10 +490,13 @@ build_dependency_package(){ # move into the tmp directory pushd /tmp &>/dev/null || return 1 + # remove leftover package if it exists from previous runs + rm -f /tmp/pihole-meta.rpm + # Prepare directory structure and spec file - mkdir -p /tmp/pihole-meta/SPECS - touch /tmp/pihole-meta/SPECS/pihole-meta.spec - echo "${PIHOLE_META_PACKAGE_CONTROL_RPM}" > /tmp/pihole-meta/SPECS/pihole-meta.spec + mkdir -p "${tempdir}"/SPECS + touch "${tempdir}"/SPECS/pihole-meta.spec + echo "${PIHOLE_META_PACKAGE_CONTROL_RPM}" > "${tempdir}"/SPECS/pihole-meta.spec # check if we need to install the build dependencies if ! is_command rpmbuild; then @@ -491,10 +505,10 @@ build_dependency_package(){ fi # Build the package - rpmbuild -bb /tmp/pihole-meta/SPECS/pihole-meta.spec + rpmbuild -bb "${tempdir}"/SPECS/pihole-meta.spec --define "_topdir ${tempdir}" # Move the package to the /tmp directory - mv /tmp/pihole-meta/RPMS/noarch/pihole-meta*.rpm /tmp/pihole-meta.rpm + mv "${tempdir}"/RPMS/noarch/pihole-meta*.rpm /tmp/pihole-meta.rpm # Remove the build dependencies when we've installed them if [ -n "${REMOVE_RPM_BUILD}" ]; then @@ -506,7 +520,7 @@ build_dependency_package(){ fi # Remove the build directory - rm -rf /tmp/pihole-meta + rm -rf "${tempdir}" } # A function for checking if a directory is a git repository From b23348916b3b7cf175128c7ad32ce69ea28dc294 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 26 Nov 2024 21:07:11 +0100 Subject: [PATCH 06/30] Remove Ubuntu 23 tests, it is EOL Signed-off-by: DL6ER --- .github/workflows/test.yml | 1 - test/tox.ubuntu_23.ini | 10 ---------- 2 files changed, 11 deletions(-) delete mode 100644 test/tox.ubuntu_23.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7c419e9a..983ca0bc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,7 +65,6 @@ jobs: debian_12, ubuntu_20, ubuntu_22, - ubuntu_23, ubuntu_24, centos_9, fedora_40, diff --git a/test/tox.ubuntu_23.ini b/test/tox.ubuntu_23.ini deleted file mode 100644 index f0a32a68..00000000 --- a/test/tox.ubuntu_23.ini +++ /dev/null @@ -1,10 +0,0 @@ -[tox] -envlist = py3 - -[testenv:py3] -allowlist_externals = docker -deps = -rrequirements.txt -setenv = - COLUMNS=120 -commands = docker buildx build --load --progress plain -f _ubuntu_23.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From 5ef4a5e8b074aa878c6f82248b5f0c7f0c6f5a2e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Dec 2024 10:09:54 +0000 Subject: [PATCH 07/30] Bump pytest from 8.3.3 to 8.3.4 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 8.3.3 to 8.3.4. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/8.3.3...8.3.4) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 93232df7..d72475c4 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ pyyaml == 6.0.2 -pytest == 8.3.3 +pytest == 8.3.4 pytest-xdist == 3.6.1 pytest-testinfra == 10.1.1 tox == 4.23.2 From 11e00e04b5bb7cf99131552f566db7209b5f03c6 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 7 Dec 2024 10:27:20 +0100 Subject: [PATCH 08/30] Fix ARP flush command Signed-off-by: DL6ER --- advanced/Scripts/piholeARPTable.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeARPTable.sh b/advanced/Scripts/piholeARPTable.sh index c04c5b33..f55b1320 100755 --- a/advanced/Scripts/piholeARPTable.sh +++ b/advanced/Scripts/piholeARPTable.sh @@ -32,7 +32,7 @@ flushARP(){ fi # Stop FTL to prevent database access - if ! output=$(pihole-FTL service stop 2>&1); then + if ! output=$(service pihole-FTL stop 2>&1); then echo -e "${OVER} ${CROSS} Failed to stop FTL" echo " Output: ${output}" return 1 @@ -64,7 +64,7 @@ flushARP(){ fi # Start FTL again - if ! output=$(pihole-FTL service restart 2>&1); then + if ! output=$(service pihole-FTL restart 2>&1); then echo -e "${OVER} ${CROSS} Failed to restart FTL" echo " Output: ${output}" return 1 From 8f1fce8f4bcc795bf721da21b242cdd6b7eab364 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 10 Dec 2024 19:01:58 +0000 Subject: [PATCH 09/30] move the sourcing of utils.sh outside of installPihole Signed-off-by: Adam Warner --- automated install/basic-install.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 90eea220..b2bbb219 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1685,15 +1685,6 @@ installPihole() { exit 1 fi - # /opt/pihole/utils.sh should be installed by installScripts now, so we can use it - if [ -f "${PI_HOLE_INSTALL_DIR}/utils.sh" ]; then - # shellcheck disable=SC1091 - source "${PI_HOLE_INSTALL_DIR}/utils.sh" - else - printf " %b Failure: /opt/pihole/utils.sh does not exist .\\n" "${CROSS}" - exit 1 - fi - remove_old_dnsmasq_ftl_configs remove_old_pihole_lighttpd_configs @@ -2426,6 +2417,15 @@ main() { # Install and log everything to a file installPihole | tee -a /proc/$$/fd/3 + # /opt/pihole/utils.sh should be installed by installScripts now, so we can use it + if [ -f "${PI_HOLE_INSTALL_DIR}/utils.sh" ]; then + # shellcheck disable=SC1091 + source "${PI_HOLE_INSTALL_DIR}/utils.sh" + else + printf " %b Failure: /opt/pihole/utils.sh does not exist .\\n" "${CROSS}" + exit 1 + fi + # Copy the temp log file into final log location for storage copy_to_install_log From 764aa48c143bb1f4b36b8a8002b52d9e67c67e10 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 11 Dec 2024 17:22:49 +0000 Subject: [PATCH 10/30] Remove no-longer-needed utils Signed-off-by: Adam Warner --- advanced/Scripts/utils.sh | 38 ----------------------- test/test_any_utils.py | 64 --------------------------------------- 2 files changed, 102 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 67301394..63d51f87 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -25,7 +25,6 @@ # # Example usage: # addOrEditKeyValPair "/etc/pihole/setupVars.conf" "BLOCKING_ENABLED" "true" -# TODO: We miight not actually need this function in v6 ####################### addOrEditKeyValPair() { local file="${1}" @@ -44,43 +43,6 @@ addOrEditKeyValPair() { fi } -####################### -# Takes two arguments: file, and key. -# Adds a key to target file -# -# Example usage: -# addKey "/etc/dnsmasq.d/01-pihole.conf" "log-queries" -####################### -addKey(){ - local file="${1}" - local key="${2}" - - # touch file to prevent grep error if file does not exist yet - touch "${file}" - - # Match key against entire line, using both anchors. We assume - # that the file's keys never have bounding whitespace. Anchors - # are necessary to ensure the key is considered absent when it - # is a substring of another key present in the file. - if ! grep -q "^${key}$" "${file}"; then - # Key does not exist, add it. - echo "${key}" >> "${file}" - fi -} - -####################### -# Takes two arguments: file, and key. -# Deletes a key or key/value pair from target file -# -# Example usage: -# removeKey "/etc/pihole/setupVars.conf" "PIHOLE_DNS_1" -####################### -removeKey() { - local file="${1}" - local key="${2}" - sed -i "/^${key}/d" "${file}" -} - ####################### # returns FTL's PID based on the content of the pihole-FTL.pid file # diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 59745c48..cf6cc7e6 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -18,70 +18,6 @@ def test_key_val_replacement_works(host): assert expected_stdout == output.stdout -def test_key_addition_works(host): - """Confirms addKey adds a key (no value) to a file without duplicating it""" - host.run( - """ - source /opt/pihole/utils.sh - addKey "./testoutput" "KEY_ONE" - addKey "./testoutput" "KEY_ONE" - addKey "./testoutput" "KEY_TWO" - addKey "./testoutput" "KEY_TWO" - addKey "./testoutput" "KEY_THREE" - addKey "./testoutput" "KEY_THREE" - """ - ) - output = host.run( - """ - cat ./testoutput - """ - ) - expected_stdout = "KEY_ONE\nKEY_TWO\nKEY_THREE\n" - assert expected_stdout == output.stdout - - -def test_key_addition_substr(host): - """Confirms addKey adds substring keys (no value) to a file""" - host.run( - """ - source /opt/pihole/utils.sh - addKey "./testoutput" "KEY_ONE" - addKey "./testoutput" "KEY_O" - addKey "./testoutput" "KEY_TWO" - addKey "./testoutput" "Y_TWO" - """ - ) - output = host.run( - """ - cat ./testoutput - """ - ) - expected_stdout = "KEY_ONE\nKEY_O\nKEY_TWO\nY_TWO\n" - assert expected_stdout == output.stdout - - -def test_key_removal_works(host): - """Confirms removeKey removes a key or key/value pair""" - host.run( - """ - source /opt/pihole/utils.sh - addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1" - addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2" - addOrEditKeyValPair "./testoutput" "KEY_THREE" "value3" - addKey "./testoutput" "KEY_FOUR" - removeKey "./testoutput" "KEY_TWO" - removeKey "./testoutput" "KEY_FOUR" - """ - ) - output = host.run( - """ - cat ./testoutput - """ - ) - expected_stdout = "KEY_ONE=value1\nKEY_THREE=value3\n" - assert expected_stdout == output.stdout - - def test_getFTLPID_default(host): """Confirms getFTLPID returns the default value if FTL is not running""" output = host.run( From fdda40994b2e4f3515c9a84738c1e0bf5d7aaada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 14 Dec 2024 22:26:05 +0100 Subject: [PATCH 11/30] Fix rare case when apt and rpm package managers are found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b2bbb219..81b240e4 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -484,9 +484,8 @@ build_dependency_package(){ # Move back into the directory the user started in popd &> /dev/null || return 1 - fi - if is_command rpm; then + elif is_command rpm; then # move into the tmp directory pushd /tmp &>/dev/null || return 1 @@ -517,6 +516,13 @@ build_dependency_package(){ # Move back into the directory the user started in popd &> /dev/null || return 1 + + # If neither apt-get or yum/dnf package managers were found + else + # we cannot build required packages + printf " %b No supported package manager found\\n" "${CROSS}" + # so exit the installer + exit 1 fi # Remove the build directory From cc01c110f18a2137a2c3f7cd874de80a979b63a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 14 Dec 2024 22:31:02 +0100 Subject: [PATCH 12/30] Also check during installlation of the dependency package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 81b240e4..f1ef8887 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1517,11 +1517,9 @@ install_dependent_packages() { printf " %b Error: Unable to find Pi-hole dependency meta package.\\n" "${COL_LIGHT_RED}" return 1 fi - fi - # Install Fedora/CentOS packages - if is_command rpm; then - if [ -f /tmp/pihole-meta.rpm ]; then + elif is_command rpm; then + if [ -f /tmp/pihole-meta.rpm ]; then eval "${PKG_INSTALL}" "/tmp/pihole-meta.rpm" rm /tmp/pihole-meta.rpm else @@ -1529,7 +1527,14 @@ install_dependent_packages() { return 1 fi + # If neither apt-get or yum/dnf package managers were found + else + # we cannot install the dependency package + printf " %b No supported package manager found\\n" "${CROSS}" + # so exit the installer + exit 1 fi + printf "\\n" return 0 } From 26ef0be9d635bce7a410330d9c4932a661c45970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 16 Dec 2024 11:56:04 +0100 Subject: [PATCH 13/30] One check less MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f1ef8887..a4ccf434 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2490,10 +2490,6 @@ main() { # Update local and remote versions via updatechecker /opt/pihole/updatecheck.sh - if [[ "${useUpdateVars}" == false ]]; then - displayFinalMessage "${pw}" - fi - # If there is a password if ((${#pw} > 0)); then # display the password @@ -2502,6 +2498,9 @@ main() { fi if [[ "${useUpdateVars}" == false ]]; then + # Display the completion dialog + displayFinalMessage "${pw}" + # If the Web interface was installed, printf " %b View the web interface at http://pi.hole:${WEBPORT}/admin or http://%s/admin\\n\\n" "${INFO}" "${IPV4_ADDRESS%/*}:${WEBPORT}" From 4d55bc1ae3d244e19e7158eeffdbf3bb3d2eb208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 16 Dec 2024 12:08:16 +0100 Subject: [PATCH 14/30] pihole -a is gone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 4 ++-- manpages/pihole.8 | 34 ++++++------------------------ 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a4ccf434..ef1e372a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2446,7 +2446,7 @@ main() { if [[ $(pihole-FTL --config webserver.api.pwhash) == '""' ]]; then # generate a random password pw=$(tr -dc _A-Z-a-z-0-9 0)); then # display the password printf " %b Web Interface password: %b%s%b\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${pw}" "${COL_NC}" - printf " %b This can be changed using 'pihole -a -p'\\n\\n" "${INFO}" + printf " %b This can be changed using 'pihole setpassword'\\n\\n" "${INFO}" fi if [[ "${useUpdateVars}" == false ]]; then diff --git a/manpages/pihole.8 b/manpages/pihole.8 index 825a1fd1..5a312efe 100644 --- a/manpages/pihole.8 +++ b/manpages/pihole.8 @@ -7,13 +7,7 @@ Pi-hole : A black-hole for internet advertisements \fBpihole\fR (\fB-w\fR|\fB-b\fR|\fB--wild\fR|\fB--regex\fR) [options] domain(s) .br -\fBpihole -a\fR \fB-p\fR password -.br -\fBpihole -a\fR (\fB-c|-f|-k\fR) -.br -\fBpihole -a -i\fR interface -.br -\fBpihole -a -l\fR privacylevel +\fBpihole setpassword\fR password .br \fBpihole -c\fR [-j|-r|-e] .br @@ -120,25 +114,6 @@ Available commands and options: (regular expressions are supported) .br -\fB-a, admin\fR [options] -.br - - (Admin options): -.br - -p, password Set Web Interface password -.br - -c, celsius Set Celsius as preferred temperature unit -.br - -f, fahrenheit Set Fahrenheit as preferred temperature unit -.br - -k, kelvin Set Kelvin as preferred temperature unit -.br - -i, interface Specify dnsmasq's interface listening behavior -.br - -l, privacylevel Set privacy level - (0 = lowest, 3 = highest) -.br - \fB-g, updateGravity\fR .br Update the list of ad-serving domains @@ -211,6 +186,11 @@ Available commands and options: repositories .br +\fBsetpassword\fR +.br + Set Web Interface password +.br + \fBuninstall\fR .br Uninstall Pi-hole from your system @@ -303,7 +283,7 @@ Allow-/denylist manipulation Changing the Web Interface password .br -\fBpihole -a -p ExamplePassword\fR +\fBpihole setpassword ExamplePassword\fR .br Change the password to "ExamplePassword" .br From 3ac426b5d183e412c57673cef91b919bb78efac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 16 Dec 2024 12:42:07 +0100 Subject: [PATCH 15/30] Update manpage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- manpages/pihole.8 | 77 ++++++++++++++++++++--------------------------- pihole | 1 + 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/manpages/pihole.8 b/manpages/pihole.8 index 5a312efe..97a6ec68 100644 --- a/manpages/pihole.8 +++ b/manpages/pihole.8 @@ -5,13 +5,15 @@ Pi-hole : A black-hole for internet advertisements .br .SH "SYNOPSIS" -\fBpihole\fR (\fB-w\fR|\fB-b\fR|\fB--wild\fR|\fB--regex\fR) [options] domain(s) +\fBpihole\fR (\fB-allow\fR|\fB-deny\fR) [options] domain(s) +.br +\fBpihole\fR (\fB--allow-regex\fR|\fB--regex\fR) [options] domain(s) +.br +\fBpihole\fR (\fB--allow-wild\fR|\fB--wild\fR) [options] domain(s) .br \fBpihole setpassword\fR password .br -\fBpihole -c\fR [-j|-r|-e] -.br -\fBpihole\fR \fB-d\fR [-a] +\fBpihole\fR \fB-d\fR [-a] [-c] .br \fBpihole -f .br @@ -19,7 +21,7 @@ pihole -r .br \fBpihole\fR \fB-t\fR [arg] .br -pihole -g\fR +\fBpihole -g\fR .br \fBpihole\fR -\fBq\fR [options] .br @@ -27,20 +29,22 @@ pihole -g\fR .br \fBpihole -up \fR[--check-only] .br -\fBpihole -v\fR [-p|-a|-f] [-c|-l|-hash] +\fBpihole -v\fR .br -\fBpihole uninstall +\fBpihole uninstall\fR .br -pihole status +\fBpihole status\fR .br -pihole reloaddns\fR +\fBpihole reloaddns\fR .br -pihole reloadlists\fR +\fBpihole reloadlists\fR .br \fBpihole\fR (\fBenable\fR|\fBdisable\fR [time]) .br \fBpihole\fR \fBcheckout\fR repo [branch] .br +\fBpihole\fR \api\fR endpoint +.br \fBpihole\fR \fBhelp\fR .br .SH "DESCRIPTION" @@ -93,6 +97,7 @@ Available commands and options: .br -a Enable automated debugging + -c Include a Pi-hole database integrity check .br \fB-f, flush\fR @@ -126,11 +131,9 @@ Available commands and options: (Query options): .br - -adlist Print the name of the block list URL + -partial Search the adlists for partially matching domains .br - -exact Search the block lists for exact domain matches -.br - -all Return all query matches within a block list + -all Return all query matches within a adlists .br \fB-h, --help, help\fR @@ -161,31 +164,11 @@ Available commands and options: --check-only Exit script before update is performed. .br -\fB-v, version\fR [repo] [options] +\fB-v, version\fR .br Show installed versions of Pi-hole, Web Interface & FTL .br -.br - (repo options): -.br - -p, --pihole Only retrieve info regarding Pi-hole repository -.br - -a, --admin Only retrieve info regarding web - repository -.br - -f, --ftl Only retrieve info regarding FTL repository -.br - (version options): -.br - -c, --current Return the current version -.br - -l, --latest Return the latest version -.br - --hash Return the GitHub hash from your local - repositories -.br - \fBsetpassword\fR .br Set Web Interface password @@ -201,14 +184,14 @@ Available commands and options: Display the running status of Pi-hole subsystems .br -\fBenable\fR +\fBenable\fR [time] .br - Enable Pi-hole subsystems + Enable Pi-hole blocking, optionally for a set duration .br \fBdisable\fR [time] .br - Disable Pi-hole subsystems, optionally for a set duration + Disable Pi-hole blocking, optionally for a set duration .br (time options): @@ -250,6 +233,11 @@ Available commands and options: .br branchname Update subsystems to the specified branchname .br + +\fBapi\fR endpoint +.br + Query the Pi-hole API at +.br .SH "EXAMPLE" Some usage examples @@ -263,7 +251,7 @@ Allow-/denylist manipulation Allow "iloveads.example.com" .br -\fBpihole deny not noads.example.com\fR +\fBpihole deny remove noads.example.com\fR .br Removes "noads.example.com" from denylist .br @@ -299,9 +287,9 @@ Updating lists from internet sources Displaying version information .br -\fBpihole -v -a -c\fR +\fBpihole -v\fR .br - Display the current version of web + Display the current version of Pi-hole .br Temporarily disabling Pi-hole @@ -330,10 +318,11 @@ Switching Pi-hole subsystem branches Flush information stored in Pi-hole's network tables .br -.SH "SEE ALSO" - -\fBlighttpd\fR(8), \fBpihole-FTL\fR(8) +\fBpihole api stats/summary\fR .br + Queries FTL for the stats/summary endpoint +.br + .SH "COLOPHON" Get sucked into the latest news and community activity by entering Pi-hole's orbit. Information about Pi-hole, and the latest version of the software can be found at https://pi-hole.net. diff --git a/pihole b/pihole index 5657637b..f3e14ac6 100755 --- a/pihole +++ b/pihole @@ -501,6 +501,7 @@ Options: uninstall Uninstall Pi-hole from your system status Display the running status of Pi-hole subsystems enable Enable Pi-hole subsystems + Add '-h' for more info on enable usage disable Disable Pi-hole subsystems Add '-h' for more info on disable usage reloaddns Update the lists and flush the cache without restarting the DNS server From 7dc542f3c294539a5349b0d90b6e9529ee6c6ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 16 Dec 2024 12:51:23 +0100 Subject: [PATCH 16/30] Get WEBPORT from pihole.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ef1e372a..bff59bb8 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -91,7 +91,7 @@ IPV4_ADDRESS=${IPV4_ADDRESS} IPV6_ADDRESS=${IPV6_ADDRESS} # Give settings their default values. These may be changed by prompts later in the script. QUERY_LOGGING= -WEBPORT=8080 +WEBPORT= PRIVACY_LEVEL= # Where old configs go to if a v6 migration is performed @@ -2498,6 +2498,9 @@ main() { fi if [[ "${useUpdateVars}" == false ]]; then + # Get the Web interface port, return only the first port + WEBPORT=$(getFTLConfigValue webserver.port|cut -d, -f1) + # Display the completion dialog displayFinalMessage "${pw}" From b2a556468534692c887d55490810f01147db2de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 16 Dec 2024 13:06:25 +0100 Subject: [PATCH 17/30] FTL allows non-numieric port notation - we need to strip this MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bff59bb8..20051b83 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2498,8 +2498,8 @@ main() { fi if [[ "${useUpdateVars}" == false ]]; then - # Get the Web interface port, return only the first port - WEBPORT=$(getFTLConfigValue webserver.port|cut -d, -f1) + # Get the Web interface port, return only the first port and strip all non-numeric characters + WEBPORT=$(getFTLConfigValue webserver.port|cut -d, -f1 | tr -cd '0-9') # Display the completion dialog displayFinalMessage "${pw}" From 83224e7729e91849b9b8f8506c33e85061f78d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 16 Dec 2024 09:30:25 +0100 Subject: [PATCH 18/30] Improve dependency package output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 49 ++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f1ef8887..976bcf72 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -480,7 +480,16 @@ build_dependency_package(){ echo "${PIHOLE_META_PACKAGE_CONTROL_APT}" > "${tempdir}"/DEBIAN/control # Build the package - dpkg-deb --build --root-owner-group "${tempdir}" pihole-meta.deb + local str="Building dependency package pihole-meta.deb" + printf " %b %s..." "${INFO}" "${str}" + + if dpkg-deb --build --root-owner-group "${tempdir}" pihole-meta.deb &>/dev/null; then + printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" + else + printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" + printf "%b Error: Building pihole-meta.deb failed. %b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + return 1 + fi # Move back into the directory the user started in popd &> /dev/null || return 1 @@ -504,7 +513,16 @@ build_dependency_package(){ fi # Build the package - rpmbuild -bb "${tempdir}"/SPECS/pihole-meta.spec --define "_topdir ${tempdir}" + local str="Building dependency package pihole-meta.rpm" + printf " %b %s..." "${INFO}" "${str}" + + if rpmbuild -bb "${tempdir}"/SPECS/pihole-meta.spec --define "_topdir ${tempdir}" &>/dev/null; then + printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" + else + printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" + printf "%b Error: Building pihole-meta.rpm failed. %b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + return 1 + fi # Move the package to the /tmp directory mv "${tempdir}"/RPMS/noarch/pihole-meta*.rpm /tmp/pihole-meta.rpm @@ -1507,23 +1525,37 @@ notify_package_updates_available() { install_dependent_packages() { # Install meta dependency package + local str="Installing Pi-hole dependency package" + printf " %b %s..." "${INFO}" "${str}" # Install Debian/Ubuntu packages if is_command apt-get; then if [ -f /tmp/pihole-meta.deb ]; then - eval "${PKG_INSTALL}" "/tmp/pihole-meta.deb" - rm /tmp/pihole-meta.deb + if eval "${PKG_INSTALL}" "/tmp/pihole-meta.deb" &>/dev/null; then + printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" + rm /tmp/pihole-meta.deb + else + printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" + printf " %b Error: Unable to install Pi-hole dependency package.\\n" "${COL_LIGHT_RED}" + return 1 + fi else - printf " %b Error: Unable to find Pi-hole dependency meta package.\\n" "${COL_LIGHT_RED}" + printf " %b Error: Unable to find Pi-hole dependency package.\\n" "${COL_LIGHT_RED}" return 1 fi # Install Fedora/CentOS packages elif is_command rpm; then if [ -f /tmp/pihole-meta.rpm ]; then - eval "${PKG_INSTALL}" "/tmp/pihole-meta.rpm" - rm /tmp/pihole-meta.rpm + if eval "${PKG_INSTALL}" "/tmp/pihole-meta.rpm" &>/dev/null; then + printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" + rm /tmp/pihole-meta.rpm + else + printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" + printf " %b Error: Unable to install Pi-hole dependency package.\\n" "${COL_LIGHT_RED}" + return 1 + fi else - printf " %b Error: Unable to find Pi-hole dependency meta package.\\n" "${COL_LIGHT_RED}" + printf " %b Error: Unable to find Pi-hole dependency package.\\n" "${COL_LIGHT_RED}" return 1 fi @@ -2354,7 +2386,6 @@ main() { build_dependency_package # Install Pi-hole dependencies - printf " %b Installing required dependencies ...\\n" "${INFO}" install_dependent_packages # Check that the installed OS is officially supported - display warning if not From 92a3c73f801c358fbfa015fd908ef2802f7a64a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 22 Dec 2024 21:46:32 +0100 Subject: [PATCH 19/30] Fix v5 -> v6 update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 755d8dd9..c5d2ad9c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2401,8 +2401,8 @@ main() { exit 1 fi - # in case of an update - if [[ -f "${PI_HOLE_V6_CONFIG}" ]]; then + # in case of an update (can be a v5 -> v6 or v6 -> v6 update) + if [[ -f "${PI_HOLE_V6_CONFIG}" ]] || [[ -f "/etc/pihole/setupVars.conf" ]]; then # if it's running unattended, if [[ "${runUnattended}" == true ]]; then printf " %b Performing unattended setup, no dialogs will be displayed\\n" "${INFO}" From c777152c04b8cc1f8a1b07e05bdd61d38180fb38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 22 Dec 2024 21:55:25 +0100 Subject: [PATCH 20/30] Only separat data and status when needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/api.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/api.sh b/advanced/Scripts/api.sh index 43c91d69..785b8309 100755 --- a/advanced/Scripts/api.sh +++ b/advanced/Scripts/api.sh @@ -165,15 +165,16 @@ GetFTLData() { # get the data from querying the API as well as the http status code response=$(curl -skS -w "%{http_code}" -X GET "${API_URL}$1" -H "Accept: application/json" -H "sid: ${SID}" ) - # status are the last 3 characters - status="${response#"${response%???}"}" - # data is everything from response without the last 3 characters - data="${response%???}" - if [ "${2}" = "raw" ]; then # return the raw response echo "${response}" else + + # status are the last 3 characters # status are the last 3 characters + status="${response#"${response%???}"}" + # data is everything from response without the last 3 characters + data="${response%???}" + # return only the data if [ "${status}" = 200 ]; then # response OK From 3011d48b6f22996f36b2e72cad633484e9e3d0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 22 Dec 2024 23:30:14 +0100 Subject: [PATCH 21/30] Use tail instead of parameter expansion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/api.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/api.sh b/advanced/Scripts/api.sh index 785b8309..c9c2dd49 100755 --- a/advanced/Scripts/api.sh +++ b/advanced/Scripts/api.sh @@ -170,8 +170,9 @@ GetFTLData() { echo "${response}" else - # status are the last 3 characters # status are the last 3 characters - status="${response#"${response%???}"}" + # status are the last 3 characters + # not using ${response#"${response%???}"}" here because it's extremely slow on big responses + status=$(printf "%s" "${response}" | tail -c 3) # data is everything from response without the last 3 characters data="${response%???}" @@ -265,7 +266,8 @@ apiFunc() { response=$(GetFTLData "$1" raw) # status are the last 3 characters - status="${response#"${response%???}"}" + # not using ${response#"${response%???}"}" here because it's extremely slow on big responses + status=$(printf "%s" "${response}" | tail -c 3) # data is everything from response without the last 3 characters data="${response%???}" From a2a22c4e138398499d649135ccc7c53a3fcf019a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 23 Dec 2024 09:13:34 +0100 Subject: [PATCH 22/30] Exit early when neither service nor systemctl commands are available Signed-off-by: DL6ER --- automated install/basic-install.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c5d2ad9c..368fa6c0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2328,6 +2328,17 @@ migrate_dnsmasq_configs() { mv /etc/dnsmasq.d/06-rfc6761.conf "${V6_CONF_MIGRATION_DIR}/" 2>/dev/null || true } +# Check for availability of either the "service" or "systemctl" commands +check_service_command() { + # Check for the availability of the "service" command + if ! is_command service && ! is_command systemctl; then + # If neither the "service" nor the "systemctl" command is available, inform the user + printf " %b Neither the service nor the systemctl commands are available\\n" "${CROSS}" + printf " on this machine. This Pi-hole installer cannot continue.\\n" + exit 1 + fi +} + main() { ######## FIRST CHECK ######## # Must be root to install @@ -2376,6 +2387,9 @@ main() { # Check if SELinux is Enforcing and exit before doing anything else checkSelinux + # Check for availability of either the "service" or "systemctl" commands + check_service_command + # Check for supported package managers so that we may install dependencies package_manager_detect From e08f65d1c4ca40de27df124ac378736a3cf0f189 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 23 Dec 2024 09:30:37 +0100 Subject: [PATCH 23/30] Disable lighttpd if found Signed-off-by: DL6ER --- automated install/basic-install.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c5d2ad9c..7411b2c5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2300,6 +2300,21 @@ copy_to_install_log() { chown pihole:pihole "${installLogLoc}" } +disableLighttpd() { + # Lighttpd is not needed anymore, so disable it + # We keep all the configuration files in place, so the user can re-enable it + # if needed + + # Check if lighttpd is installed + if is_command lighttpd; then + # Stop the lighttpd service + stop_service lighttpd + + # Disable the lighttpd service + disable_service lighttpd + fi +} + migrate_dnsmasq_configs() { # Previously, Pi-hole created a number of files in /etc/dnsmasq.d # During migration, their content is copied into the new single source of @@ -2489,6 +2504,9 @@ main() { # but before starting or resttarting the ftl service disable_resolved_stublistener + # Disable lighttpd server + disableLighttpd + # Check if gravity database needs to be upgraded. If so, do it without rebuilding # gravity altogether. This may be a very long running task needlessly blocking # the update process. From 47d5a085652e05e4b0a0fbafe9393ff3112fce9e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 23 Dec 2024 19:12:47 +0100 Subject: [PATCH 24/30] Ask the user if they want to disable lighttpd Signed-off-by: DL6ER --- automated install/basic-install.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 7411b2c5..fc2b28ef 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2301,6 +2301,24 @@ copy_to_install_log() { } disableLighttpd() { + # Detect if the terminal is interactive + if [[ -t 0 ]]; then + # The terminal is interactive + dialog --no-shadow --keep-tite \ + --title "Pi-hole v6.0 does no longer need lighttpd" \ + --yesno "Pi-hole v6.0 has its own embedded web server so lighttpd is no longer needed *unless* you have custom configurations. In this case, you can opt-out of disabling lighttpd and pihole-FTL will try to bind to an alternative port such as 8080.\\n\\nDo you want to disable lighttpd (recommended)?" "${r}" "${c}" + response=$? + else + # The terminal is non-interactive, assume yes. Lighttpd will be stopped + # but keeps being installed and can easily be re-enabled by the user + response=0 + fi + + # If the user does not want to disable lighttpd, return early + if [[ "${response}" -ne 0 ]]; then + return + fi + # Lighttpd is not needed anymore, so disable it # We keep all the configuration files in place, so the user can re-enable it # if needed From 50645c2924d8eb92f8b0e4a3dec5fdd762ba617f Mon Sep 17 00:00:00 2001 From: Dominik Date: Tue, 24 Dec 2024 02:19:37 +0100 Subject: [PATCH 25/30] Apply suggestions from code review Co-authored-by: Adam Warner Co-authored-by: RD WebDesign Signed-off-by: Dominik --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index fc2b28ef..13606758 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2305,8 +2305,8 @@ disableLighttpd() { if [[ -t 0 ]]; then # The terminal is interactive dialog --no-shadow --keep-tite \ - --title "Pi-hole v6.0 does no longer need lighttpd" \ - --yesno "Pi-hole v6.0 has its own embedded web server so lighttpd is no longer needed *unless* you have custom configurations. In this case, you can opt-out of disabling lighttpd and pihole-FTL will try to bind to an alternative port such as 8080.\\n\\nDo you want to disable lighttpd (recommended)?" "${r}" "${c}" + --title "Pi-hole v6.0 no longer uses lighttpd" \ + --yesno "\\n\\nPi-hole v6.0 has its own embedded web server so lighttpd is no longer needed *unless* you have custom configurations.\\n\\nIn this case, you can opt-out of disabling lighttpd and pihole-FTL will try to bind to an alternative port such as 8080.\\n\\nDo you want to disable lighttpd (recommended)?" "${r}" "${c}" response=$? else # The terminal is non-interactive, assume yes. Lighttpd will be stopped From 22b6dc7dae8742de00244d22df72c0f99c281e01 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 29 Dec 2024 12:22:35 +0000 Subject: [PATCH 26/30] Add test scripts for fed 41 for v5 Signed-off-by: Adam Warner --- .github/workflows/test.yml | 1 + test/_fedora_41.Dockerfile | 18 ++++++++++++++++++ test/tox.fedora_41.ini | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/_fedora_41.Dockerfile create mode 100644 test/tox.fedora_41.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ec2b5728..a3d49fc5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -59,6 +59,7 @@ jobs: centos_9, fedora_39, fedora_40, + fedora_41, ] env: DISTRO: ${{matrix.distro}} diff --git a/test/_fedora_41.Dockerfile b/test/_fedora_41.Dockerfile new file mode 100644 index 00000000..5297e2a8 --- /dev/null +++ b/test/_fedora_41.Dockerfile @@ -0,0 +1,18 @@ +FROM fedora:41 +RUN dnf install -y git initscripts + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV SKIP_INSTALL true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.fedora_41.ini b/test/tox.fedora_41.ini new file mode 100644 index 00000000..2b95a670 --- /dev/null +++ b/test/tox.fedora_41.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py3 + +[testenv] +allowlist_externals = docker +deps = -rrequirements.txt +commands = docker buildx build --load --progress plain -f _fedora_41.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py From d972ffa53afd9d0603b33d76aa165fd8d6963678 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 29 Dec 2024 12:35:32 +0000 Subject: [PATCH 27/30] while v6 is still not released, update tests in master to NOT use development branch of FTL Signed-off-by: Adam Warner --- test/test_any_automated_install.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index c1b91664..a5038d3c 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -179,7 +179,7 @@ def test_installPihole_fresh_install_readableFiles(host): # Install FTL's development branch to get the latest features host.run( """ - echo "development" > /etc/pihole/ftlbranch + echo "master" > /etc/pihole/ftlbranch """ ) install = host.run( @@ -440,7 +440,7 @@ def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): # Install FTL's development branch to get the latest features host.run( """ - echo "development" > /etc/pihole/ftlbranch + echo "master" > /etc/pihole/ftlbranch """ ) installWeb = host.run( @@ -893,7 +893,7 @@ def test_FTL_binary_installed_and_responsive_no_errors(host): source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) - echo "development" > /etc/pihole/ftlbranch + echo "master" > /etc/pihole/ftlbranch binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" From dff0c0105d8228fa6ce1c7648d76f853659f7a0d Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 29 Dec 2024 12:43:08 +0000 Subject: [PATCH 28/30] remove EOL OS from test suite Signed-off-by: Adam Warner --- .github/workflows/test.yml | 3 --- test/_debian_10.Dockerfile | 17 ----------------- test/_fedora_39.Dockerfile | 18 ------------------ test/_ubuntu_23.Dockerfile | 18 ------------------ test/tox.debian_10.ini | 8 -------- test/tox.fedora_39.ini | 8 -------- test/tox.ubuntu_23.ini | 8 -------- 7 files changed, 80 deletions(-) delete mode 100644 test/_debian_10.Dockerfile delete mode 100644 test/_fedora_39.Dockerfile delete mode 100644 test/_ubuntu_23.Dockerfile delete mode 100644 test/tox.debian_10.ini delete mode 100644 test/tox.fedora_39.ini delete mode 100644 test/tox.ubuntu_23.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a3d49fc5..19a89f1b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,15 +49,12 @@ jobs: matrix: distro: [ - debian_10, debian_11, debian_12, ubuntu_20, ubuntu_22, - ubuntu_23, ubuntu_24, centos_9, - fedora_39, fedora_40, fedora_41, ] diff --git a/test/_debian_10.Dockerfile b/test/_debian_10.Dockerfile deleted file mode 100644 index 3b177cc8..00000000 --- a/test/_debian_10.Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM buildpack-deps:buster-scm - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV SKIP_INSTALL true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_fedora_39.Dockerfile b/test/_fedora_39.Dockerfile deleted file mode 100644 index 1727a3aa..00000000 --- a/test/_fedora_39.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM fedora:39 -RUN dnf install -y git initscripts - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV SKIP_INSTALL true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_ubuntu_23.Dockerfile b/test/_ubuntu_23.Dockerfile deleted file mode 100644 index f9b3910b..00000000 --- a/test/_ubuntu_23.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM buildpack-deps:lunar-scm - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR -ENV DEBIAN_FRONTEND=noninteractive - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV SKIP_INSTALL true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.debian_10.ini b/test/tox.debian_10.ini deleted file mode 100644 index f107300f..00000000 --- a/test/tox.debian_10.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py3 - -[testenv:py3] -allowlist_externals = docker -deps = -rrequirements.txt -commands = docker buildx build --load --progress plain -f _debian_10.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.fedora_39.ini b/test/tox.fedora_39.ini deleted file mode 100644 index 7a538371..00000000 --- a/test/tox.fedora_39.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py3 - -[testenv] -allowlist_externals = docker -deps = -rrequirements.txt -commands = docker buildx build --load --progress plain -f _fedora_39.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.ubuntu_23.ini b/test/tox.ubuntu_23.ini deleted file mode 100644 index 767ed9ef..00000000 --- a/test/tox.ubuntu_23.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py3 - -[testenv:py3] -allowlist_externals = docker -deps = -rrequirements.txt -commands = docker buildx build --load --progress plain -f _ubuntu_23.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From a1ccee6694a9648347098d66e19572b0fc0a9cc7 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 29 Dec 2024 13:32:07 +0000 Subject: [PATCH 29/30] use rpm -q to check if packages are already installed, this is due to a change in the behaviour of dnf in Fedora 41 Signed-off-by: Adam Warner --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index daa35a70..6c84369e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1698,7 +1698,7 @@ install_dependent_packages() { for i in "$@"; do # For each package, check if it's already installed (and if so, don't add it to the installArray) printf " %b Checking for %s..." "${INFO}" "${i}" - if "${PKG_MANAGER}" -q list installed "${i}" &> /dev/null; then + if rpm -q "${i}" &> /dev/null; then printf "%b %b Checking for %s\\n" "${OVER}" "${TICK}" "${i}" else printf "%b %b Checking for %s (will be installed)\\n" "${OVER}" "${INFO}" "${i}" From 18358273718b7186d3f417d4b4c32375c75b6ab4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 30 Dec 2024 15:35:41 +0100 Subject: [PATCH 30/30] Ensure Yes to keeping lighttpd doesn't trigger set -e during the upgrade Signed-off-by: DL6ER --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 13606758..85587bb3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2301,13 +2301,13 @@ copy_to_install_log() { } disableLighttpd() { + local response # Detect if the terminal is interactive if [[ -t 0 ]]; then # The terminal is interactive dialog --no-shadow --keep-tite \ --title "Pi-hole v6.0 no longer uses lighttpd" \ - --yesno "\\n\\nPi-hole v6.0 has its own embedded web server so lighttpd is no longer needed *unless* you have custom configurations.\\n\\nIn this case, you can opt-out of disabling lighttpd and pihole-FTL will try to bind to an alternative port such as 8080.\\n\\nDo you want to disable lighttpd (recommended)?" "${r}" "${c}" - response=$? + --yesno "\\n\\nPi-hole v6.0 has its own embedded web server so lighttpd is no longer needed *unless* you have custom configurations.\\n\\nIn this case, you can opt-out of disabling lighttpd and pihole-FTL will try to bind to an alternative port such as 8080.\\n\\nDo you want to disable lighttpd (recommended)?" "${r}" "${c}" && response=0 || response="$?" else # The terminal is non-interactive, assume yes. Lighttpd will be stopped # but keeps being installed and can easily be re-enabled by the user