command_dev_detect_glibc.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. commandname="DEV-DETECT-GLIBC"
  8. commandaction="Developer detect glibc"
  9. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. echo -e "================================="
  11. echo -e "glibc Requirements Checker"
  12. echo -e "================================="
  13. if [ ! "$(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 -e "Checking directory: "
  23. echo -e "${serverfiles}"
  24. elif [ -f "${serverfiles}" ]; then
  25. echo -e "Checking file: "
  26. echo -e "${serverfiles}"
  27. fi
  28. echo -e ""
  29. glibc_check_dir_array=( steamcmddir serverfiles )
  30. for glibc_check_var in "${glibc_check_dir_array[@]}"
  31. do
  32. if [ "${glibc_check_var}" == "serverfiles" ]; then
  33. glibc_check_dir="${serverfiles}"
  34. glibc_check_name="${gamename}"
  35. elif [ "${glibc_check_var}" == "steamcmddir" ]; then
  36. glibc_check_dir="${steamcmddir}"
  37. glibc_check_name="SteamCMD"
  38. fi
  39. if [ -d "${glibc_check_dir}" ]; then
  40. glibc_check_files=$(find "${glibc_check_dir}" | wc -l)
  41. find "${glibc_check_dir}" -type f -print0 |
  42. while IFS= read -r -d $'\0' line; do
  43. glibcversion=$(objdump -T "${line}" 2>/dev/null | grep -oP "GLIBC[^ ]+" | grep -v GLIBCXX | sort | uniq | sort -r --version-sort | head -n 1)
  44. if [ "${glibcversion}" ]; then
  45. echo -e "${glibcversion}: ${line}" >>"${tmpdir}/detect_glibc_files_${glibc_check_var}.tmp"
  46. fi
  47. objdump -T "${line}" 2>/dev/null | grep -oP "GLIBC[^ ]+" >>"${tmpdir}/detect_glibc_${glibc_check_var}.tmp"
  48. echo -n "${i} / ${glibc_check_files}" $'\r'
  49. ((i++))
  50. done
  51. echo -e ""
  52. echo -e ""
  53. echo -e "${glibc_check_name} glibc Requirements"
  54. echo -e "================================="
  55. if [ -f "${tmpdir}/detect_glibc_files_${glibc_check_var}.tmp" ]; then
  56. echo -e "Required glibc"
  57. cat "${tmpdir}/detect_glibc_${glibc_check_var}.tmp" | sort | uniq | sort -r --version-sort | head -1 |tee -a "${tmpdir}/detect_glibc_highest.tmp"
  58. echo -e ""
  59. echo -e "Files requiring GLIBC"
  60. echo -e "Highest verion required: filename"
  61. cat "${tmpdir}/detect_glibc_files_${glibc_check_var}.tmp"
  62. echo -e ""
  63. echo -e "All required GLIBC versions"
  64. cat "${tmpdir}/detect_glibc_${glibc_check_var}.tmp" | sort | uniq | sort -r --version-sort
  65. rm -f "${tmpdir:?}/detect_glibc_${glibc_check_var}.tmp"
  66. rm -f "${tmpdir:?}/detect_glibc_files_${glibc_check_var}.tmp"
  67. else
  68. fn_print_information_nl "glibc is not required"
  69. fi
  70. else
  71. fn_print_information_nl "${glibc_check_name} is not installed"
  72. fi
  73. done
  74. echo -e ""
  75. echo -e "Final glibc Requirement"
  76. echo -e "================================="
  77. if [ -f "${tmpdir}/detect_glibc_highest.tmp" ]; then
  78. cat "${tmpdir}/detect_glibc_highest.tmp" | sort | uniq | sort -r --version-sort | head -1
  79. rm -f "${tmpdir:?}/detect_glibc_highest.tmp"
  80. else
  81. fn_print_information_nl "glibc is not required"
  82. fi
  83. core_exit.sh