fn_update_check 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #!/bin/bash
  2. # LGSM fn_update_check function
  3. # Author: Daniel Gibbs
  4. # Website: http://danielgibbs.co.uk
  5. # Version: 150315
  6. # Description: Checks if a server update is available.
  7. local modulename="Update"
  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_printwarn "Multiple appmanifest_${appid}.acf files found"
  20. fn_scriptlog "Warning! Multiple appmanifest_${appid}.acf files found"
  21. sleep 2
  22. fn_printdots "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_printfail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  31. fn_scriptlog "Failure! 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
  39. else
  40. sleep 1
  41. fn_printok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  42. fn_scriptlog "Success! Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  43. sleep 1
  44. fn_printinfonl "Forcing update to correct issue"
  45. fn_scriptlog "Forcing update to correct issue"
  46. sleep 1
  47. fn_update_dl
  48. fn_update_check
  49. fi
  50. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  51. fn_printwarn "No appmanifest_${appid}.acf found"
  52. fn_scriptlog "Warning! No appmanifest_${appid}.acf found"
  53. sleep 2
  54. fn_printinfonl "Forcing update to correct issue"
  55. fn_scriptlog "Forcing update to correct issue"
  56. sleep 1
  57. fn_update_dl
  58. fn_update_check
  59. fi
  60. }
  61. fn_logupdaterequest(){
  62. # Checks for server update requests from server logs.
  63. echo ""
  64. fn_printdots "Checking for update: Server logs"
  65. sleep 1
  66. fn_printok "Checking for update: Server logs"
  67. fn_scriptlog "Checking for update: Server logs"
  68. sleep 1
  69. requestrestart=$(grep -sc "MasterRequestRestart" "${consolelog}")
  70. if [ "${requestrestart}" -ge "1" ]; then
  71. fn_printoknl "Server requesting update"
  72. sleep 1
  73. echo ""
  74. echo -ne "Applying update.\r"
  75. sleep 1
  76. echo -ne "Applying update..\r"
  77. sleep 1
  78. echo -ne "Applying update...\r"
  79. sleep 1
  80. echo -ne "\n"
  81. if [ ! -z "${norestart}" ]; then
  82. fn_update_dl
  83. else
  84. fn_stop
  85. fn_update_dl
  86. fn_start
  87. fi
  88. else
  89. fn_printok "Checking for update: Server logs: No update requested"
  90. sleep 1
  91. fi
  92. echo ""
  93. }
  94. fn_steamcmdcheck(){
  95. fn_appmanifestcheck
  96. # Checks for server update from SteamCMD
  97. fn_printdots "Checking for update: SteamCMD"
  98. fn_scriptlog "Checking for update: SteamCMD"
  99. sleep 1
  100. # Gets currentbuild
  101. currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  102. # Gets availablebuild info
  103. cd "${rootdir}/steamcmd"
  104. availablebuild=$(./steamcmd.sh +login "${steamuser}" "${steampass}" +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)
  105. if [ -z "${availablebuild}" ]; then
  106. fn_printfail "Checking for update: SteamCMD"
  107. fn_scriptlog "Failure! Checking for update: SteamCMD"
  108. sleep 1
  109. fn_printfail "Checking for update: SteamCMD: Not returning version info"
  110. fn_scriptlog "Failure! Checking for update: SteamCMD: Not returning version info"
  111. sleep 2
  112. else
  113. fn_printok "Checking for update: SteamCMD"
  114. fn_scriptlog "Success! Checking for update: SteamCMD"
  115. sleep 1
  116. fi
  117. if [ "${currentbuild}" -ne "${availablebuild}" ]; then
  118. echo -e "\n"
  119. echo -e "Update available:"
  120. sleep 1
  121. echo -e " Current build: \e[0;31m${currentbuild}\e[0;39m"
  122. echo -e " Available build: \e[0;32m${availablebuild}\e[0;39m"
  123. echo -e ""
  124. echo -e " https://steamdb.info/app/${appid}/"
  125. sleep 1
  126. echo ""
  127. echo -en "Applying update.\r"
  128. sleep 1
  129. echo -en "Applying update..\r"
  130. sleep 1
  131. echo -en "Applying update...\r"
  132. sleep 1
  133. echo -en "\n"
  134. fn_scriptlog "Update available"
  135. fn_scriptlog "Current build: ${currentbuild}"
  136. fn_scriptlog "Available build: ${availablebuild}"
  137. fn_scriptlog "${currentbuild} > ${availablebuild}"
  138. if [ ! -z "${norestart}" ]; then
  139. fn_update_dl
  140. else
  141. fn_stop
  142. fn_update_dl
  143. fn_start
  144. fi
  145. else
  146. echo -e "\n"
  147. echo -e "No update available:"
  148. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  149. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  150. echo -e " https://steamdb.info/app/${appid}/"
  151. echo -e ""
  152. fn_printoknl "No update available"
  153. fn_scriptlog "Current build: ${currentbuild}"
  154. fn_scriptlog "Available build: ${availablebuild}"
  155. fi
  156. }
  157. ### END SteamCMD Update Checker ###
  158. fn_teamspeak3_check(){
  159. # Checks for server update from teamspeak.com using a mirror dl.4players.de
  160. fn_printdots "Checking for update: teamspeak.com"
  161. fn_scriptlog "Checking for update: teamspeak.com"
  162. sleep 1
  163. # Gets currentbuild info
  164. # Checks currentbuild info is available, if fails a server restart will be forced to generate logs
  165. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  166. fn_printfail "Checking for update: teamspeak.com"
  167. fn_scriptlog "Checking for update: teamspeak.com"
  168. sleep 1
  169. fn_printfailnl "Checking for update: teamspeak.com: No logs with server version found"
  170. fn_scriptlog "Failure! Checking for update: teamspeak.com: No logs with server version found"
  171. sleep 2
  172. fn_printinfonl "Checking for update: teamspeak.com: Forcing server restart"
  173. fn_scriptlog "Checking for update: teamspeak.com: Forcing server restart"
  174. sleep 2
  175. ./${selfname} restart
  176. sleep 2
  177. # If still failing will exit
  178. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  179. fn_printfailnl "Checking for update: teamspeak.com: Still No logs with server version found"
  180. fn_scriptlog "Failure! Checking for update: teamspeak.com: Still No logs with server version found"
  181. exit
  182. fi
  183. fi
  184. 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}')
  185. # Gets the teamspeak server architecture
  186. ts3arch=$(ls $(find ${filesdir}/ -name 'ts3server_*_*' 2> /dev/null | grep -v 'ts3server_minimal_runscript.sh' | sort | tail -1) | egrep -o '(amd64|x86)' | tail -1)
  187. # Gets availablebuild info
  188. 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.tmp
  189. # Finds directory with most recent server version.
  190. while read ts3_version_number; do
  191. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux-${ts3arch}-${ts3_version_number}.tar.gz"
  192. if [[ $? == 0 ]]; then
  193. availablebuild="${ts3_version_number}"
  194. # Break while-loop, if the latest release could be found
  195. break
  196. fi
  197. done < .ts3_version_numbers.tmp
  198. rm .ts3_version_numbers.tmp
  199. # Checks availablebuild info is available
  200. if [ -z "${availablebuild}" ]; then
  201. fn_printfail "Checking for update: teamspeak.com"
  202. fn_scriptlog "Checking for update: teamspeak.com"
  203. sleep 1
  204. fn_printfail "Checking for update: teamspeak.com: Not returning version info"
  205. fn_scriptlog "Failure! Checking for update: teamspeak.com: Not returning version info"
  206. sleep 2
  207. exit
  208. else
  209. fn_printok "Checking for update: teamspeak.com"
  210. fn_scriptlog "Success! Checking for update: teamspeak.com"
  211. sleep 1
  212. fi
  213. # Removes dots so if can compare version numbers
  214. currentbuilddigit=$(echo "${currentbuild}"|tr -cd "[:digit:]")
  215. availablebuilddigit=$(echo "${availablebuild}"|tr -cd "[:digit:]")
  216. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  217. echo -e "\n"
  218. echo -e "Update available:"
  219. sleep 1
  220. echo -e " Current build: \e[0;31m${currentbuild} ${architecture}\e[0;39m"
  221. echo -e " Available build: \e[0;32m${availablebuild} ${architecture}\e[0;39m"
  222. echo -e ""
  223. sleep 1
  224. echo ""
  225. echo -en "Applying update.\r"
  226. sleep 1
  227. echo -en "Applying update..\r"
  228. sleep 1
  229. echo -en "Applying update...\r"
  230. sleep 1
  231. echo -en "\n"
  232. fn_scriptlog "Update available"
  233. fn_scriptlog "Current build: ${currentbuild}"
  234. fn_scriptlog "Available build: ${availablebuild}"
  235. fn_scriptlog "${currentbuild} > ${availablebuild}"
  236. fn_stop
  237. fn_update_dl
  238. fn_start
  239. else
  240. echo -e "\n"
  241. echo -e "No update available:"
  242. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  243. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  244. echo -e ""
  245. fn_printoknl "No update available"
  246. fn_scriptlog "Current build: ${currentbuild}"
  247. fn_scriptlog "Available build: ${availablebuild}"
  248. fi
  249. }
  250. fn_printdots "Checking for update"
  251. if [ "${gamename}" == "Teamspeak 3" ]; then
  252. fn_teamspeak3_check
  253. else
  254. fn_logupdaterequest
  255. fn_steamcmdcheck
  256. fi