check_steamcmd.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. # LGSM check_steamcmd.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Checks SteamCMD is installed and correct.
  6. local modulename="Checking"
  7. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  8. fn_install_steamcmd(){
  9. if [ ! -d "${steamcmddir}" ]; then
  10. mkdir -v "${steamcmddir}"
  11. fi
  12. fn_fetch_file "http://media.steampowered.com/client/steamcmd_linux.tar.gz" "${lgsmdir}/tmp" "steamcmd_linux.tar.gz"
  13. fn_dl_extract "${lgsmdir}/tmp" "steamcmd_linux.tar.gz" "${steamcmddir}"
  14. chmod +x "${steamcmddir}/steamcmd.sh"
  15. }
  16. fn_check_steamcmd_user(){
  17. # Checks steamuser is setup.
  18. if [ "${steamuser}" == "username" ]; then
  19. fn_print_fail_nl "Steam login not set. Update steamuser in ${selfname}."
  20. echo " * Change steamuser=\"username\" to a valid steam login."
  21. if [ -d "${scriptlogdir}" ]; then
  22. fn_script_log_fatal "Steam login not set. Update steamuser in ${selfname}."
  23. fi
  24. core_exit.sh
  25. fi
  26. # Anonymous user is set if steamuser is missing
  27. if [ -z "${steamuser}" ]; then
  28. fn_print_warn_nl "Steam login not set. Using anonymous login."
  29. if [ -d "${scriptlogdir}" ]; then
  30. fn_script_log_error "Steam login not set. Using anonymous login."
  31. fi
  32. steamuser="anonymous"
  33. steampass=""
  34. sleep 2
  35. fi
  36. }
  37. fn_check_steamcmd_sh(){
  38. # Checks if SteamCMD exists when starting or updating a server.
  39. # Installs if missing.
  40. steamcmddir="${rootdir}/steamcmd"
  41. if [ ! -f "${steamcmddir}/steamcmd.sh" ]; then
  42. if [ "${function_selfname}" == "command_install.sh" ]; then
  43. fn_install_steamcmd
  44. else
  45. fn_print_warn_nl "SteamCMD is missing"
  46. fn_script_log_warn "SteamCMD is missing"
  47. sleep 1
  48. fn_install_steamcmd
  49. fi
  50. elif [ "${function_selfname}" == "command_install.sh" ]; then
  51. fn_print_infomation "SteamCMD is already installed..."
  52. fn_print_ok_eol_nl
  53. fi
  54. }
  55. fn_check_steamcmd_guard(){
  56. if [ "${function_selfname}" == "command_update.sh" ]||[ "${function_selfname}" == "command_validate.sh" ]; then
  57. # Checks that steamcmd is working correctly and will prompt Steam Guard if required.
  58. "${steamcmddir}"/steamcmd.sh +login "${steamuser}" "${steampass}" +quit
  59. if [ $? -ne 0 ]; then
  60. fn_print_failure_nl "Error running SteamCMD"
  61. fi
  62. fi
  63. }
  64. fn_check_steamcmd_user
  65. fn_check_steamcmd_sh
  66. fn_check_steamcmd_guard