check_steamcmd.sh 2.2 KB

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