update_steamcmd.sh 6.2 KB

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