check_steamcmd.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/bash
  2. # LinuxGSM check_steamcmd.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Checks if SteamCMD is installed correctly.
  6. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  7. fn_install_steamcmd(){
  8. if [ ${shortname} == "ark" ]&&[ "${installsteamcmd}" == "1" ]; then
  9. steamcmddir="${serverfiles}/Engine/Binaries/ThirdParty/SteamCMD/Linux"
  10. fi
  11. if [ ! -d "${steamcmddir}" ]; then
  12. mkdir -p "${steamcmddir}"
  13. fi
  14. remote_fileurl="${1}"
  15. remote_fileurl_backup="${2}"
  16. remote_fileurl_name="${3}"
  17. remote_fileurl_backup_name="${4}"
  18. local_filedir="${5}"
  19. local_filename="${6}"
  20. chmodx="${7:-0}"
  21. run="${8:-0}"
  22. forcedl="${9:-0}"
  23. md5="${10:-0}"
  24. fn_fetch_file "http://media.steampowered.com/client/steamcmd_linux.tar.gz" "" "" "" "${tmpdir}" "steamcmd_linux.tar.gz" "" "norun" "noforce" "nomd5"
  25. fn_dl_extract "${tmpdir}" "steamcmd_linux.tar.gz" "${steamcmddir}"
  26. chmod +x "${steamcmddir}/steamcmd.sh"
  27. }
  28. fn_check_steamcmd_user(){
  29. # Checks if steamuser is setup.
  30. if [ "${steamuser}" == "username" ]; then
  31. if [ "${legacymode}" == "1" ]; then
  32. fn_print_fail_nl "Steam login not set. Update steamuser in ${selfname}"
  33. else
  34. fn_print_fail_nl "Steam login not set. Update steamuser in ${configdirserver}"
  35. fi
  36. echo -e " * Change steamuser=\"username\" to a valid steam login."
  37. if [ -d "${lgsmlogdir}" ]; then
  38. if [ "${legacymode}" == "1" ]; then
  39. fn_script_log_fatal "Steam login not set. Update steamuser in ${selfname}"
  40. else
  41. fn_script_log_fatal "Steam login not set. Update steamuser in ${configdirserver}"
  42. fi
  43. fi
  44. core_exit.sh
  45. fi
  46. # Anonymous user is set if steamuser is missing.
  47. if [ -z "${steamuser}" ]; then
  48. if [ -d "${lgsmlogdir}" ]; then
  49. fn_script_log_info "Using anonymous Steam login"
  50. fi
  51. steamuser="anonymous"
  52. steampass=''
  53. fi
  54. }
  55. fn_check_steamcmd(){
  56. # Checks if SteamCMD exists when starting or updating a server.
  57. # Only install if steamcmd package is missing or steamcmd dir is missing.
  58. if [ ! -f "${steamcmddir}/steamcmd.sh" ]&&[ -z "$(command -v steamcmd 2>/dev/null)" ]; then
  59. if [ "${commandname}" == "INSTALL" ]; then
  60. fn_install_steamcmd
  61. else
  62. fn_print_warn_nl "SteamCMD is missing"
  63. fn_script_log_warn "SteamCMD is missing"
  64. fn_install_steamcmd
  65. fi
  66. elif [ "${commandname}" == "INSTALL" ]; then
  67. fn_print_information "SteamCMD is already installed..."
  68. fn_print_ok_eol_nl
  69. fi
  70. }
  71. fn_check_steamcmd_dir(){
  72. # Worksround that pre-installs the correct steam directories to ensure all packages use the correct Standard.
  73. # https://github.com/ValveSoftware/steam-for-linux/issues/6976#issuecomment-610446347
  74. # Create Steam installation directory.
  75. if [ ! -d "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" ]; then
  76. mkdir -p "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam"
  77. fi
  78. # Create common Steam directory.
  79. if [ ! -d "${HOME}/.steam" ]; then
  80. mkdir -p "${HOME}/.steam"
  81. fi
  82. # Symbolic links to Steam installation directory.
  83. if [ ! -L "${HOME}/.steam/root" ]; then
  84. if [ -d "${HOME}/.steam/root" ]; then
  85. rm "${HOME}/.steam/root"
  86. fi
  87. ln -s "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" "${HOME}/.steam/root"
  88. fi
  89. if [ ! -L "${HOME}/.steam/steam" ]; then
  90. if [ -d "${HOME}/.steam/steam" ]; then
  91. rm -rf "${HOME}/.steam/steam"
  92. fi
  93. ln -s "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" "${HOME}/.steam/steam"
  94. fi
  95. }
  96. fn_check_steamcmd_dir_legacy(){
  97. # Remove old Steam installation directories ~/Steam and ${rootdir}/steamcmd
  98. if [ -d "${rootdir}/steamcmd" ]&&[ "${steamcmddir}" == "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" ]; then
  99. rm -rf "${rootdir:?}/steamcmd"
  100. fi
  101. if [ -d "${HOME}/Steam" ]&&[ "${steamcmddir}" == "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" ]; then
  102. rm -rf "${HOME}/Steam"
  103. fi
  104. }
  105. fn_check_steamcmd_ark(){
  106. # Checks if SteamCMD exists in
  107. # Engine/Binaries/ThirdParty/SteamCMD/Linux
  108. # to allow ark mods to work
  109. if [ ! -f "${serverfiles}/Engine/Binaries/ThirdParty/SteamCMD/Linux/steamcmd.sh" ]; then
  110. installsteamcmd=1
  111. if [ "${commandname}" == "INSTALL" ]; then
  112. fn_install_steamcmd
  113. else
  114. fn_print_warn_nl "ARK mods SteamCMD is missing"
  115. fn_script_log_warn "ARK mods SteamCMD is missing"
  116. fn_install_steamcmd
  117. fi
  118. elif [ "${commandname}" == "INSTALL" ]; then
  119. fn_print_information "ARK mods SteamCMD is already installed..."
  120. fn_print_ok_eol_nl
  121. fi
  122. }
  123. fn_check_steamcmd_clear(){
  124. # Will remove steamcmd dir if steamcmd package is installed.
  125. if [ "$(command -v steamcmd 2>/dev/null)" ]&&[ -d "${rootdir}/steamcmd" ]; then
  126. rm -rf "${steamcmddir:?}"
  127. exitcode=$?
  128. if [ ${exitcode} -ne 0 ]; then
  129. fn_script_log_fatal "Removing ${rootdir}/steamcmd"
  130. else
  131. fn_script_log_pass "Removing ${rootdir}/steamcmd"
  132. fi
  133. fi
  134. }
  135. fn_check_steamcmd_exec(){
  136. if [ "$(command -v steamcmd 2>/dev/null)" ]; then
  137. steamcmdcommand="steamcmd"
  138. else
  139. steamcmdcommand="./steamcmd.sh"
  140. fi
  141. }
  142. fn_check_steamcmd_clear
  143. fn_check_steamcmd
  144. if [ ${shortname} == "ark" ]; then
  145. fn_check_steamcmd_ark
  146. fi
  147. fn_check_steamcmd_dir
  148. fn_check_steamcmd_dir_legacy
  149. fn_check_steamcmd_user
  150. fn_check_steamcmd_exec