update_steamcmd.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/bin/bash
  2. # LGSM commanf_update.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="210516"
  6. # Description:Handles updating using steamCMD.
  7. fn_update_steamcmd_dl(){
  8. check.sh
  9. info_config.sh
  10. fn_print_dots "Updating ${servername}"
  11. sleep 1
  12. fn_print_ok_nl "Updating ${servername}"
  13. fn_script_log_info "Updating ${servername}"
  14. cd "${rootdir}/steamcmd"
  15. # Detects if unbuffer command is available.
  16. if [ $(command -v stdbuf) ]; then
  17. unbuffer="stdbuf -i0 -o0 -e0"
  18. fi
  19. if [ "${engine}" == "goldsource" ]; then
  20. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_set_config 90 mod ${appidmod} +app_update "${appid}" +quit | tee -a "${scriptlog}"
  21. else
  22. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_update "${appid}" +quit | tee -a "${scriptlog}"
  23. fi
  24. fix.sh
  25. }
  26. fn_appmanifest_info(){
  27. appmanifestfile=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf")
  28. appmanifestfilewc=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf"|wc -l)
  29. }
  30. fn_appmanifest_check(){
  31. fn_appmanifest_info
  32. # Multiple or no matching appmanifest files may sometimes be present.
  33. # This error is corrected if required.
  34. if [ "${appmanifestfilewc}" -ge "2" ]; then
  35. sleep 1
  36. fn_print_warn "Multiple appmanifest_${appid}.acf files found"
  37. fn_script_log_warn "Multiple appmanifest_${appid}.acf files found"
  38. sleep 2
  39. fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  40. sleep 1
  41. for appfile in ${appmanifestfile}; do
  42. rm "${appfile}"
  43. done
  44. sleep 1
  45. appmanifestfilewc1="${appmanifestfilewc}"
  46. fn_appmanifest_info
  47. if [ "${appmanifestfilewc}" -ge "2" ]; then
  48. fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  49. fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  50. sleep 1
  51. echo " * Check user permissions"
  52. for appfile in ${appmanifestfile}; do
  53. echo " ${appfile}"
  54. done
  55. core_exit.sh
  56. else
  57. fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  58. fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  59. sleep 1
  60. fn_print_warn_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. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  67. if [ "${forceupdate}" == "1" ]; then
  68. fn_print_fail "Still no appmanifest_${appid}.acf found: Unable to update"
  69. fn_script_log "Warning! Still no appmanifest_${appid}.acf found: Unable to update"
  70. exit 1
  71. fi
  72. forceupdate=1
  73. fn_print_warn "No appmanifest_${appid}.acf found"
  74. fn_script_log "Warning! No appmanifest_${appid}.acf found"
  75. sleep 2
  76. fn_print_info_nl "Forcing update to correct issue"
  77. fn_script_log "Forcing update to correct issue"
  78. sleep 1
  79. update_dl.sh
  80. update_check.sh
  81. fi
  82. }
  83. fn_update_request_log(){
  84. # Checks for server update requests from server logs.
  85. fn_print_dots "Checking for update: Server logs"
  86. fn_script_log "Checking for update: Server logs"
  87. sleep 1
  88. requestrestart=$(grep -Ec "MasterRequestRestart" "${consolelog}")
  89. if [ "${requestrestart}" -ge "1" ]; then
  90. fn_print_ok_nl "Checking for update: Server logs: Update requested"
  91. sleep 1
  92. echo ""
  93. echo -ne "Applying update.\r"
  94. sleep 1
  95. echo -ne "Applying update..\r"
  96. sleep 1
  97. echo -ne "Applying update...\r"
  98. sleep 1
  99. echo -ne "\n"
  100. unset updateonstart
  101. check_status.sh
  102. if [ "${status}" != "0" ]; then
  103. exitbypass=1
  104. command_stop.sh
  105. fn_update_steamcmd_dl
  106. exitbypass=1
  107. command_start.sh
  108. else
  109. fn_update_steamcmd_dl
  110. fi
  111. alert="update"
  112. alert.sh
  113. else
  114. fn_print_ok "Checking for update: Server logs: No update requested"
  115. sleep 1
  116. fi
  117. }
  118. fn_update_steamcmd_check(){
  119. fn_appmanifest_check
  120. # Checks for server update from SteamCMD
  121. fn_print_dots "Checking for update: SteamCMD"
  122. fn_script_log_info "Checking for update: SteamCMD"
  123. sleep 1
  124. # Gets currentbuild
  125. currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  126. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD
  127. cd "${rootdir}/steamcmd"
  128. if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then
  129. rm -f "${HOME}/Steam/appcache/appinfo.vdf"
  130. fi
  131. # Set branch for updateinfo
  132. IFS=' ' read -a branchsplits <<< "${branch}"
  133. if [ "${#branchsplits[@]}" -gt 1 ]; then
  134. branchname="${branchsplits[1]}"
  135. else
  136. branchname="public"
  137. fi
  138. # Gets availablebuild info
  139. 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)
  140. if [ -z "${availablebuild}" ]; then
  141. fn_print_fail "Checking for update: SteamCMD"
  142. sleep 1
  143. fn_print_fail_nl "Checking for update: SteamCMD: Not returning version info"
  144. fn_script_log_fatal "Checking for update: SteamCMD: Not returning version info"
  145. core_exit.sh
  146. else
  147. fn_print_ok "Checking for update: SteamCMD"
  148. fn_script_log_pass "Checking for update: SteamCMD"
  149. sleep 1
  150. fi
  151. if [ "${currentbuild}" != "${availablebuild}" ]; then
  152. echo -e "\n"
  153. echo -e "Update available:"
  154. sleep 1
  155. echo -e " Current build: \e[0;31m${currentbuild}\e[0;39m"
  156. echo -e " Available build: \e[0;32m${availablebuild}\e[0;39m"
  157. echo -e ""
  158. echo -e " https://steamdb.info/app/${appid}/"
  159. sleep 1
  160. echo ""
  161. echo -en "Applying update.\r"
  162. sleep 1
  163. echo -en "Applying update..\r"
  164. sleep 1
  165. echo -en "Applying update...\r"
  166. sleep 1
  167. echo -en "\n"
  168. fn_script_log_info "Update available"
  169. fn_script_log_info "Current build: ${currentbuild}"
  170. fn_script_log_info "Available build: ${availablebuild}"
  171. fn_script_log_info "${currentbuild} > ${availablebuild}"
  172. unset updateonstart
  173. check_status.sh
  174. if [ "${status}" != "0" ]; then
  175. exitbypass=1
  176. command_stop.sh
  177. fn_update_steamcmd_dl
  178. exitbypass=1
  179. command_start.sh
  180. else
  181. fn_update_steamcmd_dl
  182. fi
  183. alert="update"
  184. alert.sh
  185. else
  186. echo -e "\n"
  187. echo -e "No update available:"
  188. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  189. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  190. echo -e " https://steamdb.info/app/${appid}/"
  191. echo -e ""
  192. fn_print_ok_nl "No update available"
  193. fn_script_log_info "Current build: ${currentbuild}"
  194. fn_script_log_info "Available build: ${availablebuild}"
  195. fi
  196. }
  197. if [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
  198. # Goldsource servers bypass checks as fn_update_steamcmd_check does not work for appid 90 servers.
  199. # forceupdate bypasses checks
  200. check_status.sh
  201. if [ "${status}" != "0" ]; then
  202. exitbypass=1
  203. command_stop.sh
  204. fn_update_steamcmd_dl
  205. exitbypass=1
  206. command_start.sh
  207. else
  208. fn_update_steamcmd_dl
  209. fi
  210. else
  211. fn_update_request_log
  212. fn_update_steamcmd_check
  213. fi