diff options
author | Michael Boelen <michael.boelen@cisofy.com> | 2018-01-25 21:43:51 +0300 |
---|---|---|
committer | Michael Boelen <michael.boelen@cisofy.com> | 2018-01-25 21:43:51 +0300 |
commit | 7b664a7560401494f33c52069c53b61a8de167f4 (patch) | |
tree | a499cb3a78b3049b694eadd095d7089cfc35677c /include/binaries | |
parent | e4a43e2528a073994435899e6ac818d943e03f80 (diff) |
Reverse PATH search
Diffstat (limited to 'include/binaries')
-rw-r--r-- | include/binaries | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/include/binaries b/include/binaries index a86708f3..f737bb86 100644 --- a/include/binaries +++ b/include/binaries @@ -42,10 +42,19 @@ Display --indent 2 --text "- Checking system binaries..." LogText "Status: Starting binary scan..." - # Test if our PATH variable provides a set of paths (otherwise we use predefined list in include/consts) - if [ ! -z "${PATH}" ]; then BIN_PATHS=$(echo "${BIN_PATHS} ${PATH}" | tr ':' ' '); fi - SORTED_BIN_PATHS=$(echo ${BIN_PATHS} | tr ' ' '\n' | sort | uniq | tr '\n' ' ') - for SCANDIR in ${SORTED_BIN_PATHS}; do + # Test if our PATH variable provides a set of paths + # If so, reverse the order. If we discover the same binary multiple times, the one first in PATH + # should be used. + # If PATH is empty, we use the predefined list in include/consts. Common paths first, then followed + # by more specific paths. This helps on the slightly ancient UNIX derivatives. + if [ ! -z "${PATH}" ]; then + PATH_REVERSED=$(echo ${PATH} | awk -F: '{ for (i=NF; i>1; i--) printf("%s ",$i); print $1; }') + BIN_PATHS=$(echo "${PATH_REVERSED} ${BIN_PATHS}" | tr ':' ' ') + fi + + # Avoid sorting, as this might result in incorrect order of finding binaries (e.g. awk binary) + #SORTED_BIN_PATHS=$(echo ${BIN_PATHS} | tr ' ' '\n' | sort | uniq | tr '\n' ' ') + for SCANDIR in ${BIN_PATHS}; do LogText "Test: Checking binaries in directory ${SCANDIR}" ORGPATH="" if [ -d ${SCANDIR} ]; then @@ -239,7 +248,7 @@ LogText "Result: Directory ${SCANDIR} does NOT exist" fi done - unset SORTED_BIN_PATHS + # unset SORTED_BIN_PATHS BINARY_SCAN_FINISHED=1 BINARY_PATHS_FOUND=$(echo ${BINARY_PATHS_FOUND} | sed 's/^, //g' | sed 's/ //g') LogText "Discovered directories: ${BINARY_PATHS_FOUND}" |