fn_versioncheck 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/bash
  2. # LGSM fn_versioncheck function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 191214
  6. fn_steamdbcheck(){
  7. # Checks for server update from SteamDB.info API.
  8. fn_printdots "Checking ${servicename}: Checking for updates via steamdb.info"
  9. installedversion=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  10. availableversion=$(wget -qO- "http://steamdb.info/api/GetRawDepots/?appid=${appid}" | sed 's/\\n/\n/g' | grep -EA 1000 "^\s+\[branches\]" | grep -EA 5 "^\s+\[public\]" | grep -m 1 -EB 10 "^\s+\)$" | grep -E "^\s+\[buildid\]\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f4)
  11. sleep 1
  12. if [ -z "${availableversion}" ]; then
  13. fn_printfail "Checking ${servicename}: steamdb.info not returning version info"
  14. sleep 1
  15. echo ""
  16. fn_logupdaterequest
  17. elif [ "${installedversion}" -ne "${availableversion}" ]; then
  18. fn_printok "Checking ${servicename}: Checking for updates via steamdb.info"
  19. sleep 1
  20. echo -e ""
  21. echo -e "Update available:"
  22. sleep 1
  23. echo -e " Installed version: \e[0;31m${installedversion}\e[0;39m"
  24. echo -e " Available version: \e[0;32m${availableversion}\e[0;39m"
  25. echo -e ""
  26. echo -e " https://steamdb.info/app/261140/"
  27. sleep 1
  28. echo ""
  29. echo -ne "Applying update.\r"
  30. sleep 1
  31. echo -ne "Applying update..\r"
  32. sleep 1
  33. echo -ne "Applying update...\r"
  34. sleep 1
  35. echo -ne "\n"
  36. fn_stopserver
  37. fn_updateserver
  38. else
  39. fn_printok "Checking ${servicename}: Checking for updates via steamdb.info"
  40. sleep 1
  41. echo -e "\n"
  42. echo -e "No update available:"
  43. echo -e " Installed version: \e[0;32m${installedversion}\e[0;39m"
  44. echo -e " Available version: \e[0;32m${availableversion}\e[0;39m"
  45. echo -e " https://steamdb.info/app/261140/"
  46. echo -e ""
  47. fi
  48. }
  49. fn_logupdaterequest(){
  50. # Checks for server update from server logs.
  51. fn_printdots "Checking ${servicename}: Checking logs for update requests"
  52. sleep 1
  53. requestrestart=$(grep -sc "MasterRequestRestart" "${consolelog}")
  54. if [ "${requestrestart}" -ge "1" ]; then
  55. fn_printok "Checking ${servicename}: Checking logs for update requests"
  56. sleep 1
  57. fn_printoknl "Checking ${servicename}: Server requesting update"
  58. fn_stopserver
  59. fn_updateserver
  60. else
  61. fn_printok "Checking ${servicename}: Checking logs for update requests"
  62. sleep 1
  63. fn_printok "Checking ${servicename}: No update request detected"
  64. sleep 1
  65. echo ""
  66. fi
  67. }
  68. fn_appmanifestinfo(){
  69. appmanifestfile=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf")
  70. appmanifestfilewc=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf"|wc -l)
  71. }
  72. fn_appmanifestcheck(){
  73. fn_appmanifestinfo
  74. # Multiple matching appmanifest files may sometimes be present.
  75. # This is an error is corrected below if required.
  76. if [ "${appmanifestfilewc}" -ge "2" ]; then
  77. sleep 1
  78. fn_printwarn "Checking ${servicename}: Multiple appmanifest_${appid}.acf files found"
  79. sleep 2
  80. fn_printdots "Checking ${servicename}: Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  81. sleep 1
  82. for appfile in ${appmanifestfile}; do
  83. rm "${appfile}"
  84. done
  85. appmanifestfilewc1="${appmanifestfilewc}"
  86. fn_appmanifestinfo
  87. if [ "${appmanifestfilewc}" -ge "2" ]; then
  88. fn_printfail "Checking ${servicename}: Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  89. sleep 1
  90. echo ""
  91. echo " Check user permissions"
  92. for appfile in ${appmanifestfile}; do
  93. echo " ${appfile}"
  94. done
  95. exit
  96. else
  97. sleep 1
  98. fn_printok "Checking ${servicename}: Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  99. sleep 1
  100. fn_printinfonl "Checking ${servicename}: Forcing update to correct issue"
  101. sleep 1
  102. fn_updateserver
  103. fn_versioncheck
  104. fi
  105. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  106. fn_printwarn "Checking ${servicename}: No appmanifest_${appid}.acf found"
  107. sleep 2
  108. fn_printinfonl "Checking ${servicename}: Forcing update to correct issue"
  109. sleep 1
  110. fn_updateserver
  111. fn_logupdaterequest
  112. fi
  113. }
  114. fn_printdots "Checking ${servicename}: Checking for updates"
  115. fn_appmanifestcheck
  116. fn_steamdbcheck