command_dev_detect_deps.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. # LinuxGSM command_dev_detect_deps.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Detects dependencies the server binary requires.
  6. local commandname="DEPS-DETECT"
  7. local commandaction="Deps-Detect"
  8. local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  9. echo "================================="
  10. echo "Dependencies Checker"
  11. echo "================================="
  12. echo "Checking directory: "
  13. echo "${serverfiles}"
  14. if [ "$(command -v eu-readelf 2>/dev/null)" ]; then
  15. readelf=eu-readelf
  16. elif [ "$(command -v readelf 2>/dev/null)" ]; then
  17. readelf=readelf
  18. else
  19. echo "readelf/eu-readelf not installed"
  20. fi
  21. files=$(find "${serverfiles}" | wc -l)
  22. find "${serverfiles}" -type f -print0 |
  23. while IFS= read -r -d $'\0' line; do
  24. if [ "${readelf}" == "eu-readelf" ]; then
  25. ${readelf} -d "${line}" 2>/dev/null | grep NEEDED| awk '{ print $4 }' | sed 's/\[//g;s/\]//g' >> "${tmpdir}/.depdetect_readelf"
  26. else
  27. ${readelf} -d "${line}" 2>/dev/null | grep NEEDED | awk '{ print $5 }' | sed 's/\[//g;s/\]//g' >> "${tmpdir}/.depdetect_readelf"
  28. fi
  29. echo -n "${i} / ${files}" $'\r'
  30. ((i++))
  31. done
  32. sort "${tmpdir}/.depdetect_readelf" |uniq >"${tmpdir}/.depdetect_readelf_uniq"
  33. while read -r lib; do
  34. if [ "${lib}" == "libm.so.6" ]||[ "${lib}" == "libc.so.6" ]||[ "${lib}" == "libtcmalloc_minimal.so.4" ]||[ "${lib}" == "libpthread.so.0" ]||[ "${lib}" == "libdl.so.2" ]||[ "${lib}" == "libnsl.so.1" ]||[ "${lib}" == "libgcc_s.so.1" ]||[ "${lib}" == "librt.so.1" ]||[ "${lib}" == "ld-linux.so.2" ]; then
  35. echo "glibc.i686" >> "${tmpdir}/.depdetect_centos_list"
  36. echo "lib32gcc1" >> "${tmpdir}/.depdetect_ubuntu_list"
  37. echo "lib32gcc1" >> "${tmpdir}/.depdetect_debian_list"
  38. elif [ "${lib}" == "libstdc++.so.6" ]; then
  39. echo "libstdc++.i686" >> "${tmpdir}/.depdetect_centos_list"
  40. echo "libstdc++6:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  41. echo "libstdc++6:i386" >> "${tmpdir}/.depdetect_debian_list"
  42. elif [ "${lib}" == "libstdc++.so.5" ]; then
  43. echo "compat-libstdc++-33.i686" >> "${tmpdir}/.depdetect_centos_list"
  44. echo "libstdc++5:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  45. echo "libstdc++5:i386" >> "${tmpdir}/.depdetect_debian_list"
  46. elif [ "${lib}" == "libcurl-gnutls.so.4" ]; then
  47. echo "libcurl.i686" >> "${tmpdir}/.depdetect_centos_list"
  48. echo "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  49. echo "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_debian_list"
  50. elif [ "${lib}" == "libspeex.so.1" ]||[ "${lib}" == "libspeexdsp.so.1" ]; then
  51. echo "speex.i686" >> "${tmpdir}/.depdetect_centos_list"
  52. echo "speex:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  53. echo "speex:i386" >> "${tmpdir}/.depdetect_debian_list"
  54. elif [ "${lib}" == "./libSDL-1.2.so.0" ]||[ "${lib}" == "libSDL-1.2.so.0" ]; then
  55. echo "SDL.i686" >> "${tmpdir}/.depdetect_centos_list"
  56. echo "libsdl1.2debian" >> "${tmpdir}/.depdetect_ubuntu_list"
  57. echo "libsdl1.2debian" >> "${tmpdir}/.depdetect_debian_list"
  58. elif [ "${lib}" == "libtbb.so.2" ]; then
  59. echo "tbb.i686" >> "${tmpdir}/.depdetect_centos_list"
  60. echo "libtbb2" >> "${tmpdir}/.depdetect_ubuntu_list"
  61. echo "libtbb2" >> "${tmpdir}/.depdetect_debian_list"
  62. elif [ "${lib}" == "libtier0.so" ]||[ "${lib}" == "libtier0_srv.so" ]||[ "${lib}" == "libvstdlib_srv.so" ]||[ "${lib}" == "Core.so" ]||[ "${lib}" == "libvstdlib.so" ]||[ "${lib}" == "libtier0_s.so" ]||[ "${lib}" == "Editor.so" ]||[ "${lib}" == "Engine.so" ]||[ "${lib}" == "liblua.so" ]||[ "${lib}" == "libsteam_api.so" ]||[ "${lib}" == "ld-linux-x86-64.so.2" ]||[ "${lib}" == "libPhysX3_x86.so" ]||[ "${lib}" == "libPhysX3Common_x86.so" ]||[ "${lib}" == "libPhysX3Cooking_x86.so" ]; then
  63. # Known shared libs what dont requires dependencies
  64. :
  65. else
  66. unknownlib=1
  67. echo "${lib}" >> "${tmpdir}/.depdetect_unknown"
  68. fi
  69. done < "${tmpdir}/.depdetect_readelf_uniq"
  70. sort "${tmpdir}/.depdetect_centos_list" | uniq >> "${tmpdir}/.depdetect_centos_list_uniq"
  71. sort "${tmpdir}/.depdetect_ubuntu_list" | uniq >> "${tmpdir}/.depdetect_ubuntu_list_uniq"
  72. sort "${tmpdir}/.depdetect_debian_list" | uniq >> "${tmpdir}/.depdetect_debian_list_uniq"
  73. if [ "${unknownlib}" == "1" ]; then
  74. sort "${tmpdir}/.depdetect_unknown" | uniq >> "${tmpdir}/.depdetect_unknown_uniq"
  75. fi
  76. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_centos_list_uniq" > "${tmpdir}/.depdetect_centos_line"
  77. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_ubuntu_list_uniq" > "${tmpdir}/.depdetect_ubuntu_line"
  78. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_debian_list_uniq" > "${tmpdir}/.depdetect_debian_line"
  79. echo ""
  80. echo ""
  81. echo "Required Dependencies"
  82. echo "================================="
  83. echo "${executable}"
  84. echo ""
  85. echo "CentOS"
  86. echo "================================="
  87. cat "${tmpdir}/.depdetect_centos_line"
  88. echo ""
  89. echo ""
  90. echo "Ubuntu"
  91. echo "================================="
  92. cat "${tmpdir}/.depdetect_ubuntu_line"
  93. echo ""
  94. echo ""
  95. echo "Debian"
  96. echo "================================="
  97. cat "${tmpdir}/.depdetect_debian_line"
  98. echo ""
  99. if [ "${unknownlib}" == "1" ]; then
  100. echo ""
  101. echo "Unknown shared Library"
  102. echo "================================="
  103. cat "${tmpdir}/.depdetect_unknown"
  104. fi
  105. echo ""
  106. echo "Required Librarys"
  107. echo "================================="
  108. sort "${tmpdir}/.depdetect_readelf" | uniq
  109. echo -en "\n"
  110. rm -f "${tmpdir}/.depdetect_centos_line"
  111. rm -f "${tmpdir}/.depdetect_centos_list"
  112. rm -f "${tmpdir}/.depdetect_centos_list_uniq"
  113. rm -f "${tmpdir}/.depdetect_debian_line"
  114. rm -f "${tmpdir}/.depdetect_debian_list"
  115. rm -f "${tmpdir}/.depdetect_debian_list_uniq"
  116. rm -f "${tmpdir}/.depdetect_ubuntu_line"
  117. rm -f "${tmpdir}/.depdetect_ubuntu_list"
  118. rm -f "${tmpdir}/.depdetect_ubuntu_list_uniq"
  119. rm -f "${tmpdir}/.depdetect_readelf"
  120. rm -f "${tmpdir}/.depdetect_readelf_uniq"
  121. rm -f "${tmpdir}/.depdetect_unknown"
  122. rm -f "${tmpdir}/.depdetect_unknown_uniq"
  123. core_exit.sh