4
0

command_dev_detect_deps.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. commandname="DEV-DETECT-DEPS"
  7. commandaction="Developer detect deps"
  8. functionselfname="$(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. touch "${tmpdir}/.depdetect_centos_list"
  34. touch "${tmpdir}/.depdetect_ubuntu_list"
  35. touch "${tmpdir}/.depdetect_debian_list"
  36. while read -r lib; do
  37. echo -e "${lib}"
  38. 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 )
  39. for lib_file in "${libs_array[@]}"
  40. do
  41. if [ "${lib}" == "${lib_file}" ]; then
  42. echo -e "glibc.i686" >> "${tmpdir}/.depdetect_centos_list"
  43. echo -e "lib32gcc1" >> "${tmpdir}/.depdetect_ubuntu_list"
  44. echo -e "lib32gcc1" >> "${tmpdir}/.depdetect_debian_list"
  45. libdetected=1
  46. fi
  47. done
  48. libs_array=( libawt.so libjava.so libjli.so libjvm.so libnet.so libnio.so libverify.so )
  49. for lib_file in "${libs_array[@]}"
  50. do
  51. if [ "${lib}" == "${lib_file}" ]; then
  52. echo -e "java-1.8.0-openjdk" >> "${tmpdir}/.depdetect_centos_list"
  53. echo -e "default-jre" >> "${tmpdir}/.depdetect_ubuntu_list"
  54. echo -e "default-jre" >> "${tmpdir}/.depdetect_debian_list"
  55. libdetected=1
  56. fi
  57. done
  58. 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)
  59. for lib_file in "${libs_array[@]}"
  60. do
  61. # Known shared libs what dont requires dependencies.
  62. if [ "${lib}" == "${lib_file}" ]; then
  63. libdetected=1
  64. fi
  65. done
  66. if [ "${lib}" == "libstdc++.so.6" ]; then
  67. echo -e "libstdc++.i686" >> "${tmpdir}/.depdetect_centos_list"
  68. echo -e "libstdc++6:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  69. echo -e "libstdc++6:i386" >> "${tmpdir}/.depdetect_debian_list"
  70. libdetected=1
  71. elif [ "${lib}" == "libstdc++.so.5" ]; then
  72. echo -e "compat-libstdc++-33.i686" >> "${tmpdir}/.depdetect_centos_list"
  73. echo -e "libstdc++5:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  74. echo -e "libstdc++5:i386" >> "${tmpdir}/.depdetect_debian_list"
  75. libdetected=1
  76. elif [ "${lib}" == "libcurl-gnutls.so.4" ]; then
  77. echo -e "libcurl.i686" >> "${tmpdir}/.depdetect_centos_list"
  78. echo -e "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  79. echo -e "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_debian_list"
  80. libdetected=1
  81. elif [ "${lib}" == "libspeex.so.1" ]||[ "${lib}" == "libspeexdsp.so.1" ]; then
  82. echo -e "speex.i686" >> "${tmpdir}/.depdetect_centos_list"
  83. echo -e "speex:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  84. echo -e "speex:i386" >> "${tmpdir}/.depdetect_debian_list"
  85. libdetected=1
  86. elif [ "${lib}" == "./libSDL-1.2.so.0" ]||[ "${lib}" == "libSDL-1.2.so.0" ]; then
  87. echo -e "SDL.i686" >> "${tmpdir}/.depdetect_centos_list"
  88. echo -e "libsdl1.2debian" >> "${tmpdir}/.depdetect_ubuntu_list"
  89. echo -e "libsdl1.2debian" >> "${tmpdir}/.depdetect_debian_list"
  90. libdetected=1
  91. elif [ "${lib}" == "libtbb.so.2" ]; then
  92. echo -e "tbb.i686" >> "${tmpdir}/.depdetect_centos_list"
  93. echo -e "libtbb2" >> "${tmpdir}/.depdetect_ubuntu_list"
  94. echo -e "libtbb2" >> "${tmpdir}/.depdetect_debian_list"
  95. libdetected=1
  96. elif [ "${lib}" == "libXrandr.so.2" ]; then
  97. echo -e "libXrandr" >> "${tmpdir}/.depdetect_centos_list"
  98. echo -e "libxrandr2" >> "${tmpdir}/.depdetect_ubuntu_list"
  99. echo -e "libxrandr2" >> "${tmpdir}/.depdetect_debian_list"
  100. libdetected=1
  101. elif [ "${lib}" == "libXext.so.6" ]; then
  102. echo -e "libXext" >> "${tmpdir}/.depdetect_centos_list"
  103. echo -e "libxext6" >> "${tmpdir}/.depdetect_ubuntu_list"
  104. echo -e "libxext6" >> "${tmpdir}/.depdetect_debian_list"
  105. libdetected=1
  106. elif [ "${lib}" == "libXtst.so.6" ]; then
  107. echo -e "libXtst" >> "${tmpdir}/.depdetect_centos_list"
  108. echo -e "libxtst6" >> "${tmpdir}/.depdetect_ubuntu_list"
  109. echo -e "libxtst6" >> "${tmpdir}/.depdetect_debian_list"
  110. libdetected=1
  111. elif [ "${lib}" == "libpulse.so.0" ]; then
  112. echo -e "pulseaudio-libs" >> "${tmpdir}/.depdetect_centos_list"
  113. echo -e "libpulse0" >> "${tmpdir}/.depdetect_ubuntu_list"
  114. echo -e "libpulse0" >> "${tmpdir}/.depdetect_debian_list"
  115. libdetected=1
  116. elif [ "${lib}" == "libopenal.so.1" ]; then
  117. echo -e "" >> "${tmpdir}/.depdetect_centos_list"
  118. echo -e "libopenal1" >> "${tmpdir}/.depdetect_ubuntu_list"
  119. echo -e "libopenal1" >> "${tmpdir}/.depdetect_debian_list"
  120. libdetected=1
  121. elif [ "${lib}" == "libgconf-2.so.4" ]; then
  122. echo -e "GConf2" >> "${tmpdir}/.depdetect_centos_list"
  123. echo -e "libgconf2-4" >> "${tmpdir}/.depdetect_ubuntu_list"
  124. echo -e "libgconf2-4" >> "${tmpdir}/.depdetect_debian_list"
  125. libdetected=1
  126. elif [ "${lib}" == "libz.so.1" ]; then
  127. echo -e "zlib" >> "${tmpdir}/.depdetect_centos_list"
  128. echo -e "zlib1g" >> "${tmpdir}/.depdetect_ubuntu_list"
  129. echo -e "zlib1g" >> "${tmpdir}/.depdetect_debian_list"
  130. libdetected=1
  131. elif [ "${lib}" == "libatk-1.0.so.0" ]; then
  132. echo -e "atk" >> "${tmpdir}/.depdetect_centos_list"
  133. echo -e "libatk1.0-0" >> "${tmpdir}/.depdetect_ubuntu_list"
  134. echo -e "libatk1.0-0" >> "${tmpdir}/.depdetect_debian_list"
  135. libdetected=1
  136. elif [ "${lib}" == "libcairo.so.2" ]; then
  137. echo -e "cairo" >> "${tmpdir}/.depdetect_centos_list"
  138. echo -e "libcairo2" >> "${tmpdir}/.depdetect_ubuntu_list"
  139. echo -e "libcairo2" >> "${tmpdir}/.depdetect_debian_list"
  140. libdetected=1
  141. elif [ "${lib}" == "libfontconfig.so.1" ]; then
  142. echo -e "fontconfig" >> "${tmpdir}/.depdetect_centos_list"
  143. echo -e "libfontconfig1" >> "${tmpdir}/.depdetect_ubuntu_list"
  144. echo -e "libfontconfig1" >> "${tmpdir}/.depdetect_debian_list"
  145. libdetected=1
  146. elif [ "${lib}" == "libfreetype.so.6" ]; then
  147. echo -e "freetype" >> "${tmpdir}/.depdetect_centos_list"
  148. echo -e "libfreetype6" >> "${tmpdir}/.depdetect_ubuntu_list"
  149. echo -e "libfreetype6" >> "${tmpdir}/.depdetect_debian_list"
  150. libdetected=1
  151. fi
  152. if [ "${libdetected}" != "1" ]; then
  153. unknownlib=1
  154. echo -e "${lib}" >> "${tmpdir}/.depdetect_unknown"
  155. fi
  156. unset libdetected
  157. done < "${tmpdir}/.depdetect_readelf_uniq"
  158. sort "${tmpdir}/.depdetect_centos_list" | uniq >> "${tmpdir}/.depdetect_centos_list_uniq"
  159. sort "${tmpdir}/.depdetect_ubuntu_list" | uniq >> "${tmpdir}/.depdetect_ubuntu_list_uniq"
  160. sort "${tmpdir}/.depdetect_debian_list" | uniq >> "${tmpdir}/.depdetect_debian_list_uniq"
  161. if [ "${unknownlib}" == "1" ]; then
  162. sort "${tmpdir}/.depdetect_unknown" | uniq >> "${tmpdir}/.depdetect_unknown_uniq"
  163. fi
  164. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_centos_list_uniq" > "${tmpdir}/.depdetect_centos_line"
  165. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_ubuntu_list_uniq" > "${tmpdir}/.depdetect_ubuntu_line"
  166. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_debian_list_uniq" > "${tmpdir}/.depdetect_debian_line"
  167. echo -e ""
  168. echo -e ""
  169. echo -e "Required Dependencies"
  170. echo -e "================================="
  171. echo -e "${executable}"
  172. echo -e ""
  173. echo -e "CentOS"
  174. echo -e "================================="
  175. cat "${tmpdir}/.depdetect_centos_line"
  176. echo -e ""
  177. echo -e ""
  178. echo -e "Ubuntu"
  179. echo -e "================================="
  180. cat "${tmpdir}/.depdetect_ubuntu_line"
  181. echo -e ""
  182. echo -e ""
  183. echo -e "Debian"
  184. echo -e "================================="
  185. cat "${tmpdir}/.depdetect_debian_line"
  186. echo -e ""
  187. if [ "${unknownlib}" == "1" ]; then
  188. echo -e ""
  189. echo -e "Unknown shared Library"
  190. echo -e "================================="
  191. cat "${tmpdir}/.depdetect_unknown"
  192. fi
  193. echo -e ""
  194. echo -e "Required Librarys"
  195. echo -e "================================="
  196. sort "${tmpdir}/.depdetect_readelf" | uniq
  197. echo -en "\n"
  198. rm -f "${tmpdir:?}/.depdetect_centos_line"
  199. rm -f "${tmpdir:?}/.depdetect_centos_list"
  200. rm -f "${tmpdir:?}/.depdetect_centos_list_uniq"
  201. rm -f "${tmpdir:?}/.depdetect_debian_line"
  202. rm -f "${tmpdir:?}/.depdetect_debian_list"
  203. rm -f "${tmpdir:?}/.depdetect_debian_list_uniq"
  204. rm -f "${tmpdir:?}/.depdetect_ubuntu_line"
  205. rm -f "${tmpdir:?}/.depdetect_ubuntu_list"
  206. rm -f "${tmpdir:?}/.depdetect_ubuntu_list_uniq"
  207. rm -f "${tmpdir:?}/.depdetect_readelf"
  208. rm -f "${tmpdir:?}/.depdetect_readelf_uniq"
  209. rm -f "${tmpdir:?}/.depdetect_unknown"
  210. rm -f "${tmpdir:?}/.depdetect_unknown_uniq"
  211. core_exit.sh