update_check.sh 11 KB

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