command_dev_detect_ldd.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. local commandname="DETECT-LDD"
  8. local commandaction="Detect-LDD"
  9. function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. echo "================================="
  11. echo "Shared Object dependencies Checker"
  12. echo "================================="
  13. if [ -z "${serverfiles}" ]; then
  14. dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
  15. fi
  16. if [ -d "${serverfiles}" ]; then
  17. echo "Checking directory: "
  18. echo "${serverfiles}"
  19. elif [ -f "${serverfiles}" ]; then
  20. echo "Checking file: "
  21. echo "${serverfiles}"
  22. fi
  23. echo ""
  24. files=$(find "${serverfiles}" | wc -l)
  25. find "${serverfiles}" -type f -print0 |
  26. while IFS= read -r -d $'\0' line; do
  27. if ldd "${line}" 2>/dev/null | grep -v "not a dynamic executable"
  28. then
  29. echo "${line}" >> "${tmpdir}/detect_ldd.tmp"
  30. ldd "${line}" 2>/dev/null | grep -v "not a dynamic executable" >> "${tmpdir}/detect_ldd.tmp"
  31. if ldd "${line}" 2>/dev/null | grep -v "not a dynamic executable" | grep "not found"
  32. then
  33. echo "${line}" >> "${tmpdir}/detect_ldd_not_found.tmp"
  34. ldd "${line}" 2>/dev/null | grep -v "not a dynamic executable" | grep "not found" >> "${tmpdir}/detect_ldd_not_found.tmp"
  35. fi
  36. fi
  37. echo -n "$i / $files" $'\r'
  38. ((i++))
  39. done
  40. echo ""
  41. echo ""
  42. echo "All"
  43. echo "================================="
  44. cat "${tmpdir}/detect_ldd.tmp"
  45. echo ""
  46. echo "Not Found"
  47. echo "================================="
  48. cat "${tmpdir}/detect_ldd_not_found.tmp"
  49. rm "${tmpdir}/detect_ldd.tmp"
  50. rm "${tmpdir}/detect_ldd_not_found.tmp"
  51. core_exit.sh