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. # Description: Checks if a server update is available.
  6. local modulename="Update"
  7. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  8. ### SteamCMD Update Checker ###
  9. fn_appmanifestinfo(){
  10. appmanifestfile=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf")
  11. appmanifestfilewc=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf"|wc -l)
  12. }
  13. fn_appmanifestcheck(){
  14. fn_appmanifestinfo
  15. # Multiple or no matching appmanifest files may sometimes be available.
  16. # This is an error is corrected below if required.
  17. if [ "${appmanifestfilewc}" -ge "2" ]; then
  18. sleep 1
  19. fn_print_warn "Multiple appmanifest_${appid}.acf files found"
  20. fn_script_log_warn "Multiple appmanifest_${appid}.acf files found"
  21. sleep 2
  22. fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  23. sleep 1
  24. for appfile in ${appmanifestfile}; do
  25. rm "${appfile}"
  26. done
  27. appmanifestfilewc1="${appmanifestfilewc}"
  28. fn_appmanifestinfo
  29. if [ "${appmanifestfilewc}" -ge "2" ]; then
  30. fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  31. fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  32. sleep 1
  33. echo ""
  34. echo " Check user permissions"
  35. for appfile in ${appmanifestfile}; do
  36. echo " ${appfile}"
  37. done
  38. exit 1
  39. else
  40. sleep 1
  41. fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  42. fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  43. sleep 1
  44. fn_print_info_nl "Forcing update to correct issue"
  45. fn_script_log_info "Forcing update to correct issue"
  46. sleep 1
  47. update_dl.sh
  48. update_check.sh
  49. fi
  50. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  51. if [ "${forceupdate}" == "1" ]; then
  52. fn_print_fail "Still no appmanifest_${appid}.acf found: Unable to update"
  53. fn_script_log_fatal "Still no appmanifest_${appid}.acf found: Unable to update"
  54. core_exit.sh
  55. fi
  56. forceupdate=1
  57. fn_print_warn "No appmanifest_${appid}.acf found"
  58. fn_script_log_warn "No appmanifest_${appid}.acf found"
  59. sleep 2
  60. fn_print_info_nl "Forcing update to correct issue"
  61. fn_script_log_warn "Forcing update to correct issue"
  62. sleep 1
  63. update_dl.sh
  64. update_check.sh
  65. fi
  66. }
  67. fn_logupdaterequest(){
  68. # Checks for server update requests from server logs.
  69. fn_print_dots "Checking for update: Server logs"
  70. fn_script_log_info "Checking for update: Server logs"
  71. sleep 1
  72. requestrestart=$(grep -Ec "MasterRequestRestart" "${consolelog}")
  73. if [ "${requestrestart}" -ge "1" ]; then
  74. fn_print_ok_nl "Checking for update: Server logs: Update requested"
  75. sleep 1
  76. echo ""
  77. echo -ne "Applying update.\r"
  78. sleep 1
  79. echo -ne "Applying update..\r"
  80. sleep 1
  81. echo -ne "Applying update...\r"
  82. sleep 1
  83. echo -ne "\n"
  84. unset updateonstart
  85. check_status.sh
  86. if [ "${status}" != "0" ]; then
  87. command_stop.sh
  88. update_dl.sh
  89. command_start.sh
  90. else
  91. update_dl.sh
  92. fi
  93. alert="update"
  94. alert.sh
  95. else
  96. fn_print_ok "Checking for update: Server logs: No update requested"
  97. sleep 1
  98. fi
  99. }
  100. fn_steamcmdcheck(){
  101. fn_appmanifestcheck
  102. # Checks for server update from SteamCMD
  103. fn_print_dots "Checking for update: SteamCMD"
  104. fn_script_log_info "Checking for update: SteamCMD"
  105. sleep 1
  106. # Gets currentbuild
  107. currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  108. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD
  109. # Gets availablebuild info
  110. cd "${rootdir}/steamcmd"
  111. if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then
  112. rm -f "${HOME}/Steam/appcache/appinfo.vdf"
  113. fi
  114. # set branch for updateinfo
  115. IFS=' ' read -a branchsplits <<< "${branch}"
  116. if [ "${#branchsplits[@]}" -gt 1 ]; then
  117. branchname="${branchsplits[1]}"
  118. else
  119. branchname="public"
  120. fi
  121. 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)
  122. if [ -z "${availablebuild}" ]; then
  123. fn_print_fail "Checking for update: SteamCMD"
  124. fn_script_log_fatal "Checking for update: SteamCMD"
  125. sleep 1
  126. fn_print_fail_nl "Checking for update: SteamCMD: Not returning version info"
  127. fn_script_log_fatal "Checking for update: SteamCMD: Not returning version info"
  128. core_exit.sh
  129. else
  130. fn_print_ok "Checking for update: SteamCMD"
  131. fn_script_log_pass "Checking for update: SteamCMD"
  132. sleep 1
  133. fi
  134. if [ "${currentbuild}" != "${availablebuild}" ]; then
  135. echo -e "\n"
  136. echo -e "Update available:"
  137. sleep 1
  138. echo -e " Current build: \e[0;31m${currentbuild}\e[0;39m"
  139. echo -e " Available build: \e[0;32m${availablebuild}\e[0;39m"
  140. echo -e ""
  141. echo -e " https://steamdb.info/app/${appid}/"
  142. sleep 1
  143. echo ""
  144. echo -en "Applying update.\r"
  145. sleep 1
  146. echo -en "Applying update..\r"
  147. sleep 1
  148. echo -en "Applying update...\r"
  149. sleep 1
  150. echo -en "\n"
  151. fn_script_log "Update available"
  152. fn_script_log "Current build: ${currentbuild}"
  153. fn_script_log "Available build: ${availablebuild}"
  154. fn_script_log "${currentbuild} > ${availablebuild}"
  155. unset updateonstart
  156. check_status.sh
  157. if [ "${status}" != "0" ]; then
  158. command_stop.sh
  159. update_dl.sh
  160. command_start.sh
  161. else
  162. update_dl.sh
  163. fi
  164. alert="update"
  165. alert.sh
  166. else
  167. echo -e "\n"
  168. echo -e "No update available:"
  169. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  170. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  171. echo -e " https://steamdb.info/app/${appid}/"
  172. echo -e ""
  173. fn_print_ok_nl "No update available"
  174. fn_script_log "Current build: ${currentbuild}"
  175. fn_script_log "Available build: ${availablebuild}"
  176. fi
  177. }
  178. ### END SteamCMD Update Checker ###
  179. fn_teamspeak3_check(){
  180. # Checks for server update from teamspeak.com using a mirror dl.4players.de
  181. fn_print_dots "Checking for update: teamspeak.com"
  182. fn_script_log_info "Checking for update: teamspeak.com"
  183. sleep 1
  184. # Gets currentbuild info
  185. # Checks currentbuild info is available, if fails a server restart will be forced to generate logs
  186. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  187. fn_print_fail "Checking for update: teamspeak.com"
  188. sleep 1
  189. fn_print_fail_nl "Checking for update: teamspeak.com: No logs with server version found"
  190. fn_script_log_error "Checking for update: teamspeak.com: No logs with server version found"
  191. sleep 2
  192. fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
  193. fn_script_log_info "Checking for update: teamspeak.com: Forcing server restart"
  194. sleep 2
  195. command_stop.sh
  196. command_start.sh
  197. sleep 2
  198. # If still failing will exit
  199. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  200. fn_print_fail_nl "Checking for update: teamspeak.com: Still No logs with server version found"
  201. fn_script_log_fatal "Checking for update: teamspeak.com: Still No logs with server version found"
  202. core_exit.sh
  203. else
  204. exitcode=0
  205. fi
  206. fi
  207. 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}')
  208. # Gets the teamspeak server architecture
  209. info_distro.sh
  210. if [ "${arch}" == "x86_64" ]; then
  211. ts3arch="amd64"
  212. elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then
  213. ts3arch="x86"
  214. else
  215. echo ""
  216. fn_print_failure "${arch} is an unsupported architecture"
  217. exit 1
  218. fi
  219. # Gets availablebuild info
  220. # Grabs all version numbers but not in correct order
  221. 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
  222. # Sort version numbers
  223. cat .ts3_version_numbers_unsorted.tmp | sort -r --version-sort -o .ts3_version_numbers_sorted.tmp
  224. # Finds directory with most recent server version.
  225. while read ts3_version_number; do
  226. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
  227. if [ $? -eq 0 ]; then
  228. availablebuild="${ts3_version_number}"
  229. # Break while-loop, if the latest release could be found
  230. break
  231. fi
  232. done < .ts3_version_numbers_sorted.tmp
  233. # Tidy up
  234. rm -f ".ts3_version_numbers_unsorted.tmp"
  235. rm -f ".ts3_version_numbers_sorted.tmp"
  236. # Checks availablebuild info is available
  237. if [ -z "${availablebuild}" ]; then
  238. fn_print_fail "Checking for update: teamspeak.com"
  239. sleep 1
  240. fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
  241. fn_script_log_fatal "Failure! Checking for update: teamspeak.com: Not returning version info"
  242. sleep 1
  243. core_exit.sh
  244. else
  245. fn_print_ok "Checking for update: teamspeak.com"
  246. fn_script_log_pass "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_script_log "Update available"
  269. fn_script_log "Current build: ${currentbuild}"
  270. fn_script_log "Available build: ${availablebuild}"
  271. fn_script_log "${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_script_log "Current build: ${currentbuild}"
  294. fn_script_log "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. exitbypass=1
  306. command_stop.sh
  307. update_dl.sh
  308. command_start.sh
  309. else
  310. update_dl.sh
  311. fi
  312. else
  313. fn_logupdaterequest
  314. fn_steamcmdcheck
  315. fi