From 9c51050283cc357543cc26df82a6596f5dc3dfdf Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Tue, 13 Sep 2022 00:58:10 +0000 Subject: [PATCH 1/4] basic-install.sh: Use `grep -E` instead of `egrep` Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com> --- 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 d4c1ce77..99fac2cf 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -358,7 +358,7 @@ package_manager_detect() { # 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) # 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 | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" + PKG_COUNT="${PKG_MANAGER} check-update | grep -E '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" OS_CHECK_DEPS=(grep bind-utils) INSTALLER_DEPS=(git dialog iproute newt procps-ng which chkconfig ca-certificates) PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat jq) From e3db5fc601fe2536b818032cb4d3cbc59760200d Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Tue, 13 Sep 2022 00:20:01 +0000 Subject: [PATCH 2/4] basic-install.sh: Use `command -v` instead of `which` `command -v` is the standardized version of `which` and doesn't require any extra packages Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com> --- 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 99fac2cf..a29f3bd1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2267,7 +2267,7 @@ get_binary_name() { local rev rev=$(uname -m | sed "s/[^0-9]//g;") local lib - lib=$(ldd "$(which sh)" | grep -E '^\s*/lib' | awk '{ print $1 }') + lib=$(ldd "$(command -v sh)" | grep -E '^\s*/lib' | awk '{ print $1 }') if [[ "${lib}" == "/lib/ld-linux-aarch64.so.1" ]]; then printf "%b %b Detected AArch64 (64 Bit ARM) processor\\n" "${OVER}" "${TICK}" # set the binary to be used From e5695f862f52de00723ea87a875c9a2de2ce9971 Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Tue, 11 Oct 2022 14:35:11 +0000 Subject: [PATCH 3/4] test_any_automated_install.py: Use `command -v` instead of `which` Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com> --- test/test_any_automated_install.py | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 0fd80f7e..56c492da 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -619,8 +619,8 @@ def test_FTL_detect_aarch64_no_errors(host): """ # mock uname to return aarch64 platform mock_command("uname", {"-m": ("aarch64", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with aarch64 shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0")}, host) detectPlatform = host.run( @@ -647,8 +647,8 @@ def test_FTL_detect_armv4t_no_errors(host): """ # mock uname to return armv4t platform mock_command("uname", {"-m": ("armv4t", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with armv4t shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) detectPlatform = host.run( @@ -675,8 +675,8 @@ def test_FTL_detect_armv5te_no_errors(host): """ # mock uname to return armv5te platform mock_command("uname", {"-m": ("armv5te", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) detectPlatform = host.run( @@ -704,8 +704,8 @@ def test_FTL_detect_armv6l_no_errors(host): # mock uname to return armv6l platform mock_command("uname", {"-m": ("armv6l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) detectPlatform = host.run( """ @@ -734,8 +734,8 @@ def test_FTL_detect_armv7l_no_errors(host): # mock uname to return armv7l platform mock_command("uname", {"-m": ("armv7l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) detectPlatform = host.run( """ @@ -763,8 +763,8 @@ def test_FTL_detect_armv8a_no_errors(host): """ # mock uname to return armv8a platform mock_command("uname", {"-m": ("armv8a", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) detectPlatform = host.run( @@ -789,8 +789,8 @@ def test_FTL_detect_x86_64_no_errors(host): """ confirms only x86_64 package is downloaded for FTL engine """ - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -813,8 +813,8 @@ def test_FTL_detect_unknown_no_errors(host): """confirms only generic package is downloaded for FTL engine""" # mock uname to return generic platform mock_command("uname", {"-m": ("mips", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh From 5c090d25e1df555a8723347916fd305f5c0f6a6c Mon Sep 17 00:00:00 2001 From: MichaIng Date: Tue, 11 Oct 2022 22:18:31 +0200 Subject: [PATCH 4/4] Fix ldd sh mock in tests Since "command" is a shell internal, it cannot be mocked, done via /usr/local/bin override. Since Debian containers ship without /bin => /usr/bin symlink, while all other containers do, the "ldd" mock needs to be applied for both paths, then. Signed-off-by: MichaIng --- test/test_any_automated_install.py | 70 ++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 56c492da..e6673bb5 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -619,10 +619,15 @@ def test_FTL_detect_aarch64_no_errors(host): """ # mock uname to return aarch64 platform mock_command("uname", {"-m": ("aarch64", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with aarch64 shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0"), + "/usr/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -647,10 +652,15 @@ def test_FTL_detect_armv4t_no_errors(host): """ # mock uname to return armv4t platform mock_command("uname", {"-m": ("armv4t", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with armv4t shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -675,10 +685,15 @@ def test_FTL_detect_armv5te_no_errors(host): """ # mock uname to return armv5te platform mock_command("uname", {"-m": ("armv5te", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -704,9 +719,14 @@ def test_FTL_detect_armv6l_no_errors(host): # mock uname to return armv6l platform mock_command("uname", {"-m": ("armv6l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -734,9 +754,14 @@ def test_FTL_detect_armv7l_no_errors(host): # mock uname to return armv7l platform mock_command("uname", {"-m": ("armv7l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -763,10 +788,15 @@ def test_FTL_detect_armv8a_no_errors(host): """ # mock uname to return armv8a platform mock_command("uname", {"-m": ("armv8a", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -789,8 +819,6 @@ def test_FTL_detect_x86_64_no_errors(host): """ confirms only x86_64 package is downloaded for FTL engine """ - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -813,8 +841,6 @@ def test_FTL_detect_unknown_no_errors(host): """confirms only generic package is downloaded for FTL engine""" # mock uname to return generic platform mock_command("uname", {"-m": ("mips", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh