fix_steamcmd.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/bash
  2. # LinuxGSM fix_steamcmd.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Resolves issues with SteamCMD.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. # function to simplify the steamclient.so fix
  9. # example
  10. # fn_fix_steamclient_so 32|64 (bit) "${serverfiles}/linux32/"
  11. fn_fix_steamclient_so() {
  12. # $1 type of fix 32 or 64 as possible values
  13. # $2 as destination where the lib will be copied to
  14. if [ "$1" == "32" ]; then
  15. # steamclient.so x86 fix.
  16. if [ ! -f "${2}/steamclient.so" ]; then
  17. fixname="steamclient.so x86"
  18. fn_fix_msg_start
  19. if [ ! -d "${2}" ]; then
  20. mkdir -p "${2}"
  21. fi
  22. if [ -f "${HOME}/.steam/steamcmd/linux32/steamclient.so" ]; then
  23. cp "${HOME}/.steam/steamcmd/linux32/steamclient.so" "${2}/steamclient.so"
  24. elif [ -f "${steamcmddir}/linux32/steamclient.so" ]; then
  25. cp "${steamcmddir}/linux32/steamclient.so" "${2}/steamclient.so"
  26. elif [ -f "${HOME}/.local/share/Steam/steamcmd/linux32/steamclient.so" ]; then
  27. cp "${HOME}/.local/share/Steam/steamcmd/linux32/steamclient.so" "${2}/steamclient.so"
  28. fi
  29. fn_fix_msg_end
  30. fi
  31. elif [ "$1" == "64" ]; then
  32. # steamclient.so x86_64 fix.
  33. if [ ! -f "${2}/steamclient.so" ]; then
  34. fixname="steamclient.so x86_64"
  35. fn_fix_msg_start
  36. if [ ! -d "${2}" ]; then
  37. mkdir -p "${2}"
  38. fi
  39. if [ -f "${HOME}/.steam/steamcmd/linux64/steamclient.so" ]; then
  40. cp "${HOME}/.steam/steamcmd/linux64/steamclient.so" "${2}/steamclient.so"
  41. elif [ -f "${steamcmddir}/linux64/steamclient.so" ]; then
  42. cp "${steamcmddir}/linux64/steamclient.so" "${2}/steamclient.so"
  43. elif [ -f "${HOME}/.local/share/Steam/steamcmd/linux64/steamclient.so" ]; then
  44. cp "${HOME}/.local/share/Steam/steamcmd/linux64/steamclient.so" "${2}/steamclient.so"
  45. fi
  46. fn_fix_msg_end
  47. fi
  48. fi
  49. }
  50. # Helps fix: [S_API FAIL] SteamAPI_Init() failed; unable to locate a running instance of Steam,or a local steamclient.so.
  51. steamsdk64="${HOME}/.steam/sdk64"
  52. steamclientsdk64="${steamsdk64}/steamclient.so"
  53. # remove any old unlinked versions of steamclient.so
  54. if [ -f "${steamclientsdk64}" ]; then
  55. if [ "$(stat -c '%h' "${steamclientsdk64}")" -eq 1 ]; then
  56. fixname="steamclient.so sdk64 - remove old file"
  57. fn_fix_msg_start
  58. rm -f "${steamclientsdk64}"
  59. fn_fix_msg_end
  60. fi
  61. fi
  62. # place new hardlink for the file to the disk
  63. if [ ! -f "${steamclientsdk64}" ]; then
  64. for steamclientso in "${HOME}/.steam/steamcmd/linux64/steamclient.so" "${steamcmddir}/linux64/steamclient.so" "${HOME}/.local/share/Steam/steamcmd/linux64/steamclient.so"; do
  65. if [ -f "${steamclientso}" ]; then
  66. fixname="steamclient.so sdk64 hardlink"
  67. fn_fix_msg_start
  68. mkdir -p "${steamsdk64}"
  69. ln "${steamclientso}" "${steamclientsdk64}"
  70. fn_fix_msg_end
  71. break
  72. fi
  73. done
  74. fi
  75. # Helps fix: [S_API FAIL] SteamAPI_Init() failed; unable to locate a running instance of Steam,or a local steamclient.so.
  76. steamsdk32="${HOME}/.steam/sdk32"
  77. steamclientsdk32="${HOME}/.steam/sdk32/steamclient.so"
  78. if [ -f "${steamclientsdk32}" ]; then
  79. if [ " $(stat -c '%h' "${steamclientsdk32}")" -eq 1 ]; then
  80. fixname="steamclient.so sdk32 - remove old file"
  81. fn_fix_msg_start
  82. rm -f "${steamclientsdk32}"
  83. fn_fix_msg_end
  84. fi
  85. fi
  86. # place new hardlink for the file to the disk
  87. if [ ! -f "${steamclientsdk32}" ]; then
  88. for steamclientso in "${HOME}/.steam/steamcmd/linux32/steamclient.so" "${steamcmddir}/linux32/steamclient.so" "${HOME}/.local/share/Steam/steamcmd/linux32/steamclient.so"; do
  89. if [ -f "${steamclientso}" ]; then
  90. fixname="steamclient.so sdk32 link"
  91. fn_fix_msg_start
  92. mkdir -p "${steamsdk32}"
  93. ln "${steamclientso}" "${steamclientsdk32}"
  94. fn_fix_msg_end
  95. break
  96. fi
  97. done
  98. fi
  99. # Helps fix: WARNING: Failed to load 32-bit libtinfo.so.5 or libncurses.so.5.
  100. # On distros that ship libtinfo.so.6 (e.g. Ubuntu 22.04+, Debian 12+) but not
  101. # libtinfo.so.5, SteamCMD prints this warning and loses readline support.
  102. # Creating a symlink from .so.5 -> .so.6 resolves the warning without root.
  103. for libtinfo32dir in "${HOME}/.steam/steamcmd" "${steamcmddir}" "${HOME}/.local/share/Steam/steamcmd"; do
  104. if [ -d "${libtinfo32dir}" ]; then
  105. libtinfo32so="${libtinfo32dir}/libtinfo.so.5"
  106. # Also repair broken symlinks (! -e catches missing target, -L catches dangling link)
  107. if [ ! -e "${libtinfo32so}" ]; then
  108. # Find the .so.6 in the system 32-bit lib paths
  109. for libtinfo32so6 in /lib/i386-linux-gnu/libtinfo.so.6 /usr/lib/i386-linux-gnu/libtinfo.so.6 /lib32/libtinfo.so.6; do
  110. if [ -f "${libtinfo32so6}" ]; then
  111. fixname="libtinfo.so.5 32-bit symlink"
  112. fn_fix_msg_start
  113. mkdir -p "${libtinfo32dir}"
  114. ln -sf "${libtinfo32so6}" "${libtinfo32so}"
  115. exitcode=$?
  116. fn_fix_msg_end
  117. break
  118. fi
  119. done
  120. fi
  121. fi
  122. done
  123. # steamclient.so fixes
  124. if [ "${shortname}" == "bo" ]; then
  125. fn_fix_steamclient_so "32" "${serverfiles}/BODS_Data/Plugins/x86"
  126. fn_fix_steamclient_so "64" "${serverfiles}/BODS_Data/Plugins/x86_64"
  127. elif [ "${shortname}" == "cmw" ]; then
  128. fn_fix_steamclient_so "32" "${executabledir}/lib"
  129. elif [ "${shortname}" == "cs" ]; then
  130. fn_fix_steamclient_so "32" "${serverfiles}"
  131. elif [ "${shortname}" == "col" ]; then
  132. fn_fix_steamclient_so "64" "${serverfiles}"
  133. elif [ "${shortname}" == "ins" ]; then
  134. fn_fix_steamclient_so "32" "${serverfiles}/bin"
  135. elif [ "${shortname}" == "pz" ]; then
  136. fn_fix_steamclient_so "32" "${serverfiles}/linux32"
  137. fn_fix_steamclient_so "64" "${serverfiles}/linux64"
  138. elif [ "${shortname}" == "pvr" ]; then
  139. fn_fix_steamclient_so "64" "${executabledir}"
  140. elif [ "${shortname}" == "ss3" ]; then
  141. fn_fix_steamclient_so "32" "${serverfiles}/Bin"
  142. elif [ "${shortname}" == "tu" ]; then
  143. fn_fix_steamclient_so "64" "${executabledir}"
  144. elif [ "${shortname}" == "unt" ]; then
  145. fn_fix_steamclient_so "64" "${serverfiles}"
  146. elif [ "${shortname}" == "wurm" ]; then
  147. fn_fix_steamclient_so "64" "${serverfiles}/nativelibs"
  148. fi