update_check.sh 11 KB

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