4
0

fn_versioncheck 5.7 KB

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