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 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 8f1fce8f4bcc795bf721da21b242cdd6b7eab364 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 10 Dec 2024 19:01:58 +0000 Subject: [PATCH 6/6] 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