update_steamcmd.sh 7.0 KB

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