command_dev_detect_deps.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. echo "${lib}"
  35. 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
  36. echo "glibc.i686" >> "${tmpdir}/.depdetect_centos_list"
  37. echo "lib32gcc1" >> "${tmpdir}/.depdetect_ubuntu_list"
  38. echo "lib32gcc1" >> "${tmpdir}/.depdetect_debian_list"
  39. elif [ "${lib}" == "libstdc++.so.6" ]; then
  40. echo "libstdc++.i686" >> "${tmpdir}/.depdetect_centos_list"
  41. echo "libstdc++6:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  42. echo "libstdc++6:i386" >> "${tmpdir}/.depdetect_debian_list"
  43. elif [ "${lib}" == "libstdc++.so.5" ]; then
  44. echo "compat-libstdc++-33.i686" >> "${tmpdir}/.depdetect_centos_list"
  45. echo "libstdc++5:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  46. echo "libstdc++5:i386" >> "${tmpdir}/.depdetect_debian_list"
  47. elif [ "${lib}" == "libcurl-gnutls.so.4" ]; then
  48. echo "libcurl.i686" >> "${tmpdir}/.depdetect_centos_list"
  49. echo "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  50. echo "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_debian_list"
  51. elif [ "${lib}" == "libspeex.so.1" ]||[ "${lib}" == "libspeexdsp.so.1" ]; then
  52. echo "speex.i686" >> "${tmpdir}/.depdetect_centos_list"
  53. echo "speex:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  54. echo "speex:i386" >> "${tmpdir}/.depdetect_debian_list"
  55. elif [ "${lib}" == "./libSDL-1.2.so.0" ]||[ "${lib}" == "libSDL-1.2.so.0" ]; then
  56. echo "SDL.i686" >> "${tmpdir}/.depdetect_centos_list"
  57. echo "libsdl1.2debian" >> "${tmpdir}/.depdetect_ubuntu_list"
  58. echo "libsdl1.2debian" >> "${tmpdir}/.depdetect_debian_list"
  59. elif [ "${lib}" == "libtbb.so.2" ]; then
  60. echo "tbb.i686" >> "${tmpdir}/.depdetect_centos_list"
  61. echo "libtbb2" >> "${tmpdir}/.depdetect_ubuntu_list"
  62. echo "libtbb2" >> "${tmpdir}/.depdetect_debian_list"
  63. elif [ "${lib}" == "libawt.so" ]||[ "${lib}" == "libjava.so" ]||[ "${lib}" == "libjli.so" ]||[ "${lib}" == "libjvm.so" ]||[ "${lib}" == "libnet.so" ]||[ "${lib}" == "libnio.so" ]||[ "${lib}" == "libverify.so" ]; then
  64. echo "java-1.8.0-openjdk" >> "${tmpdir}/.depdetect_centos_list"
  65. echo "default-jre" >> "${tmpdir}/.depdetect_ubuntu_list"
  66. echo "default-jre" >> "${tmpdir}/.depdetect_debian_list"
  67. elif [ "${lib}" == "libXrandr.so.2" ]; then
  68. echo "libXrandr" >> "${tmpdir}/.depdetect_centos_list"
  69. echo "libxrandr2" >> "${tmpdir}/.depdetect_ubuntu_list"
  70. echo "libxrandr2" >> "${tmpdir}/.depdetect_debian_list"
  71. elif [ "${lib}" == "libXext.so.6" ]; then
  72. echo "libXext" >> "${tmpdir}/.depdetect_centos_list"
  73. echo "libxext6" >> "${tmpdir}/.depdetect_ubuntu_list"
  74. echo "libxext6" >> "${tmpdir}/.depdetect_debian_list"
  75. elif [ "${lib}" == "libXtst.so.6" ]; then
  76. echo "libXtst" >> "${tmpdir}/.depdetect_centos_list"
  77. echo "libxtst6" >> "${tmpdir}/.depdetect_ubuntu_list"
  78. echo "libxtst6" >> "${tmpdir}/.depdetect_debian_list"
  79. 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
  80. # Known shared libs what dont requires dependencies
  81. :
  82. else
  83. unknownlib=1
  84. echo "${lib}" >> "${tmpdir}/.depdetect_unknown"
  85. fi
  86. done < "${tmpdir}/.depdetect_readelf_uniq"
  87. sort "${tmpdir}/.depdetect_centos_list" | uniq >> "${tmpdir}/.depdetect_centos_list_uniq"
  88. sort "${tmpdir}/.depdetect_ubuntu_list" | uniq >> "${tmpdir}/.depdetect_ubuntu_list_uniq"
  89. sort "${tmpdir}/.depdetect_debian_list" | uniq >> "${tmpdir}/.depdetect_debian_list_uniq"
  90. if [ "${unknownlib}" == "1" ]; then
  91. sort "${tmpdir}/.depdetect_unknown" | uniq >> "${tmpdir}/.depdetect_unknown_uniq"
  92. fi
  93. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_centos_list_uniq" > "${tmpdir}/.depdetect_centos_line"
  94. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_ubuntu_list_uniq" > "${tmpdir}/.depdetect_ubuntu_line"
  95. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_debian_list_uniq" > "${tmpdir}/.depdetect_debian_line"
  96. echo ""
  97. echo ""
  98. echo "Required Dependencies"
  99. echo "================================="
  100. echo "${executable}"
  101. echo ""
  102. echo "CentOS"
  103. echo "================================="
  104. cat "${tmpdir}/.depdetect_centos_line"
  105. echo ""
  106. echo ""
  107. echo "Ubuntu"
  108. echo "================================="
  109. cat "${tmpdir}/.depdetect_ubuntu_line"
  110. echo ""
  111. echo ""
  112. echo "Debian"
  113. echo "================================="
  114. cat "${tmpdir}/.depdetect_debian_line"
  115. echo ""
  116. if [ "${unknownlib}" == "1" ]; then
  117. echo ""
  118. echo "Unknown shared Library"
  119. echo "================================="
  120. cat "${tmpdir}/.depdetect_unknown"
  121. fi
  122. echo ""
  123. echo "Required Librarys"
  124. echo "================================="
  125. sort "${tmpdir}/.depdetect_readelf" | uniq
  126. echo -en "\n"
  127. rm -f "${tmpdir}/.depdetect_centos_line"
  128. rm -f "${tmpdir}/.depdetect_centos_list"
  129. rm -f "${tmpdir}/.depdetect_centos_list_uniq"
  130. rm -f "${tmpdir}/.depdetect_debian_line"
  131. rm -f "${tmpdir}/.depdetect_debian_list"
  132. rm -f "${tmpdir}/.depdetect_debian_list_uniq"
  133. rm -f "${tmpdir}/.depdetect_ubuntu_line"
  134. rm -f "${tmpdir}/.depdetect_ubuntu_list"
  135. rm -f "${tmpdir}/.depdetect_ubuntu_list_uniq"
  136. rm -f "${tmpdir}/.depdetect_readelf"
  137. rm -f "${tmpdir}/.depdetect_readelf_uniq"
  138. rm -f "${tmpdir}/.depdetect_unknown"
  139. rm -f "${tmpdir}/.depdetect_unknown_uniq"
  140. core_exit.sh