command_dev_detect_glibc.sh 3.2 KB

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