4
0

command_dev_detect_glibc.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. # LinuxGSM command_dev_detect_glibc.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Automatically detects the version of GLIBC that is required.
  6. # Can check a file or directory recursively.
  7. local commandname="DETECT-GLIBC"
  8. local commandaction="Detect-Glibc"
  9. local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. echo "================================="
  11. echo "GLIBC Requirements Checker"
  12. echo "================================="
  13. if [ -z "$(command -v objdump)" ]; then
  14. fn_print_failure_nl "objdump is missing"
  15. fn_script_log_fatal "objdump is missing"
  16. core_exit.sh
  17. fi
  18. if [ -z "${serverfiles}" ]; then
  19. dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
  20. fi
  21. if [ -d "${serverfiles}" ]; then
  22. echo "Checking directory: "
  23. echo "${serverfiles}"
  24. elif [ -f "${serverfiles}" ]; then
  25. echo "Checking file: "
  26. echo "${serverfiles}"
  27. fi
  28. echo ""
  29. files=$(find "${serverfiles}" | wc -l)
  30. find "${serverfiles}" -type f -print0 |
  31. while IFS= read -r -d $'\0' line; do
  32. glibcversion=$(objdump -T "${line}" 2>/dev/null | grep -oP "GLIBC[^ ]+" | grep -v GLIBCXX | sort | uniq | sort -r --version-sort | head -n 1)
  33. if [ "${glibcversion}" ]; then
  34. echo "${glibcversion}: ${line}" >>"${tmpdir}/detect_glibc_files.tmp"
  35. fi
  36. objdump -T "${line}" 2>/dev/null | grep -oP "GLIBC[^ ]+" >>"${tmpdir}/detect_glibc.tmp"
  37. echo -n "${i} / ${files}" $'\r'
  38. ((i++))
  39. done
  40. echo ""
  41. cat "${tmpdir}/detect_glibc_files.tmp"
  42. echo ""
  43. cat "${tmpdir}/detect_glibc.tmp" | sort | uniq | sort -r --version-sort
  44. rm "${tmpdir}/detect_glibc.tmp"
  45. rm "${tmpdir}/detect_glibc_files.tmp"
  46. core_exit.sh