command_dev_detect_deps.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. local libs_array=( libm.so.6 libc.so.6 libtcmalloc_minimal.so.4 libpthread.so.0 libdl.so.2 libnsl.so.1 libgcc_s.so.1 librt.so.1 ld-linux.so.2 libdbus-glib-1.so.2 libgio-2.0.so.0 libglib-2.0.so.0 libGL.so.1 libgobject-2.0.so.0 libnm-glib.so.4 libnm-util.so.2 )
  36. for lib_file in "${libs_array[@]}"
  37. do
  38. if [ "${lib}" == "${lib_file}" ]; then
  39. echo "glibc.i686" >> "${tmpdir}/.depdetect_centos_list"
  40. echo "lib32gcc1" >> "${tmpdir}/.depdetect_ubuntu_list"
  41. echo "lib32gcc1" >> "${tmpdir}/.depdetect_debian_list"
  42. libdetected=1
  43. fi
  44. done
  45. local libs_array=( libawt.so libjava.so libjli.so libjvm.so libnet.so libnio.so libverify.so )
  46. for lib_file in "${libs_array[@]}"
  47. do
  48. if [ "${lib}" == "${lib_file}" ]; then
  49. echo "java-1.8.0-openjdk" >> "${tmpdir}/.depdetect_centos_list"
  50. echo "default-jre" >> "${tmpdir}/.depdetect_ubuntu_list"
  51. echo "default-jre" >> "${tmpdir}/.depdetect_debian_list"
  52. libdetected=1
  53. fi
  54. done
  55. local libs_array=( libtier0.so libtier0_srv.so libvstdlib_srv.so Core.so libvstdlib.so libtier0_s.so Editor.so Engine.so liblua.so libsteam_api.so ld-linux-x86-64.so.2 libPhysX3_x86.so libPhysX3Common_x86.so libPhysX3Cooking_x86.so)
  56. for lib_file in "${libs_array[@]}"
  57. do
  58. # Known shared libs what dont requires dependencies
  59. if [ "${lib}" == "${lib_file}" ]; then
  60. libdetected=1
  61. fi
  62. done
  63. if [ "${lib}" == "libstdc++.so.6" ]; then
  64. echo "libstdc++.i686" >> "${tmpdir}/.depdetect_centos_list"
  65. echo "libstdc++6:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  66. echo "libstdc++6:i386" >> "${tmpdir}/.depdetect_debian_list"
  67. libdetected=1
  68. elif [ "${lib}" == "libstdc++.so.5" ]; then
  69. echo "compat-libstdc++-33.i686" >> "${tmpdir}/.depdetect_centos_list"
  70. echo "libstdc++5:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  71. echo "libstdc++5:i386" >> "${tmpdir}/.depdetect_debian_list"
  72. libdetected=1
  73. elif [ "${lib}" == "libcurl-gnutls.so.4" ]; then
  74. echo "libcurl.i686" >> "${tmpdir}/.depdetect_centos_list"
  75. echo "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  76. echo "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_debian_list"
  77. libdetected=1
  78. elif [ "${lib}" == "libspeex.so.1" ]||[ "${lib}" == "libspeexdsp.so.1" ]; then
  79. echo "speex.i686" >> "${tmpdir}/.depdetect_centos_list"
  80. echo "speex:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  81. echo "speex:i386" >> "${tmpdir}/.depdetect_debian_list"
  82. libdetected=1
  83. elif [ "${lib}" == "./libSDL-1.2.so.0" ]||[ "${lib}" == "libSDL-1.2.so.0" ]; then
  84. echo "SDL.i686" >> "${tmpdir}/.depdetect_centos_list"
  85. echo "libsdl1.2debian" >> "${tmpdir}/.depdetect_ubuntu_list"
  86. echo "libsdl1.2debian" >> "${tmpdir}/.depdetect_debian_list"
  87. libdetected=1
  88. elif [ "${lib}" == "libtbb.so.2" ]; then
  89. echo "tbb.i686" >> "${tmpdir}/.depdetect_centos_list"
  90. echo "libtbb2" >> "${tmpdir}/.depdetect_ubuntu_list"
  91. echo "libtbb2" >> "${tmpdir}/.depdetect_debian_list"
  92. libdetected=1
  93. elif [ "${lib}" == "libXrandr.so.2" ]; then
  94. echo "libXrandr" >> "${tmpdir}/.depdetect_centos_list"
  95. echo "libxrandr2" >> "${tmpdir}/.depdetect_ubuntu_list"
  96. echo "libxrandr2" >> "${tmpdir}/.depdetect_debian_list"
  97. libdetected=1
  98. elif [ "${lib}" == "libXext.so.6" ]; then
  99. echo "libXext" >> "${tmpdir}/.depdetect_centos_list"
  100. echo "libxext6" >> "${tmpdir}/.depdetect_ubuntu_list"
  101. echo "libxext6" >> "${tmpdir}/.depdetect_debian_list"
  102. libdetected=1
  103. elif [ "${lib}" == "libXtst.so.6" ]; then
  104. echo "libXtst" >> "${tmpdir}/.depdetect_centos_list"
  105. echo "libxtst6" >> "${tmpdir}/.depdetect_ubuntu_list"
  106. echo "libxtst6" >> "${tmpdir}/.depdetect_debian_list"
  107. libdetected=1
  108. elif [ "${lib}" == "libpulse.so.0" ]; then
  109. echo "pulseaudio-libs" >> "${tmpdir}/.depdetect_centos_list"
  110. echo "libpulse0" >> "${tmpdir}/.depdetect_ubuntu_list"
  111. echo "libpulse0" >> "${tmpdir}/.depdetect_debian_list"
  112. libdetected=1
  113. elif [ "${lib}" == "libopenal.so.1" ]; then
  114. echo "" >> "${tmpdir}/.depdetect_centos_list"
  115. echo "libopenal1" >> "${tmpdir}/.depdetect_ubuntu_list"
  116. echo "libopenal1" >> "${tmpdir}/.depdetect_debian_list"
  117. libdetected=1
  118. fi
  119. if [ "${libdetected}" != "1" ]; then
  120. unknownlib=1
  121. echo "${lib}" >> "${tmpdir}/.depdetect_unknown"
  122. fi
  123. unset libdetected
  124. done < "${tmpdir}/.depdetect_readelf_uniq"
  125. sort "${tmpdir}/.depdetect_centos_list" | uniq >> "${tmpdir}/.depdetect_centos_list_uniq"
  126. sort "${tmpdir}/.depdetect_ubuntu_list" | uniq >> "${tmpdir}/.depdetect_ubuntu_list_uniq"
  127. sort "${tmpdir}/.depdetect_debian_list" | uniq >> "${tmpdir}/.depdetect_debian_list_uniq"
  128. if [ "${unknownlib}" == "1" ]; then
  129. sort "${tmpdir}/.depdetect_unknown" | uniq >> "${tmpdir}/.depdetect_unknown_uniq"
  130. fi
  131. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_centos_list_uniq" > "${tmpdir}/.depdetect_centos_line"
  132. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_ubuntu_list_uniq" > "${tmpdir}/.depdetect_ubuntu_line"
  133. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_debian_list_uniq" > "${tmpdir}/.depdetect_debian_line"
  134. echo ""
  135. echo ""
  136. echo "Required Dependencies"
  137. echo "================================="
  138. echo "${executable}"
  139. echo ""
  140. echo "CentOS"
  141. echo "================================="
  142. cat "${tmpdir}/.depdetect_centos_line"
  143. echo ""
  144. echo ""
  145. echo "Ubuntu"
  146. echo "================================="
  147. cat "${tmpdir}/.depdetect_ubuntu_line"
  148. echo ""
  149. echo ""
  150. echo "Debian"
  151. echo "================================="
  152. cat "${tmpdir}/.depdetect_debian_line"
  153. echo ""
  154. if [ "${unknownlib}" == "1" ]; then
  155. echo ""
  156. echo "Unknown shared Library"
  157. echo "================================="
  158. cat "${tmpdir}/.depdetect_unknown"
  159. fi
  160. echo ""
  161. echo "Required Librarys"
  162. echo "================================="
  163. sort "${tmpdir}/.depdetect_readelf" | uniq
  164. echo -en "\n"
  165. rm -f "${tmpdir}/.depdetect_centos_line"
  166. rm -f "${tmpdir}/.depdetect_centos_list"
  167. rm -f "${tmpdir}/.depdetect_centos_list_uniq"
  168. rm -f "${tmpdir}/.depdetect_debian_line"
  169. rm -f "${tmpdir}/.depdetect_debian_list"
  170. rm -f "${tmpdir}/.depdetect_debian_list_uniq"
  171. rm -f "${tmpdir}/.depdetect_ubuntu_line"
  172. rm -f "${tmpdir}/.depdetect_ubuntu_list"
  173. rm -f "${tmpdir}/.depdetect_ubuntu_list_uniq"
  174. rm -f "${tmpdir}/.depdetect_readelf"
  175. rm -f "${tmpdir}/.depdetect_readelf_uniq"
  176. rm -f "${tmpdir}/.depdetect_unknown"
  177. rm -f "${tmpdir}/.depdetect_unknown_uniq"
  178. core_exit.sh