update_steamcmd.sh 6.8 KB

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