update_steamcmd.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  7. fn_update_steamcmd_localbuild(){
  8. # Gets local build info.
  9. fn_print_dots "Checking local build: ${remotelocation}"
  10. fn_appmanifest_check
  11. # Uses appmanifest to find local build.
  12. localbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  13. # Set branch to public if no custom branch.
  14. if [ -z "${branch}" ]; then
  15. branch="public"
  16. fi
  17. # Checks if localbuild variable has been set.
  18. if [ -z "${localbuild}" ]||[ "${localbuild}" == "null" ]; then
  19. fn_print_fail "Checking local build: ${remotelocation}"
  20. fn_script_log_fatal "Checking local build"
  21. core_exit.sh
  22. else
  23. fn_print_ok "Checking local build: ${remotelocation}"
  24. fn_script_log_pass "Checking local build"
  25. fi
  26. }
  27. fn_update_steamcmd_remotebuild(){
  28. # Gets remote build info.
  29. if [ -d "${steamcmddir}" ]; then
  30. cd "${steamcmddir}" || exit
  31. fi
  32. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD.
  33. if [ "$(find "${HOME}" -type f -name "appinfo.vdf" | wc -l)" -ne "0" ]; then
  34. find "${HOME}" -type f -name "appinfo.vdf" -exec rm -f {} \;
  35. fi
  36. if [ -n "${branch}" ]&&[ -n "${betapassword}" ]; then
  37. remotebuild=$(${steamcmdcommand} +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" -beta "${branch}" -betapassword "${betapassword}" +quit | sed '1,/branches/d' | sed "1,/${branch}/d" | grep -m 1 buildid | tr -cd '[:digit:]')
  38. elif [ -n "${branch}" ]; then
  39. remotebuild=$(${steamcmdcommand} +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" -beta "${branch}" +quit | sed '1,/branches/d' | sed "1,/${branch}/d" | grep -m 1 buildid | tr -cd '[:digit:]')
  40. else
  41. remotebuild=$(${steamcmdcommand} +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +quit | sed '1,/branches/d' | sed "1,/${branch}/d" | grep -m 1 buildid | tr -cd '[:digit:]')
  42. fi
  43. if [ "${firstcommandname}" != "INSTALL" ]; then
  44. fn_print_dots "Checking remote build: ${remotelocation}"
  45. # Checks if remotebuild variable has been set.
  46. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  47. fn_print_fail "Checking remote build: ${remotelocation}"
  48. fn_script_log_fatal "Checking remote build"
  49. core_exit.sh
  50. else
  51. fn_print_ok "Checking remote build: ${remotelocation}"
  52. fn_script_log_pass "Checking remote build"
  53. fi
  54. else
  55. # Checks if remotebuild variable has been set.
  56. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  57. fn_print_failure "Unable to get remote build"
  58. fn_script_log_fatal "Unable to get remote build"
  59. core_exit.sh
  60. fi
  61. fi
  62. }
  63. fn_update_steamcmd_compare(){
  64. fn_print_dots "Checking for update: ${remotelocation}"
  65. if [ "${localbuild}" != "${remotebuild}" ]; then
  66. fn_print_ok_nl "Checking for update: ${remotelocation}"
  67. echo -en "\n"
  68. echo -e "Update available"
  69. echo -e "* Local build: ${red}${localbuild}${default}"
  70. echo -e "* Remote build: ${green}${remotebuild}${default}"
  71. if [ -n "${branch}" ]; then
  72. echo -e "* Branch: ${branch}"
  73. fi
  74. if [ -n "${betapassword}" ]; then
  75. echo -e "* Branch password: ${betapassword}"
  76. fi
  77. echo -e "https://steamdb.info/app/${appid}/"
  78. echo -en "\n"
  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 [ -n "${branch}" ]; then
  83. fn_script_log_info "Branch: ${branch}"
  84. fi
  85. if [ -n "${betapassword}" ]; then
  86. fn_script_log_info "Branch password: ${betapassword}"
  87. fi
  88. fn_script_log_info "${localbuild} > ${remotebuild}"
  89. unset updateonstart
  90. check_status.sh
  91. # If server stopped.
  92. if [ "${status}" == "0" ]; then
  93. fn_dl_steamcmd
  94. # If server started.
  95. else
  96. fn_print_restart_warning
  97. exitbypass=1
  98. command_stop.sh
  99. fn_firstcommand_reset
  100. exitbypass=1
  101. fn_dl_steamcmd
  102. exitbypass=1
  103. command_start.sh
  104. fn_firstcommand_reset
  105. fi
  106. unset exitbypass
  107. date +%s > "${lockdir}/lastupdate.lock"
  108. alert="update"
  109. alert.sh
  110. else
  111. fn_print_ok_nl "Checking for update: ${remotelocation}"
  112. echo -en "\n"
  113. echo -e "No update available"
  114. echo -e "* Local build: ${green}${localbuild}${default}"
  115. echo -e "* Remote build: ${green}${remotebuild}${default}"
  116. if [ -n "${branch}" ]; then
  117. echo -e "* Branch: ${branch}"
  118. fi
  119. if [ -n "${betapassword}" ]; then
  120. echo -e "* Branch password: ${betapassword}"
  121. fi
  122. echo -e "https://steamdb.info/app/${appid}/"
  123. echo -en "\n"
  124. fn_script_log_info "No update available"
  125. fn_script_log_info "Local build: ${localbuild}"
  126. fn_script_log_info "Remote build: ${remotebuild}"
  127. if [ -n "${branch}" ]; then
  128. fn_script_log_info "Branch: ${branch}"
  129. fi
  130. if [ -n "${betapassword}" ]; then
  131. fn_script_log_info "Branch password: ${betapassword}"
  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. fn_print_error "Multiple appmanifest_${appid}.acf files found"
  145. fn_script_log_error "Multiple appmanifest_${appid}.acf files found"
  146. fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  147. for appfile in ${appmanifestfile}; do
  148. rm -f "${appfile:?}"
  149. done
  150. appmanifestfilewc1="${appmanifestfilewc}"
  151. fn_appmanifest_info
  152. # if error can not be resolved.
  153. if [ "${appmanifestfilewc}" -ge "2" ]; then
  154. fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  155. fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  156. echo -e "* Check user permissions"
  157. for appfile in ${appmanifestfile}; do
  158. echo -e " ${appfile}"
  159. done
  160. core_exit.sh
  161. else
  162. fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  163. fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  164. fn_print_info_nl "Forcing update to correct issue"
  165. fn_script_log_info "Forcing update to correct issue"
  166. fn_dl_steamcmd
  167. fi
  168. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  169. fn_print_error_nl "No appmanifest_${appid}.acf found"
  170. fn_script_log_error "No appmanifest_${appid}.acf found"
  171. fn_print_info_nl "Forcing update to correct issue"
  172. fn_script_log_info "Forcing update to correct issue"
  173. fn_dl_steamcmd
  174. fn_appmanifest_info
  175. if [ "${appmanifestfilewc}" -eq "0" ]; then
  176. fn_print_fail_nl "Still no appmanifest_${appid}.acf found"
  177. fn_script_log_fatal "Still no appmanifest_${appid}.acf found"
  178. core_exit.sh
  179. fi
  180. fi
  181. }
  182. # The location where the builds are checked and downloaded.
  183. remotelocation="SteamCMD"
  184. check.sh
  185. fn_print_dots "${remotelocation}"
  186. if [ "${forceupdate}" == "1" ]; then
  187. # forceupdate bypasses update checks.
  188. if [ "${status}" != "0" ]; then
  189. fn_print_restart_warning
  190. exitbypass=1
  191. command_stop.sh
  192. fn_firstcommand_reset
  193. fn_dl_steamcmd
  194. date +%s > "${lockdir}/lastupdate.lock"
  195. exitbypass=1
  196. command_start.sh
  197. fn_firstcommand_reset
  198. else
  199. fn_dl_steamcmd
  200. date +%s > "${lockdir}/lastupdate.lock"
  201. fi
  202. else
  203. fn_update_steamcmd_localbuild
  204. fn_update_steamcmd_remotebuild
  205. fn_update_steamcmd_compare
  206. fi