fn_update_check 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. #!/bin/bash
  2. # LGSM fn_update_check function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. # Version: 190515
  6. # Description: Checks if a server update is available.
  7. local modulename="Update"
  8. ### SteamCMD Update Checker ###
  9. fn_appmanifestinfo(){
  10. appmanifestfile=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf")
  11. appmanifestfilewc=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf"|wc -l)
  12. }
  13. fn_appmanifestcheck(){
  14. fn_appmanifestinfo
  15. # Multiple or no matching appmanifest files may sometimes be available.
  16. # This is an error is corrected below if required.
  17. if [ "${appmanifestfilewc}" -ge "2" ]; then
  18. sleep 1
  19. fn_printwarn "Multiple appmanifest_${appid}.acf files found"
  20. fn_scriptlog "Warning! Multiple appmanifest_${appid}.acf files found"
  21. sleep 2
  22. fn_printdots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  23. sleep 1
  24. for appfile in ${appmanifestfile}; do
  25. rm "${appfile}"
  26. done
  27. appmanifestfilewc1="${appmanifestfilewc}"
  28. fn_appmanifestinfo
  29. if [ "${appmanifestfilewc}" -ge "2" ]; then
  30. fn_printfail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  31. fn_scriptlog "Failure! Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  32. sleep 1
  33. echo ""
  34. echo " Check user permissions"
  35. for appfile in ${appmanifestfile}; do
  36. echo " ${appfile}"
  37. done
  38. exit
  39. else
  40. sleep 1
  41. fn_printok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  42. fn_scriptlog "Success! Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  43. sleep 1
  44. fn_printinfonl "Forcing update to correct issue"
  45. fn_scriptlog "Forcing update to correct issue"
  46. sleep 1
  47. fn_update_dl
  48. fn_update_check
  49. fi
  50. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  51. if [ "${forceupdate}" -eq "1" ]; then
  52. fn_printfail "Still no appmanifest_${appid}.acf found: Unable to update"
  53. fn_scriptlog "Warning! Still no appmanifest_${appid}.acf found: Unable to update"
  54. exit
  55. fi
  56. forceupdate=1
  57. fn_printwarn "No appmanifest_${appid}.acf found"
  58. fn_scriptlog "Warning! No appmanifest_${appid}.acf found"
  59. sleep 2
  60. fn_printinfonl "Forcing update to correct issue"
  61. fn_scriptlog "Forcing update to correct issue"
  62. sleep 1
  63. fn_update_dl
  64. fn_update_check
  65. fi
  66. }
  67. fn_logupdaterequest(){
  68. # Checks for server update requests from server logs.
  69. echo ""
  70. fn_printdots "Checking for update: Server logs"
  71. sleep 1
  72. fn_printok "Checking for update: Server logs"
  73. fn_scriptlog "Checking for update: Server logs"
  74. sleep 1
  75. requestrestart=$(grep -Ec "MasterRequestRestart" "${consolelog}")
  76. echo "${requestrestart}"
  77. if [ "${requestrestart}" -ge "1" ]; then
  78. fn_printoknl "Server requesting update"
  79. sleep 1
  80. echo ""
  81. echo -ne "Applying update.\r"
  82. sleep 1
  83. echo -ne "Applying update..\r"
  84. sleep 1
  85. echo -ne "Applying update...\r"
  86. sleep 1
  87. echo -ne "\n"
  88. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  89. if [ "${tmuxwc}" -eq 1 ]; then
  90. fn_stop
  91. fn_update_dl
  92. fn_start
  93. else
  94. fn_update_dl
  95. fi
  96. else
  97. fn_printok "Checking for update: Server logs: No update requested"
  98. sleep 1
  99. fi
  100. echo ""
  101. }
  102. fn_steamcmdcheck(){
  103. fn_check_steamcmd
  104. fn_check_steamuser
  105. fn_appmanifestcheck
  106. # Checks for server update from SteamCMD
  107. fn_printdots "Checking for update: SteamCMD"
  108. fn_scriptlog "Checking for update: SteamCMD"
  109. sleep 1
  110. # Gets currentbuild
  111. currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  112. # Gets availablebuild info
  113. cd "${rootdir}/steamcmd"
  114. availablebuild=$(./steamcmd.sh +login "${steamuser}" "${steampass}" +app_info_update 1 +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)
  115. if [ -z "${availablebuild}" ]; then
  116. fn_printfail "Checking for update: SteamCMD"
  117. fn_scriptlog "Failure! Checking for update: SteamCMD"
  118. sleep 1
  119. fn_printfail "Checking for update: SteamCMD: Not returning version info"
  120. fn_scriptlog "Failure! Checking for update: SteamCMD: Not returning version info"
  121. sleep 2
  122. else
  123. fn_printok "Checking for update: SteamCMD"
  124. fn_scriptlog "Success! Checking for update: SteamCMD"
  125. sleep 1
  126. fi
  127. if [ "${currentbuild}" -ne "${availablebuild}" ]; then
  128. echo -e "\n"
  129. echo -e "Update available:"
  130. sleep 1
  131. echo -e " Current build: \e[0;31m${currentbuild}\e[0;39m"
  132. echo -e " Available build: \e[0;32m${availablebuild}\e[0;39m"
  133. echo -e ""
  134. echo -e " https://steamdb.info/app/${appid}/"
  135. sleep 1
  136. echo ""
  137. echo -en "Applying update.\r"
  138. sleep 1
  139. echo -en "Applying update..\r"
  140. sleep 1
  141. echo -en "Applying update...\r"
  142. sleep 1
  143. echo -en "\n"
  144. fn_scriptlog "Update available"
  145. fn_scriptlog "Current build: ${currentbuild}"
  146. fn_scriptlog "Available build: ${availablebuild}"
  147. fn_scriptlog "${currentbuild} > ${availablebuild}"
  148. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  149. if [ "${tmuxwc}" -eq 1 ]; then
  150. fn_stop
  151. fn_update_dl
  152. fn_start
  153. else
  154. fn_update_dl
  155. fi
  156. else
  157. echo -e "\n"
  158. echo -e "No update available:"
  159. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  160. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  161. echo -e " https://steamdb.info/app/${appid}/"
  162. echo -e ""
  163. fn_printoknl "No update available"
  164. fn_scriptlog "Current build: ${currentbuild}"
  165. fn_scriptlog "Available build: ${availablebuild}"
  166. fi
  167. }
  168. ### END SteamCMD Update Checker ###
  169. fn_teamspeak3_check(){
  170. # Checks for server update from teamspeak.com using a mirror dl.4players.de
  171. fn_printdots "Checking for update: teamspeak.com"
  172. fn_scriptlog "Checking for update: teamspeak.com"
  173. sleep 1
  174. # Gets currentbuild info
  175. # Checks currentbuild info is available, if fails a server restart will be forced to generate logs
  176. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  177. fn_printfail "Checking for update: teamspeak.com"
  178. fn_scriptlog "Checking for update: teamspeak.com"
  179. sleep 1
  180. fn_printfailnl "Checking for update: teamspeak.com: No logs with server version found"
  181. fn_scriptlog "Failure! Checking for update: teamspeak.com: No logs with server version found"
  182. sleep 2
  183. fn_printinfonl "Checking for update: teamspeak.com: Forcing server restart"
  184. fn_scriptlog "Checking for update: teamspeak.com: Forcing server restart"
  185. sleep 2
  186. fn_stop
  187. fn_start
  188. sleep 2
  189. # If still failing will exit
  190. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  191. fn_printfailnl "Checking for update: teamspeak.com: Still No logs with server version found"
  192. fn_scriptlog "Failure! Checking for update: teamspeak.com: Still No logs with server version found"
  193. exit
  194. fi
  195. fi
  196. currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | egrep -E -v '${rootdir}/.ts3version' | tail -1) | egrep -o 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}')
  197. # Gets the teamspeak server architecture
  198. ts3arch=$(ls $(find ${filesdir}/ -name 'ts3server_*_*' 2> /dev/null | grep -v 'ts3server_minimal_runscript.sh' | sort | tail -1) | egrep -o '(amd64|x86)' | tail -1)
  199. # Gets availablebuild info
  200. # Grabs all version numbers not in correct order
  201. wget "http://dl.4players.de/ts/releases/?C=M;O=D" -q -O -| grep -i dir | egrep -o '<a href=\".*\/\">.*\/<\/a>' | egrep -o '[0-9\.?]+'|uniq > .ts3_version_numbers_unsorted.tmp
  202. # removes digits to allow sorting of numbers
  203. cat .ts3_version_numbers_unsorted.tmp |tr -cd "[:digit:][*\n]" > .ts3_version_numbers_digit.tmp
  204. # Sorts numbers in to correct order
  205. # merges two files in to one with two columns sorts the numbers in to order then only outputs the second to the ts3_version_numbers.tmp
  206. paste .ts3_version_numbers_digit.tmp .ts3_version_numbers_unsorted.tmp |sort -rn|awk '{ print $2 }' > .ts3_version_numbers.tmp
  207. # Finds directory with most recent server version.
  208. while read ts3_version_number; do
  209. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux-${ts3arch}-${ts3_version_number}.tar.gz"
  210. if [[ $? == 0 ]]; then
  211. availablebuild="${ts3_version_number}"
  212. # Break while-loop, if the latest release could be found
  213. break
  214. fi
  215. done < .ts3_version_numbers.tmp
  216. rm -f .ts3_version_numbers_digit.tmp
  217. rm -f .ts3_version_numbers_unsorted.tmp
  218. rm -f .ts3_version_numbers.tmp
  219. # Checks availablebuild info is available
  220. if [ -z "${availablebuild}" ]; then
  221. fn_printfail "Checking for update: teamspeak.com"
  222. fn_scriptlog "Checking for update: teamspeak.com"
  223. sleep 1
  224. fn_printfail "Checking for update: teamspeak.com: Not returning version info"
  225. fn_scriptlog "Failure! Checking for update: teamspeak.com: Not returning version info"
  226. sleep 2
  227. exit
  228. else
  229. fn_printok "Checking for update: teamspeak.com"
  230. fn_scriptlog "Success! Checking for update: teamspeak.com"
  231. sleep 1
  232. fi
  233. # Removes dots so if can compare version numbers
  234. currentbuilddigit=$(echo "${currentbuild}"|tr -cd "[:digit:]")
  235. availablebuilddigit=$(echo "${availablebuild}"|tr -cd "[:digit:]")
  236. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  237. echo -e "\n"
  238. echo -e "Update available:"
  239. sleep 1
  240. echo -e " Current build: \e[0;31m${currentbuild} ${architecture}\e[0;39m"
  241. echo -e " Available build: \e[0;32m${availablebuild} ${architecture}\e[0;39m"
  242. echo -e ""
  243. sleep 1
  244. echo ""
  245. echo -en "Applying update.\r"
  246. sleep 1
  247. echo -en "Applying update..\r"
  248. sleep 1
  249. echo -en "Applying update...\r"
  250. sleep 1
  251. echo -en "\n"
  252. fn_scriptlog "Update available"
  253. fn_scriptlog "Current build: ${currentbuild}"
  254. fn_scriptlog "Available build: ${availablebuild}"
  255. fn_scriptlog "${currentbuild} > ${availablebuild}"
  256. fn_check_ts3status
  257. if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ];then
  258. fn_update_dl
  259. fn_start
  260. sleep 5
  261. fn_stop
  262. else
  263. fn_stop
  264. fn_update_dl
  265. fn_start
  266. fi
  267. else
  268. echo -e "\n"
  269. echo -e "No update available:"
  270. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  271. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  272. echo -e ""
  273. fn_printoknl "No update available"
  274. fn_scriptlog "Current build: ${currentbuild}"
  275. fn_scriptlog "Available build: ${availablebuild}"
  276. fi
  277. }
  278. fn_printdots "Checking for update"
  279. if [ "${gamename}" == "Teamspeak 3" ]; then
  280. fn_teamspeak3_check
  281. elif [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
  282. # Goldsource servers bypass checks as fn_steamcmdcheck does not work for appid 90 servers.
  283. # forceupdate bypasses checks
  284. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  285. if [ "${tmuxwc}" -eq 1 ]; then
  286. fn_stop
  287. fn_update_dl
  288. fn_start
  289. else
  290. fn_update_dl
  291. fi
  292. else
  293. fn_logupdaterequest
  294. fn_steamcmdcheck
  295. fi