command_dev_detect_ldd.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. # LinuxGSM command_dev_detect_ldd.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Automatically detects required deps using ldd.
  7. # Can check a file or directory recursively.
  8. commandname="DEV-DETECT-LDD"
  9. commandaction="Shared Object Dependencies Checker"
  10. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  11. fn_firstcommand_set
  12. fn_print_header
  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"; then
  30. echo -e "${line}" >> "${tmpdir}/detect_ldd.tmp"
  31. ldd "${line}" 2> /dev/null | grep -v "not a dynamic executable" >> "${tmpdir}/detect_ldd.tmp"
  32. if ldd "${line}" 2> /dev/null | grep -v "not a dynamic executable" | grep "not found"; then
  33. echo -e "${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 -e ""
  41. echo -e ""
  42. fn_print_nl "${bold}${lightyellow}All${default}"
  43. fn_messages_separator
  44. cat "${tmpdir}/detect_ldd.tmp"
  45. echo -e ""
  46. fn_print_nl "${bold}${lightyellow}Not Found${default}"
  47. fn_messages_separator
  48. cat "${tmpdir}/detect_ldd_not_found.tmp"
  49. rm -f "${tmpdir:?}/detect_ldd.tmp"
  50. rm -f "${tmpdir:?}/detect_ldd_not_found.tmp"
  51. core_exit.sh