command_dev_detect_ldd.sh 1.8 KB

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