command_dev_detect_ldd.sh 1.8 KB

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