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 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" "${lgsmdir}/tmp" "steamcmd_linux.tar.gz"
  12. fn_dl_extract "${lgsmdir}/tmp" "steamcmd_linux.tar.gz" "${steamcmddir}"
  13. chmod +x "${steamcmddir}/steamcmd.sh"
  14. }
  15. fn_check_steamcmd_user(){
  16. # Checks 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. fn_print_error_nl "Steam login not set. Using anonymous login."
  28. if [ -d "${scriptlogdir}" ]; then
  29. fn_script_log_error "Steam login not set. Using anonymous login."
  30. fi
  31. steamuser="anonymous"
  32. steampass=""
  33. sleep 2
  34. fi
  35. }
  36. fn_check_steamcmd_sh(){
  37. # Checks if SteamCMD exists when starting or updating a server.
  38. # Installs if missing.
  39. steamcmddir="${rootdir}/steamcmd"
  40. if [ ! -f "${steamcmddir}/steamcmd.sh" ]; then
  41. if [ "${function_selfname}" == "command_install.sh" ]; then
  42. fn_install_steamcmd
  43. else
  44. fn_print_error_nl "SteamCMD is missing"
  45. fn_script_log_error "SteamCMD is missing"
  46. sleep 1
  47. fn_install_steamcmd
  48. fi
  49. elif [ "${function_selfname}" == "command_install.sh" ]; then
  50. fn_print_infomation "SteamCMD is already installed..."
  51. fn_print_ok_eol_nl
  52. fi
  53. }
  54. fn_check_steamcmd_guard(){
  55. if [ "${function_selfname}" == "command_update.sh" ]||[ "${function_selfname}" == "command_validate.sh" ]; then
  56. # Checks that steamcmd is working correctly and will prompt Steam Guard if required.
  57. "${steamcmddir}"/steamcmd.sh +login "${steamuser}" "${steampass}" +quit
  58. if [ $? -ne 0 ]; then
  59. fn_print_failure_nl "Error running SteamCMD"
  60. fi
  61. fi
  62. }
  63. fn_check_steamcmd_user
  64. fn_check_steamcmd_sh
  65. # stdbuf has now replaced unbuffer. This shoudl no longer be required
  66. #fn_check_steamcmd_guard