fn_versioncheck 5.8 KB

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