update_steamcmd.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #!/bin/bash
  2. # LinuxGSM update_steamcmd.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.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. info_config.sh
  11. # Detects if unbuffer command is available for 32 bit distributions only.
  12. info_distro.sh
  13. if [ "$(command -v stdbuf)" ]&&[ "${arch}" != "x86_64" ]; then
  14. unbuffer="stdbuf -i0 -o0 -e0"
  15. fi
  16. cd "${steamcmddir}" || exit
  17. if [ "${appid}" == "90" ]; then
  18. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" ${branch} +quit | tee -a "${lgsmlog}"
  19. else
  20. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" ${branch} +quit | tee -a "${lgsmlog}"
  21. fi
  22. fix.sh
  23. }
  24. fn_update_steamcmd_localbuild(){
  25. # Gets local build info.
  26. fn_print_dots "Checking for update: ${remotelocation}: checking local build"
  27. sleep 0.5
  28. fn_appmanifest_check
  29. # Uses appmanifest to find local build.
  30. localbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  31. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD.
  32. if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then
  33. rm -f "${HOME}/Steam/appcache/appinfo.vdf"
  34. fi
  35. # Set branch for updateinfo.
  36. IFS=' ' read -ra branchsplits <<< "${branch}"
  37. if [ "${#branchsplits[@]}" -gt 1 ]; then
  38. branchname="${branchsplits[1]}"
  39. else
  40. branchname="public"
  41. fi
  42. sleep 0.5
  43. }
  44. fn_update_steamcmd_remotebuild(){
  45. # Gets remote build info.
  46. cd "${steamcmddir}" || exit
  47. remotebuild=$(./steamcmd.sh +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +quit | sed '1,/branches/d' | sed "1,/${branchname}/d" | grep -m 1 buildid | tr -cd '[:digit:]')
  48. if [ "${installer}" != "1" ]; then
  49. fn_print_dots "Checking for update: ${remotelocation}: checking remote build"
  50. sleep 0.5
  51. # Checks if remotebuild variable has been set.
  52. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  53. fn_print_fail "Checking for update: ${remotelocation}: checking remote build"
  54. fn_script_log_fatal "Checking remote build"
  55. core_exit.sh
  56. else
  57. fn_print_ok "Checking for update: ${remotelocation}: checking remote build"
  58. fn_script_log_pass "Checking remote build"
  59. sleep 0.5
  60. fi
  61. else
  62. # Checks if remotebuild variable has been set.
  63. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  64. fn_print_failure "Unable to get remote build"
  65. fn_script_log_fatal "Unable to get remote build"
  66. core_exit.sh
  67. fi
  68. fi
  69. }
  70. fn_update_steamcmd_compare(){
  71. fn_print_dots "Checking for update: ${remotelocation}"
  72. sleep 0.5
  73. if [ "${localbuild}" != "${remotebuild}" ]; then
  74. fn_print_ok_nl "Checking for update: ${remotelocation}"
  75. sleep 0.5
  76. echo -en "\n"
  77. echo -e "Update available"
  78. echo -e "* Local build: ${red}${localbuild}${default}"
  79. echo -e "* Remote build: ${green}${remotebuild}${default}"
  80. if [ -v "${branch}" ]; then
  81. echo -e "* Branch: ${branch}"
  82. fi
  83. echo -e "https://steamdb.info/app/${appid}/"
  84. fn_script_log_info "Update available"
  85. fn_script_log_info "Local build: ${localbuild}"
  86. fn_script_log_info "Remote build: ${remotebuild}"
  87. if [ -v "${branch}" ]; then
  88. fn_script_log_info "Branch: ${branch}"
  89. fi
  90. fn_script_log_info "${localbuild} > ${remotebuild}"
  91. sleep 0.5
  92. echo -en "\n"
  93. echo -en "applying update.\r"
  94. sleep 1
  95. echo -en "applying update..\r"
  96. sleep 1
  97. echo -en "applying update...\r"
  98. sleep 1
  99. echo -en "\n"
  100. unset updateonstart
  101. check_status.sh
  102. # If server stopped.
  103. if [ "${status}" == "0" ]; then
  104. fn_update_steamcmd_dl
  105. # If server started.
  106. else
  107. exitbypass=1
  108. command_stop.sh
  109. exitbypass=1
  110. fn_update_steamcmd_dl
  111. exitbypass=1
  112. command_start.sh
  113. fi
  114. alert="update"
  115. alert.sh
  116. else
  117. fn_print_ok_nl "Checking for update: ${remotelocation}"
  118. sleep 0.5
  119. echo -en "\n"
  120. echo -e "No update available"
  121. echo -e "* Local build: ${green}${localbuild}${default}"
  122. echo -e "* Remote build: ${green}${remotebuild}${default}"
  123. if [ -v "${branch}" ]; then
  124. echo -e "* Branch: ${branch}"
  125. fi
  126. echo -e "https://steamdb.info/app/${appid}/"
  127. fn_script_log_info "No update available"
  128. fn_script_log_info "Local build: ${localbuild}"
  129. fn_script_log_info "Remote build: ${remotebuild}"
  130. if [ -v "${branch}" ]; then
  131. fn_script_log_info "Branch: ${branch}"
  132. fi
  133. fi
  134. }
  135. fn_appmanifest_info(){
  136. appmanifestfile=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf")
  137. appmanifestfilewc=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf" | wc -l)
  138. }
  139. fn_appmanifest_check(){
  140. fn_appmanifest_info
  141. # Multiple or no matching appmanifest files may sometimes be present.
  142. # This error is corrected if required.
  143. if [ "${appmanifestfilewc}" -ge "2" ]; then
  144. sleep 0.5
  145. fn_print_error "Multiple appmanifest_${appid}.acf files found"
  146. fn_script_log_error "Multiple appmanifest_${appid}.acf files found"
  147. sleep 2
  148. fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  149. sleep 0.5
  150. for appfile in ${appmanifestfile}; do
  151. rm "${appfile}"
  152. done
  153. sleep 0.5
  154. appmanifestfilewc1="${appmanifestfilewc}"
  155. fn_appmanifest_info
  156. if [ "${appmanifestfilewc}" -ge "2" ]; then
  157. fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  158. fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  159. sleep 0.5
  160. echo " * Check user permissions"
  161. for appfile in ${appmanifestfile}; do
  162. echo " ${appfile}"
  163. done
  164. core_exit.sh
  165. else
  166. fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  167. fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  168. sleep 0.5
  169. fn_print_info_nl "Forcing update to correct issue"
  170. fn_script_log_info "Forcing update to correct issue"
  171. sleep 0.5
  172. fn_update_steamcmd_dl
  173. fi
  174. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  175. fn_print_error_nl "No appmanifest_${appid}.acf found"
  176. fn_script_log_error "No appmanifest_${appid}.acf found"
  177. sleep 0.5
  178. fn_print_info_nl "Forcing update to correct issue"
  179. fn_script_log_info "Forcing update to correct issue"
  180. sleep 0.5
  181. fn_update_steamcmd_dl
  182. fn_appmanifest_info
  183. if [ "${appmanifestfilewc}" -eq "0" ]; then
  184. fn_print_fail_nl "Still no appmanifest_${appid}.acf found"
  185. fn_script_log_fatal "Still no appmanifest_${appid}.acf found"
  186. core_exit.sh
  187. fi
  188. fi
  189. }
  190. # The location where the builds are checked and downloaded.
  191. remotelocation="SteamCMD"
  192. check.sh
  193. if [ "${forceupdate}" == "1" ]; then
  194. # forceupdate bypasses update checks.
  195. check_status.sh
  196. if [ "${status}" != "0" ]; then
  197. exitbypass=1
  198. command_stop.sh
  199. fn_update_steamcmd_dl
  200. exitbypass=1
  201. command_start.sh
  202. else
  203. fn_update_steamcmd_dl
  204. fi
  205. else
  206. fn_update_steamcmd_localbuild
  207. fn_update_steamcmd_remotebuild
  208. fn_update_steamcmd_compare
  209. fi