check_steamcmd.sh 4.7 KB

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