command_dev_detect_deps.sh 9.1 KB

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