From 2601162243028115768878f3bb0f5ec8fdde8393 Mon Sep 17 00:00:00 2001 From: spmfox Date: Sat, 16 Apr 2022 16:25:33 -0400 Subject: [PATCH 1/4] Changed ldd binary check from /bin/ls to /usr/bin/bash Signed-off-by: spmfox --- automated install/basic-install.sh | 2 +- test/test_any_automated_install.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e1683993..ced6ff2a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2216,7 +2216,7 @@ get_binary_name() { local rev rev=$(uname -m | sed "s/[^0-9]//g;") local lib - lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }') + lib=$(ldd /bin/bash | 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 diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index b7b4ccd8..1e65842b 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -679,7 +679,7 @@ def test_FTL_detect_aarch64_no_errors(host): mock_command( 'ldd', { - '/bin/ls': ( + '/bin/bash': ( '/lib/ld-linux-aarch64.so.1', '0' ) @@ -709,7 +709,7 @@ def test_FTL_detect_armv4t_no_errors(host): # mock uname to return armv4t platform mock_command('uname', {'-m': ('armv4t', '0')}, host) # mock ldd to respond with ld-linux shared library - mock_command('ldd', {'/bin/ls': ('/lib/ld-linux.so.3', '0')}, host) + mock_command('ldd', {'/bin/bash': ('/lib/ld-linux.so.3', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -733,7 +733,7 @@ def test_FTL_detect_armv5te_no_errors(host): # mock uname to return armv5te platform mock_command('uname', {'-m': ('armv5te', '0')}, host) # mock ldd to respond with ld-linux shared library - mock_command('ldd', {'/bin/ls': ('/lib/ld-linux.so.3', '0')}, host) + mock_command('ldd', {'/bin/bash': ('/lib/ld-linux.so.3', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -757,7 +757,7 @@ 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('ldd', {'/bin/ls': ('/lib/ld-linux-armhf.so.3', '0')}, host) + mock_command('ldd', {'/bin/bash': ('/lib/ld-linux-armhf.so.3', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -782,7 +782,7 @@ 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('ldd', {'/bin/ls': ('/lib/ld-linux-armhf.so.3', '0')}, host) + mock_command('ldd', {'/bin/bash': ('/lib/ld-linux-armhf.so.3', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -807,7 +807,7 @@ def test_FTL_detect_armv8a_no_errors(host): # mock uname to return armv8a platform mock_command('uname', {'-m': ('armv8a', '0')}, host) # mock ldd to respond with ld-linux-armhf shared library - mock_command('ldd', {'/bin/ls': ('/lib/ld-linux-armhf.so.3', '0')}, host) + mock_command('ldd', {'/bin/bash': ('/lib/ld-linux-armhf.so.3', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user From 9840148ba95678c7b9316e171fd2a4659a88c1d3 Mon Sep 17 00:00:00 2001 From: spmfox Date: Sun, 17 Apr 2022 14:52:05 -0400 Subject: [PATCH 2/4] Update automated install/basic-install.sh Co-authored-by: Dan Schaper --- 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 ced6ff2a..79b6d1fa 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2216,7 +2216,7 @@ get_binary_name() { local rev rev=$(uname -m | sed "s/[^0-9]//g;") local lib - lib=$(ldd /bin/bash | grep -E '^\s*/lib' | awk '{ print $1 }') + lib=$(ldd $(which 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 71072b4beb0e4356f64e3f24f5524c878d1cb756 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 20 Apr 2022 10:21:24 -0700 Subject: [PATCH 3/4] Stickler quoting --- 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 79b6d1fa..5bf4dedf 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2216,7 +2216,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 "$(which 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 c19788dd18c27b7461402d0753062f0823452616 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 20 Apr 2022 10:35:18 -0700 Subject: [PATCH 4/4] Mock `which sh` to reutrn `/bin/sh`. Check for `/bin/sh` library Signed-off-by: Dan Schaper --- test/test_any_automated_install.py | 39 ++++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 1e65842b..41a939e0 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -675,17 +675,10 @@ 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 ldd to respond with aarch64 shared library - mock_command( - 'ldd', - { - '/bin/bash': ( - '/lib/ld-linux-aarch64.so.1', - '0' - ) - }, - host - ) + mock_command('ldd', {'/bin/sh': ('/lib/ld-linux-aarch64.so.1', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -708,8 +701,10 @@ def test_FTL_detect_armv4t_no_errors(host): ''' # mock uname to return armv4t platform mock_command('uname', {'-m': ('armv4t', '0')}, host) - # mock ldd to respond with ld-linux shared library - mock_command('ldd', {'/bin/bash': ('/lib/ld-linux.so.3', '0')}, host) + # mock `which sh` to return `/bin/sh` + mock_command('which', {'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(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -732,8 +727,10 @@ 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 ldd to respond with ld-linux shared library - mock_command('ldd', {'/bin/bash': ('/lib/ld-linux.so.3', '0')}, host) + mock_command('ldd', {'/bin/sh': ('/lib/ld-linux.so.3', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -757,7 +754,9 @@ 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('ldd', {'/bin/bash': ('/lib/ld-linux-armhf.so.3', '0')}, host) + # mock `which sh` to return `/bin/sh` + mock_command('which', {'sh': ('/bin/sh', '0')}, host) + mock_command('ldd', {'/bin/sh': ('/lib/ld-linux-armhf.so.3', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -782,7 +781,9 @@ 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('ldd', {'/bin/bash': ('/lib/ld-linux-armhf.so.3', '0')}, host) + # mock `which sh` to return `/bin/sh` + mock_command('which', {'sh': ('/bin/sh', '0')}, host) + mock_command('ldd', {'/bin/sh': ('/lib/ld-linux-armhf.so.3', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -806,8 +807,10 @@ 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 ldd to respond with ld-linux-armhf shared library - mock_command('ldd', {'/bin/bash': ('/lib/ld-linux-armhf.so.3', '0')}, host) + mock_command('ldd', {'/bin/sh': ('/lib/ld-linux-armhf.so.3', '0')}, host) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -828,6 +831,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) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user @@ -848,6 +853,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) detectPlatform = host.run(''' source /opt/pihole/basic-install.sh create_pihole_user