update_steamcmd.sh 7.3 KB

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