command_dev_detect_deps.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 -e "================================="
  10. echo -e "Dependencies Checker"
  11. echo -e "================================="
  12. echo -e "Checking directory: "
  13. echo -e "${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 -e "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 -e "${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 -e "glibc.i686" >> "${tmpdir}/.depdetect_centos_list"
  40. echo -e "lib32gcc1" >> "${tmpdir}/.depdetect_ubuntu_list"
  41. echo -e "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 -e "java-1.8.0-openjdk" >> "${tmpdir}/.depdetect_centos_list"
  50. echo -e "default-jre" >> "${tmpdir}/.depdetect_ubuntu_list"
  51. echo -e "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 -e "libstdc++.i686" >> "${tmpdir}/.depdetect_centos_list"
  65. echo -e "libstdc++6:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  66. echo -e "libstdc++6:i386" >> "${tmpdir}/.depdetect_debian_list"
  67. libdetected=1
  68. elif [ "${lib}" == "libstdc++.so.5" ]; then
  69. echo -e "compat-libstdc++-33.i686" >> "${tmpdir}/.depdetect_centos_list"
  70. echo -e "libstdc++5:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  71. echo -e "libstdc++5:i386" >> "${tmpdir}/.depdetect_debian_list"
  72. libdetected=1
  73. elif [ "${lib}" == "libcurl-gnutls.so.4" ]; then
  74. echo -e "libcurl.i686" >> "${tmpdir}/.depdetect_centos_list"
  75. echo -e "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  76. echo -e "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_debian_list"
  77. libdetected=1
  78. elif [ "${lib}" == "libspeex.so.1" ]||[ "${lib}" == "libspeexdsp.so.1" ]; then
  79. echo -e "speex.i686" >> "${tmpdir}/.depdetect_centos_list"
  80. echo -e "speex:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  81. echo -e "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 -e "SDL.i686" >> "${tmpdir}/.depdetect_centos_list"
  85. echo -e "libsdl1.2debian" >> "${tmpdir}/.depdetect_ubuntu_list"
  86. echo -e "libsdl1.2debian" >> "${tmpdir}/.depdetect_debian_list"
  87. libdetected=1
  88. elif [ "${lib}" == "libtbb.so.2" ]; then
  89. echo -e "tbb.i686" >> "${tmpdir}/.depdetect_centos_list"
  90. echo -e "libtbb2" >> "${tmpdir}/.depdetect_ubuntu_list"
  91. echo -e "libtbb2" >> "${tmpdir}/.depdetect_debian_list"
  92. libdetected=1
  93. elif [ "${lib}" == "libXrandr.so.2" ]; then
  94. echo -e "libXrandr" >> "${tmpdir}/.depdetect_centos_list"
  95. echo -e "libxrandr2" >> "${tmpdir}/.depdetect_ubuntu_list"
  96. echo -e "libxrandr2" >> "${tmpdir}/.depdetect_debian_list"
  97. libdetected=1
  98. elif [ "${lib}" == "libXext.so.6" ]; then
  99. echo -e "libXext" >> "${tmpdir}/.depdetect_centos_list"
  100. echo -e "libxext6" >> "${tmpdir}/.depdetect_ubuntu_list"
  101. echo -e "libxext6" >> "${tmpdir}/.depdetect_debian_list"
  102. libdetected=1
  103. elif [ "${lib}" == "libXtst.so.6" ]; then
  104. echo -e "libXtst" >> "${tmpdir}/.depdetect_centos_list"
  105. echo -e "libxtst6" >> "${tmpdir}/.depdetect_ubuntu_list"
  106. echo -e "libxtst6" >> "${tmpdir}/.depdetect_debian_list"
  107. libdetected=1
  108. elif [ "${lib}" == "libpulse.so.0" ]; then
  109. echo -e "pulseaudio-libs" >> "${tmpdir}/.depdetect_centos_list"
  110. echo -e "libpulse0" >> "${tmpdir}/.depdetect_ubuntu_list"
  111. echo -e "libpulse0" >> "${tmpdir}/.depdetect_debian_list"
  112. libdetected=1
  113. elif [ "${lib}" == "libopenal.so.1" ]; then
  114. echo -e "" >> "${tmpdir}/.depdetect_centos_list"
  115. echo -e "libopenal1" >> "${tmpdir}/.depdetect_ubuntu_list"
  116. echo -e "libopenal1" >> "${tmpdir}/.depdetect_debian_list"
  117. libdetected=1
  118. elif [ "${lib}" == "libgconf-2.so.4" ]; then
  119. echo -e "GConf2" >> "${tmpdir}/.depdetect_centos_list"
  120. echo -e "libgconf2-4" >> "${tmpdir}/.depdetect_ubuntu_list"
  121. echo -e "libgconf2-4" >> "${tmpdir}/.depdetect_debian_list"
  122. libdetected=1
  123. fi
  124. if [ "${libdetected}" != "1" ]; then
  125. unknownlib=1
  126. echo -e "${lib}" >> "${tmpdir}/.depdetect_unknown"
  127. fi
  128. unset libdetected
  129. done < "${tmpdir}/.depdetect_readelf_uniq"
  130. sort "${tmpdir}/.depdetect_centos_list" | uniq >> "${tmpdir}/.depdetect_centos_list_uniq"
  131. sort "${tmpdir}/.depdetect_ubuntu_list" | uniq >> "${tmpdir}/.depdetect_ubuntu_list_uniq"
  132. sort "${tmpdir}/.depdetect_debian_list" | uniq >> "${tmpdir}/.depdetect_debian_list_uniq"
  133. if [ "${unknownlib}" == "1" ]; then
  134. sort "${tmpdir}/.depdetect_unknown" | uniq >> "${tmpdir}/.depdetect_unknown_uniq"
  135. fi
  136. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_centos_list_uniq" > "${tmpdir}/.depdetect_centos_line"
  137. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_ubuntu_list_uniq" > "${tmpdir}/.depdetect_ubuntu_line"
  138. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_debian_list_uniq" > "${tmpdir}/.depdetect_debian_line"
  139. echo -e ""
  140. echo -e ""
  141. echo -e "Required Dependencies"
  142. echo -e "================================="
  143. echo -e "${executable}"
  144. echo -e ""
  145. echo -e "CentOS"
  146. echo -e "================================="
  147. cat "${tmpdir}/.depdetect_centos_line"
  148. echo -e ""
  149. echo -e ""
  150. echo -e "Ubuntu"
  151. echo -e "================================="
  152. cat "${tmpdir}/.depdetect_ubuntu_line"
  153. echo -e ""
  154. echo -e ""
  155. echo -e "Debian"
  156. echo -e "================================="
  157. cat "${tmpdir}/.depdetect_debian_line"
  158. echo -e ""
  159. if [ "${unknownlib}" == "1" ]; then
  160. echo -e ""
  161. echo -e "Unknown shared Library"
  162. echo -e "================================="
  163. cat "${tmpdir}/.depdetect_unknown"
  164. fi
  165. echo -e ""
  166. echo -e "Required Librarys"
  167. echo -e "================================="
  168. sort "${tmpdir}/.depdetect_readelf" | uniq
  169. echo -en "\n"
  170. rm -f "${tmpdir}/.depdetect_centos_line"
  171. rm -f "${tmpdir}/.depdetect_centos_list"
  172. rm -f "${tmpdir}/.depdetect_centos_list_uniq"
  173. rm -f "${tmpdir}/.depdetect_debian_line"
  174. rm -f "${tmpdir}/.depdetect_debian_list"
  175. rm -f "${tmpdir}/.depdetect_debian_list_uniq"
  176. rm -f "${tmpdir}/.depdetect_ubuntu_line"
  177. rm -f "${tmpdir}/.depdetect_ubuntu_list"
  178. rm -f "${tmpdir}/.depdetect_ubuntu_list_uniq"
  179. rm -f "${tmpdir}/.depdetect_readelf"
  180. rm -f "${tmpdir}/.depdetect_readelf_uniq"
  181. rm -f "${tmpdir}/.depdetect_unknown"
  182. rm -f "${tmpdir}/.depdetect_unknown_uniq"
  183. core_exit.sh