4
0

command_dev_detect_deps.sh 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #!/bin/bash
  2. # LinuxGSM command_dev_detect_deps.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Detects dependencies the server binary requires.
  7. commandname="DEV-DETECT-DEPS"
  8. commandaction="Developer detect deps"
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. echo -e "================================="
  12. echo -e "Dependencies Checker"
  13. echo -e "================================="
  14. echo -e "Checking directory: "
  15. echo -e "${serverfiles}"
  16. if [ "$(command -v eu-readelf 2> /dev/null)" ]; then
  17. readelf=eu-readelf
  18. elif [ "$(command -v readelf 2> /dev/null)" ]; then
  19. readelf=readelf
  20. else
  21. echo -e "readelf/eu-readelf not installed"
  22. fi
  23. files=$(find "${serverfiles}" | wc -l)
  24. find "${serverfiles}" -type f -print0 \
  25. | while IFS= read -r -d $'\0' line; do
  26. if [ "${readelf}" == "eu-readelf" ]; then
  27. ${readelf} -d "${line}" 2> /dev/null | grep NEEDED | awk '{ print $4 }' | sed 's/\[//g;s/\]//g' >> "${tmpdir}/.depdetect_readelf"
  28. else
  29. ${readelf} -d "${line}" 2> /dev/null | grep NEEDED | awk '{ print $5 }' | sed 's/\[//g;s/\]//g' >> "${tmpdir}/.depdetect_readelf"
  30. fi
  31. echo -n "${i} / ${files}" $'\r'
  32. ((i++))
  33. done
  34. sort "${tmpdir}/.depdetect_readelf" | uniq > "${tmpdir}/.depdetect_readelf_uniq"
  35. touch "${tmpdir}/.depdetect_centos_list"
  36. touch "${tmpdir}/.depdetect_ubuntu_list"
  37. touch "${tmpdir}/.depdetect_debian_list"
  38. while read -r lib; do
  39. echo -e "${lib}"
  40. 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)
  41. for lib_file in "${libs_array[@]}"; do
  42. if [ "${lib}" == "${lib_file}" ]; then
  43. echo -e "glibc.i686" >> "${tmpdir}/.depdetect_centos_list"
  44. echo -e "lib32gcc1" >> "${tmpdir}/.depdetect_ubuntu_list"
  45. echo -e "lib32gcc1" >> "${tmpdir}/.depdetect_debian_list"
  46. libdetected=1
  47. fi
  48. done
  49. libs_array=(libawt.so libjava.so libjli.so libjvm.so libnet.so libnio.so libverify.so)
  50. for lib_file in "${libs_array[@]}"; 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[@]}"; do
  60. # Known shared libs what dont requires dependencies.
  61. if [ "${lib}" == "${lib_file}" ]; then
  62. libdetected=1
  63. fi
  64. done
  65. if [ "${lib}" == "libstdc++.so.6" ]; then
  66. echo -e "libstdc++.i686" >> "${tmpdir}/.depdetect_centos_list"
  67. echo -e "libstdc++6:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  68. echo -e "libstdc++6:i386" >> "${tmpdir}/.depdetect_debian_list"
  69. libdetected=1
  70. elif [ "${lib}" == "libstdc++.so.5" ]; then
  71. echo -e "compat-libstdc++-33.i686" >> "${tmpdir}/.depdetect_centos_list"
  72. echo -e "libstdc++5:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  73. echo -e "libstdc++5:i386" >> "${tmpdir}/.depdetect_debian_list"
  74. libdetected=1
  75. elif [ "${lib}" == "libcurl-gnutls.so.4" ]; then
  76. echo -e "libcurl.i686" >> "${tmpdir}/.depdetect_centos_list"
  77. echo -e "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  78. echo -e "libcurl4-gnutls-dev:i386" >> "${tmpdir}/.depdetect_debian_list"
  79. libdetected=1
  80. elif [ "${lib}" == "libspeex.so.1" ] || [ "${lib}" == "libspeexdsp.so.1" ]; then
  81. echo -e "speex.i686" >> "${tmpdir}/.depdetect_centos_list"
  82. echo -e "speex:i386" >> "${tmpdir}/.depdetect_ubuntu_list"
  83. echo -e "speex:i386" >> "${tmpdir}/.depdetect_debian_list"
  84. libdetected=1
  85. elif [ "${lib}" == "./libSDL-1.2.so.0" ] || [ "${lib}" == "libSDL-1.2.so.0" ]; then
  86. echo -e "SDL.i686" >> "${tmpdir}/.depdetect_centos_list"
  87. echo -e "libsdl1.2debian" >> "${tmpdir}/.depdetect_ubuntu_list"
  88. echo -e "libsdl1.2debian" >> "${tmpdir}/.depdetect_debian_list"
  89. libdetected=1
  90. elif [ "${lib}" == "libtbb.so.2" ]; then
  91. echo -e "tbb.i686" >> "${tmpdir}/.depdetect_centos_list"
  92. echo -e "libtbb2" >> "${tmpdir}/.depdetect_ubuntu_list"
  93. echo -e "libtbb2" >> "${tmpdir}/.depdetect_debian_list"
  94. libdetected=1
  95. elif [ "${lib}" == "libXrandr.so.2" ]; then
  96. echo -e "libXrandr" >> "${tmpdir}/.depdetect_centos_list"
  97. echo -e "libxrandr2" >> "${tmpdir}/.depdetect_ubuntu_list"
  98. echo -e "libxrandr2" >> "${tmpdir}/.depdetect_debian_list"
  99. libdetected=1
  100. elif [ "${lib}" == "libXext.so.6" ]; then
  101. echo -e "libXext" >> "${tmpdir}/.depdetect_centos_list"
  102. echo -e "libxext6" >> "${tmpdir}/.depdetect_ubuntu_list"
  103. echo -e "libxext6" >> "${tmpdir}/.depdetect_debian_list"
  104. libdetected=1
  105. elif [ "${lib}" == "libXtst.so.6" ]; then
  106. echo -e "libXtst" >> "${tmpdir}/.depdetect_centos_list"
  107. echo -e "libxtst6" >> "${tmpdir}/.depdetect_ubuntu_list"
  108. echo -e "libxtst6" >> "${tmpdir}/.depdetect_debian_list"
  109. libdetected=1
  110. elif [ "${lib}" == "libpulse.so.0" ]; then
  111. echo -e "pulseaudio-libs" >> "${tmpdir}/.depdetect_centos_list"
  112. echo -e "libpulse0" >> "${tmpdir}/.depdetect_ubuntu_list"
  113. echo -e "libpulse0" >> "${tmpdir}/.depdetect_debian_list"
  114. libdetected=1
  115. elif [ "${lib}" == "libopenal.so.1" ]; then
  116. echo -e "" >> "${tmpdir}/.depdetect_centos_list"
  117. echo -e "libopenal1" >> "${tmpdir}/.depdetect_ubuntu_list"
  118. echo -e "libopenal1" >> "${tmpdir}/.depdetect_debian_list"
  119. libdetected=1
  120. elif [ "${lib}" == "libgconf-2.so.4" ]; then
  121. echo -e "GConf2" >> "${tmpdir}/.depdetect_centos_list"
  122. echo -e "libgconf2-4" >> "${tmpdir}/.depdetect_ubuntu_list"
  123. echo -e "libgconf2-4" >> "${tmpdir}/.depdetect_debian_list"
  124. libdetected=1
  125. elif [ "${lib}" == "libz.so.1" ]; then
  126. echo -e "zlib" >> "${tmpdir}/.depdetect_centos_list"
  127. echo -e "zlib1g" >> "${tmpdir}/.depdetect_ubuntu_list"
  128. echo -e "zlib1g" >> "${tmpdir}/.depdetect_debian_list"
  129. libdetected=1
  130. elif [ "${lib}" == "libatk-1.0.so.0" ]; then
  131. echo -e "atk" >> "${tmpdir}/.depdetect_centos_list"
  132. echo -e "libatk1.0-0" >> "${tmpdir}/.depdetect_ubuntu_list"
  133. echo -e "libatk1.0-0" >> "${tmpdir}/.depdetect_debian_list"
  134. libdetected=1
  135. elif [ "${lib}" == "libcairo.so.2" ]; then
  136. echo -e "cairo" >> "${tmpdir}/.depdetect_centos_list"
  137. echo -e "libcairo2" >> "${tmpdir}/.depdetect_ubuntu_list"
  138. echo -e "libcairo2" >> "${tmpdir}/.depdetect_debian_list"
  139. libdetected=1
  140. elif [ "${lib}" == "libfontconfig.so.1" ]; then
  141. echo -e "fontconfig" >> "${tmpdir}/.depdetect_centos_list"
  142. echo -e "libfontconfig1" >> "${tmpdir}/.depdetect_ubuntu_list"
  143. echo -e "libfontconfig1" >> "${tmpdir}/.depdetect_debian_list"
  144. libdetected=1
  145. elif [ "${lib}" == "libfreetype.so.6" ]; then
  146. echo -e "freetype" >> "${tmpdir}/.depdetect_centos_list"
  147. echo -e "libfreetype6" >> "${tmpdir}/.depdetect_ubuntu_list"
  148. echo -e "libfreetype6" >> "${tmpdir}/.depdetect_debian_list"
  149. libdetected=1
  150. elif [ "${lib}" == "libc++.so.1" ]; then
  151. echo -e "libcxx" >> "${tmpdir}/.depdetect_centos_list"
  152. echo -e "libc++1" >> "${tmpdir}/.depdetect_ubuntu_list"
  153. echo -e "libc++1" >> "${tmpdir}/.depdetect_debian_list"
  154. libdetected=1
  155. fi
  156. if [ "${libdetected}" != "1" ]; then
  157. unknownlib=1
  158. echo -e "${lib}" >> "${tmpdir}/.depdetect_unknown"
  159. fi
  160. unset libdetected
  161. done < "${tmpdir}/.depdetect_readelf_uniq"
  162. sort "${tmpdir}/.depdetect_centos_list" | uniq >> "${tmpdir}/.depdetect_centos_list_uniq"
  163. sort "${tmpdir}/.depdetect_ubuntu_list" | uniq >> "${tmpdir}/.depdetect_ubuntu_list_uniq"
  164. sort "${tmpdir}/.depdetect_debian_list" | uniq >> "${tmpdir}/.depdetect_debian_list_uniq"
  165. if [ "${unknownlib}" == "1" ]; then
  166. sort "${tmpdir}/.depdetect_unknown" | uniq >> "${tmpdir}/.depdetect_unknown_uniq"
  167. fi
  168. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_centos_list_uniq" > "${tmpdir}/.depdetect_centos_line"
  169. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_ubuntu_list_uniq" > "${tmpdir}/.depdetect_ubuntu_line"
  170. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_debian_list_uniq" > "${tmpdir}/.depdetect_debian_line"
  171. echo -e ""
  172. echo -e ""
  173. echo -e "Required Dependencies"
  174. echo -e "================================="
  175. echo -e "${executable}"
  176. echo -e ""
  177. echo -e "CentOS"
  178. echo -e "================================="
  179. cat "${tmpdir}/.depdetect_centos_line"
  180. echo -e ""
  181. echo -e ""
  182. echo -e "Ubuntu"
  183. echo -e "================================="
  184. cat "${tmpdir}/.depdetect_ubuntu_line"
  185. echo -e ""
  186. echo -e ""
  187. echo -e "Debian"
  188. echo -e "================================="
  189. cat "${tmpdir}/.depdetect_debian_line"
  190. echo -e ""
  191. if [ "${unknownlib}" == "1" ]; then
  192. echo -e ""
  193. echo -e "Unknown shared Library"
  194. echo -e "================================="
  195. cat "${tmpdir}/.depdetect_unknown"
  196. fi
  197. echo -e ""
  198. echo -e "Required Librarys"
  199. echo -e "================================="
  200. sort "${tmpdir}/.depdetect_readelf" | uniq
  201. echo -en "\n"
  202. rm -f "${tmpdir:?}/.depdetect_centos_line"
  203. rm -f "${tmpdir:?}/.depdetect_centos_list"
  204. rm -f "${tmpdir:?}/.depdetect_centos_list_uniq"
  205. rm -f "${tmpdir:?}/.depdetect_debian_line"
  206. rm -f "${tmpdir:?}/.depdetect_debian_list"
  207. rm -f "${tmpdir:?}/.depdetect_debian_list_uniq"
  208. rm -f "${tmpdir:?}/.depdetect_ubuntu_line"
  209. rm -f "${tmpdir:?}/.depdetect_ubuntu_list"
  210. rm -f "${tmpdir:?}/.depdetect_ubuntu_list_uniq"
  211. rm -f "${tmpdir:?}/.depdetect_readelf"
  212. rm -f "${tmpdir:?}/.depdetect_readelf_uniq"
  213. rm -f "${tmpdir:?}/.depdetect_unknown"
  214. rm -f "${tmpdir:?}/.depdetect_unknown_uniq"
  215. core_exit.sh