fn_update_check 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. fn_scriptlog "Checking for update: Server logs"
  72. sleep 1
  73. requestrestart=$(grep -Ec "MasterRequestRestart" "${consolelog}")
  74. if [ "${requestrestart}" -ge "1" ]; then
  75. fn_printoknl "Checking for update: Server logs: Update requested"
  76. sleep 1
  77. echo ""
  78. echo -ne "Applying update.\r"
  79. sleep 1
  80. echo -ne "Applying update..\r"
  81. sleep 1
  82. echo -ne "Applying update...\r"
  83. sleep 1
  84. echo -ne "\n"
  85. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  86. if [ "${tmuxwc}" -eq 1 ]; then
  87. fn_stop
  88. fn_update_dl
  89. fn_start
  90. else
  91. fn_update_dl
  92. fi
  93. else
  94. fn_printok "Checking for update: Server logs: No update requested"
  95. sleep 1
  96. fi
  97. echo ""
  98. }
  99. fn_steamcmdcheck(){
  100. fn_check_steamcmd
  101. fn_check_steamuser
  102. fn_appmanifestcheck
  103. # Checks for server update from SteamCMD
  104. fn_printdots "Checking for update: SteamCMD"
  105. fn_scriptlog "Checking for update: SteamCMD"
  106. sleep 1
  107. # Gets currentbuild
  108. currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  109. # Gets availablebuild info
  110. cd "${rootdir}/steamcmd"
  111. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD
  112. if [ -f "${rootdor}/Steam/appcache/appinfo.vdf" ]; then
  113. rm -f "${rootdor}/Steam/appcache/appinfo.vdf"
  114. echo "yup"
  115. fi
  116. 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)
  117. if [ -z "${availablebuild}" ]; then
  118. fn_printfail "Checking for update: SteamCMD"
  119. fn_scriptlog "Failure! Checking for update: SteamCMD"
  120. sleep 1
  121. fn_printfail "Checking for update: SteamCMD: Not returning version info"
  122. fn_scriptlog "Failure! Checking for update: SteamCMD: Not returning version info"
  123. sleep 2
  124. exit
  125. else
  126. fn_printok "Checking for update: SteamCMD"
  127. fn_scriptlog "Success! Checking for update: SteamCMD"
  128. sleep 1
  129. fi
  130. if [ "${currentbuild}" -ne "${availablebuild}" ]; then
  131. echo -e "\n"
  132. echo -e "Update available:"
  133. sleep 1
  134. echo -e " Current build: \e[0;31m${currentbuild}\e[0;39m"
  135. echo -e " Available build: \e[0;32m${availablebuild}\e[0;39m"
  136. echo -e ""
  137. echo -e " https://steamdb.info/app/${appid}/"
  138. sleep 1
  139. echo ""
  140. echo -en "Applying update.\r"
  141. sleep 1
  142. echo -en "Applying update..\r"
  143. sleep 1
  144. echo -en "Applying update...\r"
  145. sleep 1
  146. echo -en "\n"
  147. fn_scriptlog "Update available"
  148. fn_scriptlog "Current build: ${currentbuild}"
  149. fn_scriptlog "Available build: ${availablebuild}"
  150. fn_scriptlog "${currentbuild} > ${availablebuild}"
  151. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  152. if [ "${tmuxwc}" -eq 1 ]; then
  153. fn_stop
  154. fn_update_dl
  155. fn_start
  156. else
  157. fn_update_dl
  158. fi
  159. else
  160. echo -e "\n"
  161. echo -e "No update available:"
  162. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  163. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  164. echo -e " https://steamdb.info/app/${appid}/"
  165. echo -e ""
  166. fn_printoknl "No update available"
  167. fn_scriptlog "Current build: ${currentbuild}"
  168. fn_scriptlog "Available build: ${availablebuild}"
  169. fi
  170. }
  171. ### END SteamCMD Update Checker ###
  172. fn_teamspeak3_check(){
  173. # Checks for server update from teamspeak.com using a mirror dl.4players.de
  174. fn_printdots "Checking for update: teamspeak.com"
  175. fn_scriptlog "Checking for update: teamspeak.com"
  176. sleep 1
  177. # Gets currentbuild info
  178. # Checks currentbuild info is available, if fails a server restart will be forced to generate logs
  179. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  180. fn_printfail "Checking for update: teamspeak.com"
  181. fn_scriptlog "Checking for update: teamspeak.com"
  182. sleep 1
  183. fn_printfailnl "Checking for update: teamspeak.com: No logs with server version found"
  184. fn_scriptlog "Failure! Checking for update: teamspeak.com: No logs with server version found"
  185. sleep 2
  186. fn_printinfonl "Checking for update: teamspeak.com: Forcing server restart"
  187. fn_scriptlog "Checking for update: teamspeak.com: Forcing server restart"
  188. sleep 2
  189. fn_stop
  190. fn_start
  191. sleep 2
  192. # If still failing will exit
  193. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  194. fn_printfailnl "Checking for update: teamspeak.com: Still No logs with server version found"
  195. fn_scriptlog "Failure! Checking for update: teamspeak.com: Still No logs with server version found"
  196. exit
  197. fi
  198. fi
  199. 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}')
  200. # Gets the teamspeak server architecture
  201. ts3arch=$(ls $(find ${filesdir}/ -name 'ts3server_*_*' 2> /dev/null | grep -v 'ts3server_minimal_runscript.sh' | sort | tail -1) | egrep -o '(amd64|x86)' | tail -1)
  202. # Gets availablebuild info
  203. # Grabs all version numbers not in correct order
  204. 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
  205. # removes digits to allow sorting of numbers
  206. cat .ts3_version_numbers_unsorted.tmp |tr -cd "[:digit:][*\n]" > .ts3_version_numbers_digit.tmp
  207. # Sorts numbers in to correct order
  208. # 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
  209. paste .ts3_version_numbers_digit.tmp .ts3_version_numbers_unsorted.tmp |sort -rn|awk '{ print $2 }' > .ts3_version_numbers.tmp
  210. # Finds directory with most recent server version.
  211. while read ts3_version_number; do
  212. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux-${ts3arch}-${ts3_version_number}.tar.gz"
  213. if [[ $? == 0 ]]; then
  214. availablebuild="${ts3_version_number}"
  215. # Break while-loop, if the latest release could be found
  216. break
  217. fi
  218. done < .ts3_version_numbers.tmp
  219. rm -f .ts3_version_numbers_digit.tmp
  220. rm -f .ts3_version_numbers_unsorted.tmp
  221. rm -f .ts3_version_numbers.tmp
  222. # Checks availablebuild info is available
  223. if [ -z "${availablebuild}" ]; then
  224. fn_printfail "Checking for update: teamspeak.com"
  225. fn_scriptlog "Checking for update: teamspeak.com"
  226. sleep 1
  227. fn_printfail "Checking for update: teamspeak.com: Not returning version info"
  228. fn_scriptlog "Failure! Checking for update: teamspeak.com: Not returning version info"
  229. sleep 2
  230. exit
  231. else
  232. fn_printok "Checking for update: teamspeak.com"
  233. fn_scriptlog "Success! Checking for update: teamspeak.com"
  234. sleep 1
  235. fi
  236. # Removes dots so if can compare version numbers
  237. currentbuilddigit=$(echo "${currentbuild}"|tr -cd "[:digit:]")
  238. availablebuilddigit=$(echo "${availablebuild}"|tr -cd "[:digit:]")
  239. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  240. echo -e "\n"
  241. echo -e "Update available:"
  242. sleep 1
  243. echo -e " Current build: \e[0;31m${currentbuild} ${architecture}\e[0;39m"
  244. echo -e " Available build: \e[0;32m${availablebuild} ${architecture}\e[0;39m"
  245. echo -e ""
  246. sleep 1
  247. echo ""
  248. echo -en "Applying update.\r"
  249. sleep 1
  250. echo -en "Applying update..\r"
  251. sleep 1
  252. echo -en "Applying update...\r"
  253. sleep 1
  254. echo -en "\n"
  255. fn_scriptlog "Update available"
  256. fn_scriptlog "Current build: ${currentbuild}"
  257. fn_scriptlog "Available build: ${availablebuild}"
  258. fn_scriptlog "${currentbuild} > ${availablebuild}"
  259. fn_check_ts3status
  260. if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ];then
  261. fn_update_dl
  262. fn_start
  263. sleep 5
  264. fn_stop
  265. else
  266. fn_stop
  267. fn_update_dl
  268. fn_start
  269. fi
  270. else
  271. echo -e "\n"
  272. echo -e "No update available:"
  273. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  274. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  275. echo -e ""
  276. fn_printoknl "No update available"
  277. fn_scriptlog "Current build: ${currentbuild}"
  278. fn_scriptlog "Available build: ${availablebuild}"
  279. fi
  280. }
  281. fn_check_logs
  282. fn_printdots "Checking for update"
  283. if [ "${gamename}" == "Teamspeak 3" ]; then
  284. fn_teamspeak3_check
  285. elif [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
  286. # Goldsource servers bypass checks as fn_steamcmdcheck does not work for appid 90 servers.
  287. # forceupdate bypasses checks
  288. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  289. if [ "${tmuxwc}" -eq 1 ]; then
  290. fn_stop
  291. fn_update_dl
  292. fn_start
  293. else
  294. fn_update_dl
  295. fi
  296. else
  297. fn_logupdaterequest
  298. fn_steamcmdcheck
  299. fi