command_dev_detect_deps.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/bash
  2. # LGSM fn_dep_detect function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Detects dependencies the server binary requires.
  6. local modulename="Deps Detect"
  7. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  8. check.sh
  9. cd "${executabledir}"
  10. if [ "${executable}" == "./hlds_run" ]; then
  11. executable=hlds_linux
  12. elif [ "${executable}" == "./srcds_run" ]||[ "${executable}" == "./dabds.sh" ]||[ "${executable}" == "./srcds_run.sh" ]; then
  13. executable=srcds_linux
  14. elif [ "${executable}" == "./server_linux32" ]; then
  15. executable=libSpark_Core.so
  16. elif [ "${executable}" == "./runSam3_DedicatedServer.sh" ]; then
  17. executable=Sam3_DedicatedServer
  18. elif [ "${executable}" == "./7DaysToDie.sh" ]; then
  19. executable=7DaysToDie.x86
  20. elif [ "${executable}" == "./ucc-bin" ]; then
  21. if [ -f "${executabledir}/ucc-bin-real" ]; then
  22. executable=ucc-bin-real
  23. elif [ -f "${executabledir}/ut2004-bin" ]; then
  24. executable=ut2004-bin
  25. else
  26. executable=ut-bin
  27. fi
  28. elif [ "${executable}" == "./ts3server_startscript.sh" ]; then
  29. executable=ts3server_linux_amd64
  30. fi
  31. if [ "$(command -v eu-readelf)" ]; then
  32. readelf=eu-readelf
  33. elif [ "$(command -v readelf)" ]; then
  34. readelf=readelf
  35. else
  36. echo "readelf/eu-readelf not installed"
  37. fi
  38. ${readelf} -d ${executable} |grep NEEDED|awk '{ print $5 }'|sed 's/\[//g'|sed 's/\]//g' > "${rootdir}/.depdetect_readelf"
  39. echo "yum install " > "${rootdir}/.depdetect_centos_list_uniq"
  40. echo "apt-get install " > "${rootdir}/.depdetect_ubuntu_list_uniq"
  41. echo "apt-get install " > "${rootdir}/.depdetect_debian_list_uniq"
  42. while read lib; do
  43. sharedlib=${lib}
  44. if [ "${lib}" == "libm.so.6" ]||[ "${lib}" == "libc.so.6" ]||[ "${lib}" == "libpthread.so.0" ]||[ "${lib}" == "libdl.so.2" ]||[ "${lib}" == "libnsl.so.1" ]||[ "${lib}" == "libgcc_s.so.1" ]||[ "${lib}" == "librt.so.1" ]||[ "${lib}" == "ld-linux.so.2" ]; then
  45. echo "glibc.i686" >> "${rootdir}/.depdetect_centos_list"
  46. echo "lib32gcc1" >> "${rootdir}/.depdetect_ubuntu_list"
  47. echo "lib32gcc1" >> "${rootdir}/.depdetect_debian_list"
  48. elif [ "${lib}" == "libstdc++.so.6" ]; then
  49. echo "libstdc++.i686" >> "${rootdir}/.depdetect_centos_list"
  50. echo "libstdc++6:i386" >> "${rootdir}/.depdetect_ubuntu_list"
  51. echo "libstdc++6:i386" >> "${rootdir}/.depdetect_debian_list"
  52. elif [ "${lib}" == "libstdc++.so.5" ]; then
  53. echo "compat-libstdc++-33.i686" >> "${rootdir}/.depdetect_centos_list"
  54. echo "libstdc++5:i386" >> "${rootdir}/.depdetect_ubuntu_list"
  55. echo "libstdc++5:i386" >> "${rootdir}/.depdetect_debian_list"
  56. elif [ "${lib}" == "libspeex.so.1" ]||[ "${lib}" == "libspeexdsp.so.1" ]; then
  57. echo "speex.i686" >> "${rootdir}/.depdetect_centos_list"
  58. echo "speex:i386" >> "${rootdir}/.depdetect_ubuntu_list"
  59. echo "speex:i386" >> "${rootdir}/.depdetect_debian_list"
  60. elif [ "${lib}" == "./libSDL-1.2.so.0" ]||[ "${lib}" == "libSDL-1.2.so.0" ]; then
  61. echo "SDL.i686" >> "${rootdir}/.depdetect_centos_list"
  62. echo "libsdl1.2debian" >> "${rootdir}/.depdetect_ubuntu_list"
  63. echo "libsdl1.2debian" >> "${rootdir}/.depdetect_debian_list"
  64. elif [ "${lib}" == "libtbb.so.2" ]; then
  65. echo "tbb.i686" >> "${rootdir}/.depdetect_centos_list"
  66. echo "libtbb2" >> "${rootdir}/.depdetect_ubuntu_list"
  67. echo "libtbb2" >> "${rootdir}/.depdetect_debian_list"
  68. elif [ "${lib}" == "libtier0.so" ]||[ "${lib}" == "Core.so" ]||[ "${lib}" == "Editor.so" ]||[ "${lib}" == "Engine.so" ]||[ "${lib}" == "liblua.so" ]||[ "${lib}" == "libsteam_api.so" ]||[ "${lib}" == "ld-linux-x86-64.so.2" ]||[ "${lib}" == "libPhysX3_x86.so" ]||[ "${lib}" == "libPhysX3Common_x86.so" ]||[ "${lib}" == "libPhysX3Cooking_x86.so" ]; then
  69. # Known shared libs what dont requires dependencies
  70. :
  71. else
  72. unknownlib=1
  73. echo "${lib}" >> "${rootdir}/.depdetect_unknown"
  74. fi
  75. done < "${rootdir}/.depdetect_readelf"
  76. sort "${rootdir}/.depdetect_centos_list" | uniq >> "${rootdir}/.depdetect_centos_list_uniq"
  77. sort "${rootdir}/.depdetect_ubuntu_list" | uniq >> "${rootdir}/.depdetect_ubuntu_list_uniq"
  78. sort "${rootdir}/.depdetect_debian_list" | uniq >> "${rootdir}/.depdetect_debian_list_uniq"
  79. if [ "${unknownlib}" == "1" ]; then
  80. sort "${rootdir}/.depdetect_unknown" | uniq >> "${rootdir}/.depdetect_unknown_uniq"
  81. fi
  82. awk -vORS=' ' '{ print $1, $2 }' "${rootdir}/.depdetect_centos_list_uniq" > "${rootdir}/.depdetect_centos_line"
  83. awk -vORS=' ' '{ print $1, $2 }' "${rootdir}/.depdetect_ubuntu_list_uniq" > "${rootdir}/.depdetect_ubuntu_line"
  84. awk -vORS=' ' '{ print $1, $2 }' "${rootdir}/.depdetect_debian_list_uniq" > "${rootdir}/.depdetect_debian_line"
  85. echo ""
  86. echo "Required Dependencies"
  87. echo "================================="
  88. echo "${executable}"
  89. echo ""
  90. echo "CentOS"
  91. echo "================================="
  92. cat "${rootdir}/.depdetect_centos_line"
  93. echo ""
  94. echo ""
  95. echo "Ubuntu"
  96. echo "================================="
  97. cat "${rootdir}/.depdetect_ubuntu_line"
  98. echo ""
  99. echo ""
  100. echo "Debian"
  101. echo "================================="
  102. cat "${rootdir}/.depdetect_debian_line"
  103. echo ""
  104. if [ "${unknownlib}" == "1" ]; then
  105. echo ""
  106. echo "Unknown shared Library"
  107. echo "================================="
  108. cat "${rootdir}/.depdetect_unknown"
  109. fi
  110. echo ""
  111. echo "Required Librarys"
  112. echo "================================="
  113. sort "${rootdir}/.depdetect_readelf" |uniq
  114. echo ""
  115. echo "ldd"
  116. echo "================================="
  117. ldd ${executable}
  118. echo -en "\n"
  119. rm -f "${rootdir}/.depdetect_centos_line"
  120. rm -f "${rootdir}/.depdetect_centos_list"
  121. rm -f "${rootdir}/.depdetect_centos_list_uniq"
  122. rm -f "${rootdir}/.depdetect_debian_line"
  123. rm -f "${rootdir}/.depdetect_debian_list"
  124. rm -f "${rootdir}/.depdetect_debian_list_uniq"
  125. rm -f "${rootdir}/.depdetect_ubuntu_line"
  126. rm -f "${rootdir}/.depdetect_ubuntu_list"
  127. rm -f "${rootdir}/.depdetect_ubuntu_list_uniq"
  128. rm -f "${rootdir}/.depdetect_readelf"
  129. rm -f "${rootdir}/.depdetect_unknown"
  130. rm -f "${rootdir}/.depdetect_unknown_uniq"