check_steamcmd.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. fn_print_fail_nl "Steam login not set. Update steamuser in ${configdirserver}"
  32. echo -e " * Change steamuser=\"username\" to a valid steam login."
  33. if [ -d "${lgsmlogdir}" ]; then
  34. fn_script_log_fatal "Steam login not set. Update steamuser in ${configdirserver}"
  35. fi
  36. core_exit.sh
  37. fi
  38. # Anonymous user is set if steamuser is missing.
  39. if [ -z "${steamuser}" ]; then
  40. if [ -d "${lgsmlogdir}" ]; then
  41. fn_script_log_info "Using anonymous Steam login"
  42. fi
  43. steamuser="anonymous"
  44. steampass=''
  45. fi
  46. }
  47. fn_check_steamcmd(){
  48. # Checks if SteamCMD exists when starting or updating a server.
  49. # Only install if steamcmd package is missing or steamcmd dir is missing.
  50. if [ ! -f "${steamcmddir}/steamcmd.sh" ]&&[ -z "$(command -v steamcmd 2>/dev/null)" ]; then
  51. if [ "${commandname}" == "INSTALL" ]; then
  52. fn_install_steamcmd
  53. else
  54. fn_print_warn_nl "SteamCMD is missing"
  55. fn_script_log_warn "SteamCMD is missing"
  56. fn_install_steamcmd
  57. fi
  58. elif [ "${commandname}" == "INSTALL" ]; then
  59. fn_print_information "SteamCMD is already installed..."
  60. fn_print_ok_eol_nl
  61. fi
  62. }
  63. fn_check_steamcmd_dir(){
  64. # Worksround that pre-installs the correct steam directories to ensure all packages use the correct Standard.
  65. # https://github.com/ValveSoftware/steam-for-linux/issues/6976#issuecomment-610446347
  66. # Create Steam installation directory.
  67. if [ ! -d "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" ]; then
  68. mkdir -p "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam"
  69. fi
  70. # Create common Steam directory.
  71. if [ ! -d "${HOME}/.steam" ]; then
  72. mkdir -p "${HOME}/.steam"
  73. fi
  74. # Symbolic links to Steam installation directory.
  75. if [ ! -L "${HOME}/.steam/root" ]; then
  76. if [ -d "${HOME}/.steam/root" ]; then
  77. rm "${HOME}/.steam/root"
  78. fi
  79. ln -s "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" "${HOME}/.steam/root"
  80. fi
  81. if [ ! -L "${HOME}/.steam/steam" ]; then
  82. if [ -d "${HOME}/.steam/steam" ]; then
  83. rm -rf "${HOME}/.steam/steam"
  84. fi
  85. ln -s "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" "${HOME}/.steam/steam"
  86. fi
  87. }
  88. fn_check_steamcmd_dir_legacy(){
  89. # Remove old Steam installation directories ~/Steam and ${rootdir}/steamcmd
  90. if [ -d "${rootdir}/steamcmd" ]&&[ "${steamcmddir}" == "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" ]; then
  91. rm -rf "${rootdir:?}/steamcmd"
  92. fi
  93. if [ -d "${HOME}/Steam" ]&&[ "${steamcmddir}" == "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" ]; then
  94. rm -rf "${HOME}/Steam"
  95. fi
  96. }
  97. fn_check_steamcmd_ark(){
  98. # Checks if SteamCMD exists in
  99. # Engine/Binaries/ThirdParty/SteamCMD/Linux
  100. # to allow ark mods to work
  101. if [ ! -f "${serverfiles}/Engine/Binaries/ThirdParty/SteamCMD/Linux/steamcmd.sh" ]; then
  102. installsteamcmd=1
  103. if [ "${commandname}" == "INSTALL" ]; then
  104. fn_install_steamcmd
  105. else
  106. fn_print_warn_nl "ARK mods SteamCMD is missing"
  107. fn_script_log_warn "ARK mods SteamCMD is missing"
  108. fn_install_steamcmd
  109. fi
  110. elif [ "${commandname}" == "INSTALL" ]; then
  111. fn_print_information "ARK mods SteamCMD is already installed..."
  112. fn_print_ok_eol_nl
  113. fi
  114. }
  115. fn_check_steamcmd_clear(){
  116. # Will remove steamcmd dir if steamcmd package is installed.
  117. if [ "$(command -v steamcmd 2>/dev/null)" ]&&[ -d "${rootdir}/steamcmd" ]; then
  118. rm -rf "${steamcmddir:?}"
  119. exitcode=$?
  120. if [ "${exitcode}" != 0 ]; then
  121. fn_script_log_fatal "Removing ${rootdir}/steamcmd"
  122. else
  123. fn_script_log_pass "Removing ${rootdir}/steamcmd"
  124. fi
  125. fi
  126. }
  127. fn_check_steamcmd_exec(){
  128. if [ "$(command -v steamcmd 2>/dev/null)" ]; then
  129. steamcmdcommand="steamcmd"
  130. else
  131. steamcmdcommand="./steamcmd.sh"
  132. fi
  133. }
  134. fn_check_steamcmd_clear
  135. fn_check_steamcmd
  136. if [ ${shortname} == "ark" ]; then
  137. fn_check_steamcmd_ark
  138. fi
  139. fn_check_steamcmd_dir
  140. fn_check_steamcmd_dir_legacy
  141. fn_check_steamcmd_user
  142. fn_check_steamcmd_exec