4
0

command_dev_detect_deps.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #!/bin/bash
  2. # LinuxGSM command_dev_detect_deps.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Detects dependencies the server binary requires.
  7. commandname="DEV-DETECT-DEPS"
  8. commandaction="Dependency Checker"
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. fn_print_header
  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[@]}"; do
  40. if [ "${lib}" == "${lib_file}" ]; then
  41. echo -e "glibc.i686" >> "${tmpdir}/.depdetect_centos_list"
  42. echo -e "lib32gcc1" >> "${tmpdir}/.depdetect_ubuntu_list"
  43. echo -e "lib32gcc1" >> "${tmpdir}/.depdetect_debian_list"
  44. libdetected=1
  45. fi
  46. done
  47. libs_array=(libawt.so libjava.so libjli.so libjvm.so libnet.so libnio.so libverify.so)
  48. for lib_file in "${libs_array[@]}"; do
  49. if [ "${lib}" == "${lib_file}" ]; then
  50. echo -e "java-1.8.0-openjdk" >> "${tmpdir}/.depdetect_centos_list"
  51. echo -e "default-jre" >> "${tmpdir}/.depdetect_ubuntu_list"
  52. echo -e "default-jre" >> "${tmpdir}/.depdetect_debian_list"
  53. libdetected=1
  54. fi
  55. done
  56. 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)
  57. for lib_file in "${libs_array[@]}"; 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. elif [ "${lib}" == "libz.so.1" ]; then
  124. echo -e "zlib" >> "${tmpdir}/.depdetect_centos_list"
  125. echo -e "zlib1g" >> "${tmpdir}/.depdetect_ubuntu_list"
  126. echo -e "zlib1g" >> "${tmpdir}/.depdetect_debian_list"
  127. libdetected=1
  128. elif [ "${lib}" == "libatk-1.0.so.0" ]; then
  129. echo -e "atk" >> "${tmpdir}/.depdetect_centos_list"
  130. echo -e "libatk1.0-0" >> "${tmpdir}/.depdetect_ubuntu_list"
  131. echo -e "libatk1.0-0" >> "${tmpdir}/.depdetect_debian_list"
  132. libdetected=1
  133. elif [ "${lib}" == "libcairo.so.2" ]; then
  134. echo -e "cairo" >> "${tmpdir}/.depdetect_centos_list"
  135. echo -e "libcairo2" >> "${tmpdir}/.depdetect_ubuntu_list"
  136. echo -e "libcairo2" >> "${tmpdir}/.depdetect_debian_list"
  137. libdetected=1
  138. elif [ "${lib}" == "libfontconfig.so.1" ]; then
  139. echo -e "fontconfig" >> "${tmpdir}/.depdetect_centos_list"
  140. echo -e "libfontconfig1" >> "${tmpdir}/.depdetect_ubuntu_list"
  141. echo -e "libfontconfig1" >> "${tmpdir}/.depdetect_debian_list"
  142. libdetected=1
  143. elif [ "${lib}" == "libfreetype.so.6" ]; then
  144. echo -e "freetype" >> "${tmpdir}/.depdetect_centos_list"
  145. echo -e "libfreetype6" >> "${tmpdir}/.depdetect_ubuntu_list"
  146. echo -e "libfreetype6" >> "${tmpdir}/.depdetect_debian_list"
  147. libdetected=1
  148. elif [ "${lib}" == "libc++.so.1" ]; then
  149. echo -e "libcxx" >> "${tmpdir}/.depdetect_centos_list"
  150. echo -e "libc++1" >> "${tmpdir}/.depdetect_ubuntu_list"
  151. echo -e "libc++1" >> "${tmpdir}/.depdetect_debian_list"
  152. libdetected=1
  153. fi
  154. if [ "${libdetected}" != "1" ]; then
  155. unknownlib=1
  156. echo -e "${lib}" >> "${tmpdir}/.depdetect_unknown"
  157. fi
  158. unset libdetected
  159. done < "${tmpdir}/.depdetect_readelf_uniq"
  160. sort "${tmpdir}/.depdetect_centos_list" | uniq >> "${tmpdir}/.depdetect_centos_list_uniq"
  161. sort "${tmpdir}/.depdetect_ubuntu_list" | uniq >> "${tmpdir}/.depdetect_ubuntu_list_uniq"
  162. sort "${tmpdir}/.depdetect_debian_list" | uniq >> "${tmpdir}/.depdetect_debian_list_uniq"
  163. if [ "${unknownlib}" == "1" ]; then
  164. sort "${tmpdir}/.depdetect_unknown" | uniq >> "${tmpdir}/.depdetect_unknown_uniq"
  165. fi
  166. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_centos_list_uniq" > "${tmpdir}/.depdetect_centos_line"
  167. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_ubuntu_list_uniq" > "${tmpdir}/.depdetect_ubuntu_line"
  168. awk -vORS='' '{ print $1,$2 }' "${tmpdir}/.depdetect_debian_list_uniq" > "${tmpdir}/.depdetect_debian_line"
  169. echo -e ""
  170. echo -e ""
  171. echo -e "${bold}Required Dependencies${default}"
  172. fn_messages_separator
  173. echo -e "${executable}"
  174. echo -e ""
  175. echo -e "${bold}CentOS"
  176. fn_messages_separator
  177. cat "${tmpdir}/.depdetect_centos_line"
  178. echo -e ""
  179. echo -e ""
  180. echo -e "Ubuntu"
  181. fn_messages_separator
  182. cat "${tmpdir}/.depdetect_ubuntu_line"
  183. echo -e ""
  184. echo -e ""
  185. echo -e "Debian"
  186. fn_messages_separator
  187. cat "${tmpdir}/.depdetect_debian_line"
  188. echo -e ""
  189. if [ "${unknownlib}" == "1" ]; then
  190. echo -e ""
  191. echo -e "Unknown shared Library"
  192. fn_messages_separator
  193. cat "${tmpdir}/.depdetect_unknown"
  194. fi
  195. echo -e ""
  196. echo -e "Required Librarys"
  197. fn_messages_separator
  198. sort "${tmpdir}/.depdetect_readelf" | uniq
  199. echo -en "\n"
  200. rm -f "${tmpdir:?}/.depdetect_centos_line"
  201. rm -f "${tmpdir:?}/.depdetect_centos_list"
  202. rm -f "${tmpdir:?}/.depdetect_centos_list_uniq"
  203. rm -f "${tmpdir:?}/.depdetect_debian_line"
  204. rm -f "${tmpdir:?}/.depdetect_debian_list"
  205. rm -f "${tmpdir:?}/.depdetect_debian_list_uniq"
  206. rm -f "${tmpdir:?}/.depdetect_ubuntu_line"
  207. rm -f "${tmpdir:?}/.depdetect_ubuntu_list"
  208. rm -f "${tmpdir:?}/.depdetect_ubuntu_list_uniq"
  209. rm -f "${tmpdir:?}/.depdetect_readelf"
  210. rm -f "${tmpdir:?}/.depdetect_readelf_uniq"
  211. rm -f "${tmpdir:?}/.depdetect_unknown"
  212. rm -f "${tmpdir:?}/.depdetect_unknown_uniq"
  213. core_exit.sh