update_check.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. #!/bin/bash
  2. # LGSM update_check.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Checks if a server update is available.
  6. local commandnane="UPDATE"
  7. local commandaction="Update"
  8. local 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_script_log_warn "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_script_log_fatal "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_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  44. sleep 1
  45. fn_print_info_nl "Forcing update to correct issue"
  46. fn_script_log_info "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_script_log_fatal "Still no appmanifest_${appid}.acf found: Unable to update"
  55. core_exit.sh
  56. fi
  57. forceupdate=1
  58. fn_print_warn "No appmanifest_${appid}.acf found"
  59. fn_script_log_warn "No appmanifest_${appid}.acf found"
  60. sleep 2
  61. fn_print_info_nl "Forcing update to correct issue"
  62. fn_script_log_warn "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_script_log_info "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_script_log_info "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_script_log_fatal "Checking for update: SteamCMD"
  126. sleep 1
  127. fn_print_fail_nl "Checking for update: SteamCMD: Not returning version info"
  128. fn_script_log_fatal "Checking for update: SteamCMD: Not returning version info"
  129. core_exit.sh
  130. else
  131. fn_print_ok "Checking for update: SteamCMD"
  132. fn_script_log_pass "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: ${red}${currentbuild}${default}"
  140. echo -e " Available build: ${green}${availablebuild}${default}"
  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_script_log "Update available"
  153. fn_script_log "Current build: ${currentbuild}"
  154. fn_script_log "Available build: ${availablebuild}"
  155. fn_script_log "${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: ${green}${currentbuild}${default}"
  171. echo -e " Available version: ${green}${availablebuild}${default}"
  172. echo -e " https://steamdb.info/app/${appid}/"
  173. echo -e ""
  174. fn_print_ok_nl "No update available"
  175. fn_script_log "Current build: ${currentbuild}"
  176. fn_script_log "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_script_log_info "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_script_log_error "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_script_log_info "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_script_log_fatal "Checking for update: teamspeak.com: Still No logs with server version found"
  203. core_exit.sh
  204. else
  205. exitcode=0
  206. fi
  207. fi
  208. 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}')
  209. # Gets the teamspeak server architecture
  210. info_distro.sh
  211. if [ "${arch}" == "x86_64" ]; then
  212. ts3arch="amd64"
  213. elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then
  214. ts3arch="x86"
  215. else
  216. echo ""
  217. fn_print_failure "${arch} is an unsupported architecture"
  218. exit 1
  219. fi
  220. # Gets availablebuild info
  221. # Grabs all version numbers but not in correct order
  222. 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
  223. # Sort version numbers
  224. cat .ts3_version_numbers_unsorted.tmp | sort -r --version-sort -o .ts3_version_numbers_sorted.tmp
  225. # Finds directory with most recent server version.
  226. while read ts3_version_number; do
  227. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
  228. if [ $? -eq 0 ]; then
  229. availablebuild="${ts3_version_number}"
  230. # Break while-loop, if the latest release could be found
  231. break
  232. fi
  233. done < .ts3_version_numbers_sorted.tmp
  234. # Tidy up
  235. rm -f ".ts3_version_numbers_unsorted.tmp"
  236. rm -f ".ts3_version_numbers_sorted.tmp"
  237. # Checks availablebuild info is available
  238. if [ -z "${availablebuild}" ]; then
  239. fn_print_fail "Checking for update: teamspeak.com"
  240. sleep 1
  241. fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
  242. fn_script_log_fatal "Failure! Checking for update: teamspeak.com: Not returning version info"
  243. sleep 1
  244. core_exit.sh
  245. else
  246. fn_print_ok "Checking for update: teamspeak.com"
  247. fn_script_log_pass "Checking for update: teamspeak.com"
  248. sleep 1
  249. fi
  250. # Removes dots so if can compare version numbers
  251. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  252. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
  253. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  254. echo -e "\n"
  255. echo -e "Update available:"
  256. sleep 1
  257. echo -e " Current build: ${red}${currentbuild} ${architecture}${default}"
  258. echo -e " Available build: ${green}${availablebuild} ${architecture}${default}"
  259. echo -e ""
  260. sleep 1
  261. echo ""
  262. echo -en "Applying update.\r"
  263. sleep 1
  264. echo -en "Applying update..\r"
  265. sleep 1
  266. echo -en "Applying update...\r"
  267. sleep 1
  268. echo -en "\n"
  269. fn_script_log "Update available"
  270. fn_script_log "Current build: ${currentbuild}"
  271. fn_script_log "Available build: ${availablebuild}"
  272. fn_script_log "${currentbuild} > ${availablebuild}"
  273. unset updateonstart
  274. check_status.sh
  275. if [ "${status}" == "0" ]; then
  276. update_dl.sh
  277. command_start.sh
  278. sleep 5
  279. command_stop.sh
  280. else
  281. command_stop.sh
  282. update_dl.sh
  283. command_start.sh
  284. fi
  285. alert="update"
  286. alert.sh
  287. else
  288. echo -e "\n"
  289. echo -e "No update available:"
  290. echo -e " Current version: ${green}${currentbuild}${default}"
  291. echo -e " Available version: ${green}${availablebuild}${default}"
  292. echo -e ""
  293. fn_print_ok_nl "No update available"
  294. fn_script_log "Current build: ${currentbuild}"
  295. fn_script_log "Available build: ${availablebuild}"
  296. fi
  297. }
  298. check.sh
  299. fn_print_dots "Checking for update"
  300. if [ "${gamename}" == "Teamspeak 3" ]; then
  301. fn_teamspeak3_check
  302. elif [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
  303. # Goldsource servers bypass checks as fn_steamcmdcheck does not work for appid 90 servers.
  304. # forceupdate bypasses checks
  305. if [ "${status}" != "0" ]; then
  306. exitbypass=1
  307. command_stop.sh
  308. update_dl.sh
  309. command_start.sh
  310. else
  311. update_dl.sh
  312. fi
  313. else
  314. fn_logupdaterequest
  315. fn_steamcmdcheck
  316. fi