update_check.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #!/bin/bash
  2. # LGSM update_check.sh function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. lgsm_version="060216"
  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_print_warn "Multiple appmanifest_${appid}.acf files found"
  21. fn_scriptlog "Warning! Multiple appmanifest_${appid}.acf files found"
  22. sleep 2
  23. fn_print_dots "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_print_fail "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_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  43. fn_scriptlog "Success! Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  44. sleep 1
  45. fn_print_info_nl "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_print_fail "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_print_warn "No appmanifest_${appid}.acf found"
  59. fn_scriptlog "Warning! No appmanifest_${appid}.acf found"
  60. sleep 2
  61. fn_print_info_nl "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_print_dots "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_print_ok_nl "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. unset updateonstart
  87. if [ "${tmuxwc}" -eq 1 ]; then
  88. command_stop.sh
  89. update_dl.sh
  90. command_start.sh
  91. else
  92. update_dl.sh
  93. fi
  94. else
  95. fn_print_ok "Checking for update: Server logs: No update requested"
  96. sleep 1
  97. fi
  98. }
  99. fn_steamcmdcheck(){
  100. fn_appmanifestcheck
  101. # Checks for server update from SteamCMD
  102. fn_print_dots "Checking for update: SteamCMD"
  103. fn_scriptlog "Checking for update: SteamCMD"
  104. sleep 1
  105. # Gets currentbuild
  106. currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  107. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD
  108. # Gets availablebuild info
  109. cd "${rootdir}/steamcmd"
  110. if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then
  111. rm -f "${HOME}/Steam/appcache/appinfo.vdf"
  112. fi
  113. 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)
  114. if [ -z "${availablebuild}" ]; then
  115. fn_print_fail "Checking for update: SteamCMD"
  116. fn_scriptlog "Failure! Checking for update: SteamCMD"
  117. sleep 1
  118. fn_print_fail_nl "Checking for update: SteamCMD: Not returning version info"
  119. fn_scriptlog "Failure! Checking for update: SteamCMD: Not returning version info"
  120. exit 1
  121. else
  122. fn_print_ok "Checking for update: SteamCMD"
  123. fn_scriptlog "Success! Checking for update: SteamCMD"
  124. sleep 1
  125. fi
  126. if [ "${currentbuild}" != "${availablebuild}" ]; then
  127. echo -e "\n"
  128. echo -e "Update available:"
  129. sleep 1
  130. echo -e " Current build: \e[0;31m${currentbuild}\e[0;39m"
  131. echo -e " Available build: \e[0;32m${availablebuild}\e[0;39m"
  132. echo -e ""
  133. echo -e " https://steamdb.info/app/${appid}/"
  134. sleep 1
  135. echo ""
  136. echo -en "Applying update.\r"
  137. sleep 1
  138. echo -en "Applying update..\r"
  139. sleep 1
  140. echo -en "Applying update...\r"
  141. sleep 1
  142. echo -en "\n"
  143. fn_scriptlog "Update available"
  144. fn_scriptlog "Current build: ${currentbuild}"
  145. fn_scriptlog "Available build: ${availablebuild}"
  146. fn_scriptlog "${currentbuild} > ${availablebuild}"
  147. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  148. unset updateonstart
  149. if [ "${tmuxwc}" -eq 1 ]; then
  150. command_stop.sh
  151. update_dl.sh
  152. command_start.sh
  153. else
  154. update_dl.sh
  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_print_ok_nl "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_print_dots "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_print_fail "Checking for update: teamspeak.com"
  178. sleep 1
  179. fn_print_fail_nl "Checking for update: teamspeak.com: No logs with server version found"
  180. fn_scriptlog "Failure! Checking for update: teamspeak.com: No logs with server version found"
  181. sleep 2
  182. fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
  183. fn_scriptlog "Checking for update: teamspeak.com: Forcing server restart"
  184. sleep 2
  185. command_stop.sh
  186. command_start.sh
  187. sleep 2
  188. # If still failing will exit
  189. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  190. fn_print_fail_nl "Checking for update: teamspeak.com: Still No logs with server version found"
  191. fn_scriptlog "Failure! Checking for update: teamspeak.com: Still No logs with server version found"
  192. exit 1
  193. fi
  194. fi
  195. 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}')
  196. # Gets the teamspeak server architecture
  197. info_distro.sh
  198. if [ "${arch}" == "x86_64" ]; then
  199. ts3arch="amd64"
  200. elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then
  201. ts3arch="x86"
  202. else
  203. echo ""
  204. fn_print_failure "${arch} is an unsupported architecture"
  205. exit 1
  206. fi
  207. # Gets availablebuild info
  208. # Grabs all version numbers but not in correct order
  209. 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
  210. # Replaces dots with spaces to split up the number. e.g 3 0 12 1 is 3.0.12.1 this allows correct sorting
  211. cat .ts3_version_numbers_unsorted.tmp | tr "." " " > .ts3_version_numbers_digit.tmp
  212. # Sorts versions in to correct order
  213. # merges 2 files and orders by each column in order allowing these version numbers to be sorted in order
  214. 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
  215. # Finds directory with most recent server version.
  216. while read ts3_version_number; do
  217. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
  218. if [ $? -eq 0 ]; then
  219. availablebuild="${ts3_version_number}"
  220. # Break while-loop, if the latest release could be found
  221. break
  222. fi
  223. done < .ts3_version_numbers.tmp
  224. # tidy up
  225. rm -f ".ts3_version_numbers_digit.tmp"
  226. rm -f ".ts3_version_numbers_unsorted.tmp"
  227. rm -f ".ts3_version_numbers.tmp"
  228. # Checks availablebuild info is available
  229. if [ -z "${availablebuild}" ]; then
  230. fn_print_fail "Checking for update: teamspeak.com"
  231. fn_scriptlog "Checking for update: teamspeak.com"
  232. sleep 1
  233. fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
  234. fn_scriptlog "Failure! Checking for update: teamspeak.com: Not returning version info"
  235. sleep 2
  236. exit 1
  237. else
  238. fn_print_ok "Checking for update: teamspeak.com"
  239. fn_scriptlog "Success! Checking for update: teamspeak.com"
  240. sleep 1
  241. fi
  242. # Removes dots so if can compare version numbers
  243. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  244. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
  245. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  246. echo -e "\n"
  247. echo -e "Update available:"
  248. sleep 1
  249. echo -e " Current build: \e[0;31m${currentbuild} ${architecture}\e[0;39m"
  250. echo -e " Available build: \e[0;32m${availablebuild} ${architecture}\e[0;39m"
  251. echo -e ""
  252. sleep 1
  253. echo ""
  254. echo -en "Applying update.\r"
  255. sleep 1
  256. echo -en "Applying update..\r"
  257. sleep 1
  258. echo -en "Applying update...\r"
  259. sleep 1
  260. echo -en "\n"
  261. fn_scriptlog "Update available"
  262. fn_scriptlog "Current build: ${currentbuild}"
  263. fn_scriptlog "Available build: ${availablebuild}"
  264. fn_scriptlog "${currentbuild} > ${availablebuild}"
  265. unset updateonstart
  266. info_ts3status.sh
  267. if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ]; then
  268. update_dl.sh
  269. command_start.sh
  270. sleep 5
  271. command_stop.sh
  272. else
  273. command_stop.sh
  274. update_dl.sh
  275. command_start.sh
  276. fi
  277. else
  278. echo -e "\n"
  279. echo -e "No update available:"
  280. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  281. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  282. echo -e ""
  283. fn_print_ok_nl "No update available"
  284. fn_scriptlog "Current build: ${currentbuild}"
  285. fn_scriptlog "Available build: ${availablebuild}"
  286. fi
  287. }
  288. check.sh
  289. fn_print_dots "Checking for update"
  290. if [ "${gamename}" == "Teamspeak 3" ]; then
  291. fn_teamspeak3_check
  292. elif [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
  293. # Goldsource servers bypass checks as fn_steamcmdcheck does not work for appid 90 servers.
  294. # forceupdate bypasses checks
  295. tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
  296. if [ "${tmuxwc}" -eq 1 ]; then
  297. command_stop.sh
  298. update_dl.sh
  299. command_start.sh
  300. else
  301. update_dl.sh
  302. fi
  303. else
  304. fn_logupdaterequest
  305. fn_steamcmdcheck
  306. fi