update_steamcmd.sh 7.0 KB

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