command_dev_detect_deps.sh 9.1 KB

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