fn_install_serverfiles 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # LGSM fn_install_serverfiles function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. # Version: 050515
  6. fn_steaminstallcommand(){
  7. if [ -z "${steamuser}" ]; then
  8. fn_printwarningnl "SteamCMD user variable is not assigned in the main script! Resorting to anonymous login"
  9. steamuser="anonymous"
  10. steampass=""
  11. fi
  12. counter="0"
  13. while [ "${counter}" == "0" ]||[ "$(grep -wc 0x402 .fn_install_serverfiles.tmp)" -ge "1" ]||[ "$(grep -wc 0x406 .fn_install_serverfiles.tmp)" -ge "1" ]||[ "$(grep -wc 0x6 .fn_install_serverfiles.tmp)" -ge "1" ]||[ "$(grep -wc 0x106 .fn_install_serverfiles.tmp)" -ge "1" ]; do
  14. counter=$((counter+1))
  15. if [ "${counter}" -le "10" ]; then
  16. # Attempt 1-4: Standard attempt
  17. # Attempt 5-6: Validate attempt
  18. # Attempt 7-8: Validate, delete long name dir
  19. # Attempt 9-10: Validate, delete long name dir, re-download SteamCMD
  20. # Attempt 11: Failure
  21. if [ "${counter}" -ge "2" ]; then
  22. fn_printwarningnl "SteamCMD did not complete the download, retrying: Attempt ${counter}:"
  23. fi
  24. if [ "${counter}" -ge "7" ]; then
  25. echo "Removing $(find ${filesdir} -type d -print0 | grep -Ez '[^/]{30}$')"
  26. find ${filesdir} -type d -print0 | grep -Ez '[^/]{30}$' | xargs -0 rm -rf
  27. fi
  28. if [ "${counter}" -ge "9" ]; then
  29. rm -rf "${rootdir}/steamcmd"
  30. fn_check_steamcmd
  31. fi
  32. # Detects if unbuffer command is available.
  33. if [ $(command -v unbuffer) ]; then
  34. unbuffer=unbuffer
  35. fi
  36. if [ "${counter}" -le "4" ]; then
  37. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_update "${appid}" +quit |tee .fn_install_serverfiles.tmp
  38. elif [ "${counter}" -ge "5" ]; then
  39. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_update "${appid}" -validate +quit |tee .fn_install_serverfiles.tmp
  40. fi
  41. elif [ "${counter}" -ge "11" ]; then
  42. fn_printfailurenl "SteamCMD did not complete the download, too many retrys"
  43. break
  44. fi
  45. done
  46. # Goldsource servers commonly fail to download all the server files required.
  47. # Validating a few of times may reduce the chance of this issue.
  48. if [ "${engine}" == "goldsource" ]; then
  49. counter="0"
  50. while [ "${counter}" -le "4" ]; do
  51. counter=$((counter+1))
  52. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_update "${appid}" -validate +quit |tee .fn_install_serverfiles.tmp
  53. done
  54. fi
  55. rm -f .fn_install_serverfiles.tmp
  56. }
  57. echo ""
  58. echo "Installing ${gamename} Server"
  59. echo "================================="
  60. sleep 1
  61. mkdir -pv "${filesdir}"
  62. cd "${rootdir}/steamcmd"
  63. fn_steaminstallcommand
  64. if [ -z "${autoinstall}" ]; then
  65. echo ""
  66. echo "================================="
  67. while true; do
  68. read -p "Was the install successful? [y/N]" yn
  69. case $yn in
  70. [Yy]* ) break;;
  71. [Nn]* ) fn_install_retry;;
  72. * ) echo "Please answer yes or no.";;
  73. esac
  74. done
  75. fi