update_check.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. #!/bin/bash
  2. # LGSM update_check.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="060516"
  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. unset updateonstart
  86. check_status.sh
  87. if [ "${status}" != "0" ]; 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. # set branch for updateinfo
  114. IFS=' ' read -a branchsplits <<< "${branch}"
  115. if [ "${#branchsplits[@]}" -gt 1 ]; then
  116. branchname="${branchsplits[1]}"
  117. else
  118. branchname="public"
  119. fi
  120. 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+\"${branchname}\"$" | grep -m 1 -EB 10 "^\s+}$" | grep -E "^\s+\"buildid\"\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  121. if [ -z "${availablebuild}" ]; then
  122. fn_print_fail "Checking for update: SteamCMD"
  123. fn_scriptlog "Failure! Checking for update: SteamCMD"
  124. sleep 1
  125. fn_print_fail_nl "Checking for update: SteamCMD: Not returning version info"
  126. fn_scriptlog "Failure! Checking for update: SteamCMD: Not returning version info"
  127. exit 1
  128. else
  129. fn_print_ok "Checking for update: SteamCMD"
  130. fn_scriptlog "Success! Checking for update: SteamCMD"
  131. sleep 1
  132. fi
  133. if [ "${currentbuild}" != "${availablebuild}" ]; then
  134. echo -e "\n"
  135. echo -e "Update available:"
  136. sleep 1
  137. echo -e " Current build: \e[0;31m${currentbuild}\e[0;39m"
  138. echo -e " Available build: \e[0;32m${availablebuild}\e[0;39m"
  139. echo -e ""
  140. echo -e " https://steamdb.info/app/${appid}/"
  141. sleep 1
  142. echo ""
  143. echo -en "Applying update.\r"
  144. sleep 1
  145. echo -en "Applying update..\r"
  146. sleep 1
  147. echo -en "Applying update...\r"
  148. sleep 1
  149. echo -en "\n"
  150. fn_scriptlog "Update available"
  151. fn_scriptlog "Current build: ${currentbuild}"
  152. fn_scriptlog "Available build: ${availablebuild}"
  153. fn_scriptlog "${currentbuild} > ${availablebuild}"
  154. unset updateonstart
  155. info_status.sh
  156. if [ "${status}" != "0" ]; then
  157. command_stop.sh
  158. update_dl.sh
  159. command_start.sh
  160. else
  161. update_dl.sh
  162. fi
  163. else
  164. echo -e "\n"
  165. echo -e "No update available:"
  166. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  167. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  168. echo -e " https://steamdb.info/app/${appid}/"
  169. echo -e ""
  170. fn_print_ok_nl "No update available"
  171. fn_scriptlog "Current build: ${currentbuild}"
  172. fn_scriptlog "Available build: ${availablebuild}"
  173. fi
  174. }
  175. ### END SteamCMD Update Checker ###
  176. fn_teamspeak3_check(){
  177. # Checks for server update from teamspeak.com using a mirror dl.4players.de
  178. fn_print_dots "Checking for update: teamspeak.com"
  179. fn_scriptlog "Checking for update: teamspeak.com"
  180. sleep 1
  181. # Gets currentbuild info
  182. # Checks currentbuild info is available, if fails a server restart will be forced to generate logs
  183. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  184. fn_print_fail "Checking for update: teamspeak.com"
  185. sleep 1
  186. fn_print_fail_nl "Checking for update: teamspeak.com: No logs with server version found"
  187. fn_scriptlog "Failure! Checking for update: teamspeak.com: No logs with server version found"
  188. sleep 2
  189. fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
  190. fn_scriptlog "Checking for update: teamspeak.com: Forcing server restart"
  191. sleep 2
  192. command_stop.sh
  193. command_start.sh
  194. sleep 2
  195. # If still failing will exit
  196. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  197. fn_print_fail_nl "Checking for update: teamspeak.com: Still No logs with server version found"
  198. fn_scriptlog "Failure! Checking for update: teamspeak.com: Still No logs with server version found"
  199. exit 1
  200. fi
  201. fi
  202. 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}')
  203. # Gets the teamspeak server architecture
  204. info_distro.sh
  205. if [ "${arch}" == "x86_64" ]; then
  206. ts3arch="amd64"
  207. elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then
  208. ts3arch="x86"
  209. else
  210. echo ""
  211. fn_print_failure "${arch} is an unsupported architecture"
  212. exit 1
  213. fi
  214. # Gets availablebuild info
  215. # Grabs all version numbers but not in correct order
  216. 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
  217. # Sort version numbers
  218. cat .ts3_version_numbers_unsorted.tmp | sort -r --version-sort -o .ts3_version_numbers_sorted.tmp
  219. # Finds directory with most recent server version.
  220. while read ts3_version_number; do
  221. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
  222. if [ $? -eq 0 ]; then
  223. availablebuild="${ts3_version_number}"
  224. # Break while-loop, if the latest release could be found
  225. break
  226. fi
  227. done < .ts3_version_numbers_sorted.tmp
  228. # Tidy up
  229. rm -f ".ts3_version_numbers_unsorted.tmp"
  230. rm -f ".ts3_version_numbers_sorted.tmp"
  231. # Checks availablebuild info is available
  232. if [ -z "${availablebuild}" ]; then
  233. fn_print_fail "Checking for update: teamspeak.com"
  234. fn_scriptlog "Checking for update: teamspeak.com"
  235. sleep 1
  236. fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
  237. fn_scriptlog "Failure! Checking for update: teamspeak.com: Not returning version info"
  238. sleep 2
  239. exit 1
  240. else
  241. fn_print_ok "Checking for update: teamspeak.com"
  242. fn_scriptlog "Success! Checking for update: teamspeak.com"
  243. sleep 1
  244. fi
  245. # Removes dots so if can compare version numbers
  246. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  247. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
  248. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  249. echo -e "\n"
  250. echo -e "Update available:"
  251. sleep 1
  252. echo -e " Current build: \e[0;31m${currentbuild} ${architecture}\e[0;39m"
  253. echo -e " Available build: \e[0;32m${availablebuild} ${architecture}\e[0;39m"
  254. echo -e ""
  255. sleep 1
  256. echo ""
  257. echo -en "Applying update.\r"
  258. sleep 1
  259. echo -en "Applying update..\r"
  260. sleep 1
  261. echo -en "Applying update...\r"
  262. sleep 1
  263. echo -en "\n"
  264. fn_scriptlog "Update available"
  265. fn_scriptlog "Current build: ${currentbuild}"
  266. fn_scriptlog "Available build: ${availablebuild}"
  267. fn_scriptlog "${currentbuild} > ${availablebuild}"
  268. unset updateonstart
  269. check_status.sh
  270. if [ "${status}" == "0" ]; then
  271. update_dl.sh
  272. command_start.sh
  273. sleep 5
  274. command_stop.sh
  275. else
  276. command_stop.sh
  277. update_dl.sh
  278. command_start.sh
  279. fi
  280. else
  281. echo -e "\n"
  282. echo -e "No update available:"
  283. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  284. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  285. echo -e ""
  286. fn_print_ok_nl "No update available"
  287. fn_scriptlog "Current build: ${currentbuild}"
  288. fn_scriptlog "Available build: ${availablebuild}"
  289. fi
  290. }
  291. check.sh
  292. fn_print_dots "Checking for update"
  293. if [ "${gamename}" == "Teamspeak 3" ]; then
  294. fn_teamspeak3_check
  295. elif [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
  296. # Goldsource servers bypass checks as fn_steamcmdcheck does not work for appid 90 servers.
  297. # forceupdate bypasses checks
  298. if [ "${status}" != "0" ]; then
  299. command_stop.sh
  300. update_dl.sh
  301. command_start.sh
  302. else
  303. update_dl.sh
  304. fi
  305. else
  306. fn_logupdaterequest
  307. fn_steamcmdcheck
  308. fi