update_steamcmd.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #!/bin/bash
  2. # LGSM commanf_update.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description:Handles updating using steamCMD.
  6. local commandnane="UPDATE"
  7. local commandaction="Update"
  8. local selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. fn_update_steamcmd_dl(){
  10. check.sh
  11. info_config.sh
  12. fn_print_dots "Updating ${servername}"
  13. sleep 1
  14. fn_print_ok_nl "Updating ${servername}"
  15. fn_script_log_info "Updating ${servername}"
  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_warn "Multiple appmanifest_${appid}.acf files found"
  39. fn_script_log_warn "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_warn_nl "Forcing update to correct issue"
  63. fn_script_log_warn "Forcing update to correct issue"
  64. sleep 1
  65. update_dl.sh
  66. update_check.sh
  67. fi
  68. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  69. if [ "${forceupdate}" == "1" ]; then
  70. fn_print_fail "Still no appmanifest_${appid}.acf found: Unable to update"
  71. fn_script_log_fatal "Warning! Still no appmanifest_${appid}.acf found: Unable to update"
  72. core_exit.sh
  73. fi
  74. forceupdate=1
  75. fn_print_warn "No appmanifest_${appid}.acf found"
  76. fn_script_log_warn "No appmanifest_${appid}.acf found"
  77. sleep 1
  78. fn_print_info_nl "Forcing update to correct issue"
  79. fn_script_log_info "Forcing update to correct issue"
  80. sleep 1
  81. update_dl.sh
  82. update_check.sh
  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. sleep 1
  94. echo ""
  95. echo -ne "Applying update.\r"
  96. sleep 1
  97. echo -ne "Applying update..\r"
  98. sleep 1
  99. echo -ne "Applying update...\r"
  100. sleep 1
  101. echo -ne "\n"
  102. unset updateonstart
  103. check_status.sh
  104. if [ "${status}" != "0" ]; then
  105. exitbypass=1
  106. command_stop.sh
  107. fn_update_steamcmd_dl
  108. exitbypass=1
  109. command_start.sh
  110. else
  111. fn_update_steamcmd_dl
  112. fi
  113. alert="update"
  114. alert.sh
  115. else
  116. fn_print_ok "Checking for update: Server logs: No update requested"
  117. sleep 1
  118. fi
  119. }
  120. fn_update_steamcmd_check(){
  121. fn_appmanifest_check
  122. # Checks for server update from SteamCMD
  123. fn_print_dots "Checking for update: SteamCMD"
  124. fn_script_log_info "Checking for update: SteamCMD"
  125. sleep 1
  126. # Gets currentbuild
  127. currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  128. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD
  129. cd "${rootdir}/steamcmd"
  130. if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then
  131. rm -f "${HOME}/Steam/appcache/appinfo.vdf"
  132. fi
  133. # Set branch for updateinfo
  134. IFS=' ' read -a branchsplits <<< "${branch}"
  135. if [ "${#branchsplits[@]}" -gt 1 ]; then
  136. branchname="${branchsplits[1]}"
  137. else
  138. branchname="public"
  139. fi
  140. # Gets availablebuild info
  141. 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)
  142. if [ -z "${availablebuild}" ]; then
  143. fn_print_fail "Checking for update: SteamCMD"
  144. sleep 1
  145. fn_print_fail_nl "Checking for update: SteamCMD: Not returning version info"
  146. fn_script_log_fatal "Checking for update: SteamCMD: Not returning version info"
  147. core_exit.sh
  148. else
  149. fn_print_ok "Checking for update: SteamCMD"
  150. fn_script_log_pass "Checking for update: SteamCMD"
  151. sleep 1
  152. fi
  153. if [ "${currentbuild}" != "${availablebuild}" ]; then
  154. echo -e "\n"
  155. echo -e "Update available:"
  156. sleep 1
  157. echo -e " Current build: ${red}${currentbuild}${default}"
  158. echo -e " Available build: ${green}${availablebuild}${default}"
  159. echo -e ""
  160. echo -e " https://steamdb.info/app/${appid}/"
  161. sleep 1
  162. echo ""
  163. echo -en "Applying update.\r"
  164. sleep 1
  165. echo -en "Applying update..\r"
  166. sleep 1
  167. echo -en "Applying update...\r"
  168. sleep 1
  169. echo -en "\n"
  170. fn_script_log_info "Update available"
  171. fn_script_log_info "Current build: ${currentbuild}"
  172. fn_script_log_info "Available build: ${availablebuild}"
  173. fn_script_log_info "${currentbuild} > ${availablebuild}"
  174. unset updateonstart
  175. check_status.sh
  176. if [ "${status}" != "0" ]; then
  177. exitbypass=1
  178. command_stop.sh
  179. fn_update_steamcmd_dl
  180. exitbypass=1
  181. command_start.sh
  182. else
  183. fn_update_steamcmd_dl
  184. fi
  185. alert="update"
  186. alert.sh
  187. else
  188. echo -e "\n"
  189. echo -e "No update available:"
  190. echo -e " Current version: ${green}${currentbuild}${default}"
  191. echo -e " Available version: ${green}${availablebuild}${default}"
  192. echo -e " https://steamdb.info/app/${appid}/"
  193. echo -e ""
  194. fn_print_ok_nl "No update available"
  195. fn_script_log_info "Current build: ${currentbuild}"
  196. fn_script_log_info "Available build: ${availablebuild}"
  197. fi
  198. }
  199. if [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
  200. # Goldsource servers bypass checks as fn_update_steamcmd_check does not work for appid 90 servers.
  201. # forceupdate bypasses checks
  202. check_status.sh
  203. if [ "${status}" != "0" ]; then
  204. exitbypass=1
  205. command_stop.sh
  206. fn_update_steamcmd_dl
  207. exitbypass=1
  208. command_start.sh
  209. else
  210. fn_update_steamcmd_dl
  211. fi
  212. else
  213. fn_update_request_log
  214. fn_update_steamcmd_check
  215. fi