command_dev_detect_ldd.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. # command_dev_detect_ldd.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Automatically detects required deps using ldd.
  6. # Can check a file or directory recursively.
  7. commandname="DEV-DETECT-LDD"
  8. commandaction="Developer detect ldd"
  9. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. echo -e "================================="
  12. echo -e "Shared Object dependencies Checker"
  13. echo -e "================================="
  14. if [ -z "${serverfiles}" ]; then
  15. dir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
  16. fi
  17. if [ -d "${serverfiles}" ]; then
  18. echo -e "Checking directory: "
  19. echo -e "${serverfiles}"
  20. elif [ -f "${serverfiles}" ]; then
  21. echo -e "Checking file: "
  22. echo -e "${serverfiles}"
  23. fi
  24. echo -e ""
  25. touch "${tmpdir}/detect_ldd.tmp"
  26. touch "${tmpdir}/detect_ldd_not_found.tmp"
  27. files=$(find "${serverfiles}" | wc -l)
  28. find "${serverfiles}" -type f -print0 |
  29. while IFS= read -r -d $'\0' line; do
  30. if ldd "${line}" 2>/dev/null | grep -v "not a dynamic executable"
  31. then
  32. echo -e "${line}" >> "${tmpdir}/detect_ldd.tmp"
  33. ldd "${line}" 2>/dev/null | grep -v "not a dynamic executable" >> "${tmpdir}/detect_ldd.tmp"
  34. if ldd "${line}" 2>/dev/null | grep -v "not a dynamic executable" | grep "not found"
  35. then
  36. echo -e "${line}" >> "${tmpdir}/detect_ldd_not_found.tmp"
  37. ldd "${line}" 2>/dev/null | grep -v "not a dynamic executable" | grep "not found" >> "${tmpdir}/detect_ldd_not_found.tmp"
  38. fi
  39. fi
  40. echo -n "$i / $files" $'\r'
  41. ((i++))
  42. done
  43. echo -e ""
  44. echo -e ""
  45. echo -e "All"
  46. echo -e "================================="
  47. cat "${tmpdir}/detect_ldd.tmp"
  48. echo -e ""
  49. echo -e "Not Found"
  50. echo -e "================================="
  51. cat "${tmpdir}/detect_ldd_not_found.tmp"
  52. rm -f "${tmpdir:?}/detect_ldd.tmp"
  53. rm -f "${tmpdir:?}/detect_ldd_not_found.tmp"
  54. core_exit.sh