command_dev_detect_ldd.sh 1.5 KB

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