command_dev_detect_glibc.sh 1.4 KB

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