fn_versioncheck 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #!/bin/bash
  2. # LGSM fn_versioncheck function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 010115
  6. # Description: Checks if a server update is available.
  7. modulename="Update"
  8. fn_steamcmdcheck(){
  9. # Checks for server update from SteamCMD
  10. fn_printdots "Checking for update: SteamCMD"
  11. fn_scriptlog "Checking for update: SteamCMD"
  12. installedversion=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  13. availableversion=$(steamcmd/steamcmd.sh +login "${steamuser}" "${steampass}" +app_info_print ${appid} +app_info_print ${appid} +quit | 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\ -f3)
  14. sleep 1
  15. if [ -z "${availableversion}" ]; then
  16. fn_printfail "Checking for update: SteamCMD"
  17. fn_scriptlog "Failure! Checking for update: SteamCMD"
  18. sleep 1
  19. fn_printfail "Checking for update: SteamCMD: Not returning version info"
  20. fn_scriptlog "Failure! Checking for update: SteamCMD: Not returning version info"
  21. sleep 2
  22. else
  23. fn_printok "Checking for update: SteamCMD"
  24. fn_scriptlog "Success! Checking for update: SteamCMD"
  25. sleep 1
  26. fi
  27. if [ -z "${availableversion}" ]; then
  28. # Checks for server update from SteamDB.info if SteamCMD fails
  29. echo ""
  30. fn_printdots "Checking for update: SteamDB.info"
  31. fn_scriptlog "Checking for update: SteamDB.info"
  32. 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)
  33. sleep 1
  34. if [ -z "${availableversion}" ]; then
  35. fn_printfail "Checking for update: SteamDB.info"
  36. fn_scriptlog "Failure! Checking for update: SteamDB.info"
  37. sleep 1
  38. fn_printfail "Checking for update: SteamDB.info: Not returning version info"
  39. fn_scriptlog "Failure! Checking for update: SteamDB.info: Not returning version info"
  40. sleep 2
  41. else
  42. fn_printok "Checking for update via SteamDB.info"
  43. fn_scriptlog "Success! Checking for update: SteamDB.info"
  44. sleep 1
  45. fi
  46. fi
  47. if [ -z "${availableversion}" ]; then
  48. fn_logupdaterequest
  49. fi
  50. if [ "${installedversion}" -ne "${availableversion}" ]; then
  51. echo -e "\n"
  52. echo -e "Update available:"
  53. sleep 1
  54. echo -e " Installed version: \e[0;31m${installedversion}\e[0;39m"
  55. echo -e " Available version: \e[0;32m${availableversion}\e[0;39m"
  56. echo -e ""
  57. echo -e " https://steamdb.info/app/${appid}/"
  58. sleep 1
  59. echo ""
  60. echo -en "Applying update.\r"
  61. sleep 1
  62. echo -en "Applying update..\r"
  63. sleep 1
  64. echo -en "Applying update...\r"
  65. sleep 1
  66. echo -en "\n"
  67. fn_scriptlog "Update available"
  68. if [ ! -z "${norestart}" ]; then
  69. fn_updateserver
  70. else
  71. fn_stopserver
  72. fn_updateserver
  73. fn_startserver
  74. fi
  75. else
  76. echo -e "\n"
  77. echo -e "No update available:"
  78. echo -e " Installed version: \e[0;32m${installedversion}\e[0;39m"
  79. echo -e " Available version: \e[0;32m${availableversion}\e[0;39m"
  80. echo -e " https://steamdb.info/app/${appid}/"
  81. echo -e ""
  82. fn_printok "No update available"
  83. fn_scriptlog "No update available"
  84. fi
  85. }
  86. fn_logupdaterequest(){
  87. # Checks for server update requests from server logs.
  88. echo ""
  89. fn_printdots "Checking server logs for update requests"
  90. sleep 1
  91. fn_printok "Checking server logs for update requests"
  92. fn_scriptlog "Checking server logs for update requests"
  93. sleep 1
  94. requestrestart=$(grep -sc "MasterRequestRestart" "${consolelog}")
  95. if [ "${requestrestart}" -ge "1" ]; then
  96. fn_printoknl "Server requesting update"
  97. sleep 1
  98. echo ""
  99. echo -ne "Applying update.\r"
  100. sleep 1
  101. echo -ne "Applying update..\r"
  102. sleep 1
  103. echo -ne "Applying update...\r"
  104. sleep 1
  105. echo -ne "\n"
  106. if [ ! -z "${norestart}" ]; then
  107. fn_updateserver
  108. else
  109. fn_stopserver
  110. fn_updateserver
  111. fn_startserver
  112. fi
  113. else
  114. fn_printok "No update request detected"
  115. sleep 1
  116. fi
  117. echo ""
  118. exit
  119. }
  120. fn_appmanifestinfo(){
  121. appmanifestfile=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf")
  122. appmanifestfilewc=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf"|wc -l)
  123. }
  124. fn_appmanifestcheck(){
  125. fn_appmanifestinfo
  126. # Multiple or no matching appmanifest files may sometimes be available.
  127. # This is an error is corrected below if required.
  128. if [ "${appmanifestfilewc}" -ge "2" ]; then
  129. sleep 1
  130. fn_printwarn "Multiple appmanifest_${appid}.acf files found"
  131. fn_scriptlog "Warning! Multiple appmanifest_${appid}.acf files found"
  132. sleep 2
  133. fn_printdots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  134. sleep 1
  135. for appfile in ${appmanifestfile}; do
  136. rm "${appfile}"
  137. done
  138. appmanifestfilewc1="${appmanifestfilewc}"
  139. fn_appmanifestinfo
  140. if [ "${appmanifestfilewc}" -ge "2" ]; then
  141. fn_printfail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  142. fn_scriptlog "Failure! Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  143. sleep 1
  144. echo ""
  145. echo " Check user permissions"
  146. for appfile in ${appmanifestfile}; do
  147. echo " ${appfile}"
  148. done
  149. exit
  150. else
  151. sleep 1
  152. fn_printok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  153. fn_scriptlog "Success! Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  154. sleep 1
  155. fn_printinfonl "Forcing update to correct issue"
  156. fn_scriptlog "Forcing update to correct issue"
  157. sleep 1
  158. fn_updateserver
  159. fn_versioncheck
  160. fi
  161. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  162. fn_printwarn "No appmanifest_${appid}.acf found"
  163. fn_scriptlog "Warning! No appmanifest_${appid}.acf found"
  164. sleep 2
  165. fn_printinfonl "Forcing update to correct issue"
  166. fn_scriptlog "Forcing update to correct issue"
  167. sleep 1
  168. fn_updateserver
  169. fn_logupdaterequest
  170. fi
  171. }
  172. fn_printdots "Checking for update"
  173. fn_appmanifestcheck
  174. fn_steamcmdcheck