command_dev_detect_deps.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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="DETECT-DEPS"
  7. local commandaction="Detect-Deps"
  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}" == "libawt.so" ]||[ "${lib}" == "libjava.so" ]||[ "${lib}" == "libjli.so" ]||[ "${lib}" == "libjvm.so" ]||[ "${lib}" == "libnet.so" ]||[ "${lib}" == "libnio.so" ]||[ "${lib}" == "libverify.so" ]; then
  63. echo "java-1.8.0-openjdk" >> "${tmpdir}/.depdetect_centos_list"
  64. echo "default-jre" >> "${tmpdir}/.depdetect_ubuntu_list"
  65. echo "default-jre" >> "${tmpdir}/.depdetect_debian_list"
  66. 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
  67. # Known shared libs what dont requires dependencies
  68. :
  69. else
  70. unknownlib=1
  71. echo "${lib}" >> "${tmpdir}/.depdetect_unknown"
  72. fi
  73. done < "${tmpdir}/.depdetect_readelf_uniq"
  74. sort "${tmpdir}/.depdetect_centos_list" | uniq >> "${tmpdir}/.depdetect_centos_list_uniq"
  75. sort "${tmpdir}/.depdetect_ubuntu_list" | uniq >> "${tmpdir}/.depdetect_ubuntu_list_uniq"
  76. sort "${tmpdir}/.depdetect_debian_list" | uniq >> "${tmpdir}/.depdetect_debian_list_uniq"
  77. if [ "${unknownlib}" == "1" ]; then
  78. sort "${tmpdir}/.depdetect_unknown" | uniq >> "${tmpdir}/.depdetect_unknown_uniq"
  79. fi
  80. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_centos_list_uniq" > "${tmpdir}/.depdetect_centos_line"
  81. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_ubuntu_list_uniq" > "${tmpdir}/.depdetect_ubuntu_line"
  82. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_debian_list_uniq" > "${tmpdir}/.depdetect_debian_line"
  83. echo ""
  84. echo ""
  85. echo "Required Dependencies"
  86. echo "================================="
  87. echo "${executable}"
  88. echo ""
  89. echo "CentOS"
  90. echo "================================="
  91. cat "${tmpdir}/.depdetect_centos_line"
  92. echo ""
  93. echo ""
  94. echo "Ubuntu"
  95. echo "================================="
  96. cat "${tmpdir}/.depdetect_ubuntu_line"
  97. echo ""
  98. echo ""
  99. echo "Debian"
  100. echo "================================="
  101. cat "${tmpdir}/.depdetect_debian_line"
  102. echo ""
  103. if [ "${unknownlib}" == "1" ]; then
  104. echo ""
  105. echo "Unknown shared Library"
  106. echo "================================="
  107. cat "${tmpdir}/.depdetect_unknown"
  108. fi
  109. echo ""
  110. echo "Required Librarys"
  111. echo "================================="
  112. sort "${tmpdir}/.depdetect_readelf" | uniq
  113. echo -en "\n"
  114. rm -f "${tmpdir}/.depdetect_centos_line"
  115. rm -f "${tmpdir}/.depdetect_centos_list"
  116. rm -f "${tmpdir}/.depdetect_centos_list_uniq"
  117. rm -f "${tmpdir}/.depdetect_debian_line"
  118. rm -f "${tmpdir}/.depdetect_debian_list"
  119. rm -f "${tmpdir}/.depdetect_debian_list_uniq"
  120. rm -f "${tmpdir}/.depdetect_ubuntu_line"
  121. rm -f "${tmpdir}/.depdetect_ubuntu_list"
  122. rm -f "${tmpdir}/.depdetect_ubuntu_list_uniq"
  123. rm -f "${tmpdir}/.depdetect_readelf"
  124. rm -f "${tmpdir}/.depdetect_readelf_uniq"
  125. rm -f "${tmpdir}/.depdetect_unknown"
  126. rm -f "${tmpdir}/.depdetect_unknown_uniq"
  127. core_exit.sh