fn_versioncheck 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "\n"
  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/${appid}/"
  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. if [ ! -z "${norestart}" ]; then
  37. fn_updateserver
  38. else
  39. fn_stopserver
  40. fn_updateserver
  41. fn_startserver
  42. fi
  43. else
  44. fn_printok "Checking ${servicename}: Checking for updates via steamdb.info"
  45. sleep 1
  46. echo -e "\n"
  47. echo -e "No update available:"
  48. echo -e " Installed version: \e[0;32m${installedversion}\e[0;39m"
  49. echo -e " Available version: \e[0;32m${availableversion}\e[0;39m"
  50. echo -e " https://steamdb.info/app/${appid}/"
  51. echo -e ""
  52. fi
  53. }
  54. fn_logupdaterequest(){
  55. # Checks for server update from server logs.
  56. fn_printdots "Checking ${servicename}: Checking logs for update requests"
  57. sleep 1
  58. requestrestart=$(grep -sc "MasterRequestRestart" "${consolelog}")
  59. if [ "${requestrestart}" -ge "1" ]; then
  60. fn_printok "Checking ${servicename}: Checking logs for update requests"
  61. sleep 1
  62. fn_printoknl "Checking ${servicename}: Server requesting update"
  63. if [ ! -z "${norestart}" ]; then
  64. fn_updateserver
  65. else
  66. fn_stopserver
  67. fn_updateserver
  68. fn_startserver
  69. fi
  70. else
  71. fn_printok "Checking ${servicename}: Checking logs for update requests"
  72. sleep 1
  73. fn_printok "Checking ${servicename}: No update request detected"
  74. sleep 1
  75. echo ""
  76. fi
  77. }
  78. fn_appmanifestinfo(){
  79. appmanifestfile=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf")
  80. appmanifestfilewc=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf"|wc -l)
  81. }
  82. fn_appmanifestcheck(){
  83. fn_appmanifestinfo
  84. # Multiple matching appmanifest files may sometimes be present.
  85. # This is an error is corrected below if required.
  86. if [ "${appmanifestfilewc}" -ge "2" ]; then
  87. sleep 1
  88. fn_printwarn "Checking ${servicename}: Multiple appmanifest_${appid}.acf files found"
  89. sleep 2
  90. fn_printdots "Checking ${servicename}: Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  91. sleep 1
  92. for appfile in ${appmanifestfile}; do
  93. rm "${appfile}"
  94. done
  95. appmanifestfilewc1="${appmanifestfilewc}"
  96. fn_appmanifestinfo
  97. if [ "${appmanifestfilewc}" -ge "2" ]; then
  98. fn_printfail "Checking ${servicename}: Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  99. sleep 1
  100. echo ""
  101. echo " Check user permissions"
  102. for appfile in ${appmanifestfile}; do
  103. echo " ${appfile}"
  104. done
  105. exit
  106. else
  107. sleep 1
  108. fn_printok "Checking ${servicename}: Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  109. sleep 1
  110. fn_printinfonl "Checking ${servicename}: Forcing update to correct issue"
  111. sleep 1
  112. fn_updateserver
  113. fn_versioncheck
  114. fi
  115. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  116. fn_printwarn "Checking ${servicename}: No appmanifest_${appid}.acf found"
  117. sleep 2
  118. fn_printinfonl "Checking ${servicename}: Forcing update to correct issue"
  119. sleep 1
  120. fn_updateserver
  121. fn_logupdaterequest
  122. fi
  123. }
  124. fn_printdots "Checking ${servicename}: Checking for updates"
  125. fn_appmanifestcheck
  126. fn_steamdbcheck