update_steamcmd.sh 7.4 KB

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