From aedb2dd209cefb42e9214f33cbdc8f40bcbf0384 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sun, 12 Jul 2020 21:37:15 +0100 Subject: [PATCH] steamcmd refactor --- lgsm/functions/check.sh | 2 +- lgsm/functions/command_validate.sh | 38 +++++---- lgsm/functions/install_server_files.sh | 18 ++--- lgsm/functions/update_steamcmd.sh | 104 +++++++++++++++++++------ 4 files changed, 111 insertions(+), 51 deletions(-) diff --git a/lgsm/functions/check.sh b/lgsm/functions/check.sh index 3e8fa90a2..73bec641b 100644 --- a/lgsm/functions/check.sh +++ b/lgsm/functions/check.sh @@ -82,7 +82,7 @@ do fi done -allowed_commands_array=( DEBUG START VALIDATE ) +allowed_commands_array=( DEBUG START UPDATE VALIDATE ) for allowed_command in "${allowed_commands_array[@]}" do if [ "${allowed_command}" == "${commandname}" ]; then diff --git a/lgsm/functions/command_validate.sh b/lgsm/functions/command_validate.sh index 276458e48..870377c8c 100644 --- a/lgsm/functions/command_validate.sh +++ b/lgsm/functions/command_validate.sh @@ -9,28 +9,29 @@ commandaction="Validating" functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" fn_validate(){ - fn_script_log_warn "Validating server: SteamCMD: Validate might overwrite some customised files" + fn_script_log_warn "${remotelocation}: Validate might overwrite some customised files" totalseconds=3 for seconds in {3..1}; do - fn_print_warn "Validating server: SteamCMD: Validate might overwrite some customised files: ${totalseconds}" + fn_print_warn "${remotelocation}: Validate might overwrite some customised files: ${totalseconds}" totalseconds=$((totalseconds - 1)) sleep 1 if [ "${seconds}" == "0" ]; then break fi done - fn_print_warn_nl "Validating server: SteamCMD: Validate might overwrite some customised files" - fn_print_start_nl "Validating server: SteamCMD" - fn_script_log_info "Validating server: SteamCMD" + fn_print_warn_nl "${remotelocation}: Validate might overwrite some customised files" + + fn_print_start_nl "${remotelocation}" + fn_script_log_info "Validating server: ${remotelocation}" + info_distro.sh if [ -d "${steamcmddir}" ]; then cd "${steamcmddir}" || exit fi - # Detects if unbuffer command is available, for 32 bit distributions only. - info_distro.sh - if [ "$(command -v stdbuf)" ]&&[ "${arch}" != "x86_64" ]; then - unbuffer="stdbuf -i0 -o0 -e0" - fi + if [ "$(command -v unbuffer)" ]; then + unbuffer="unbuffer" + fi + # If GoldSrc (appid 90) servers. GoldSrc (appid 90) require extra commands. if [ "${appid}" == "90" ]; then # If using a specific branch. @@ -50,13 +51,13 @@ fn_validate(){ fi exitcode=$? - fn_print_dots "Validating server: SteamCMD" + fn_print_dots "${remotelocation}" if [ "${exitcode}" != "0" ]; then - fn_print_fail_nl "Validating server: SteamCMD" - fn_script_log_fatal "Validating server: SteamCMD: FAIL" + fn_print_fail_nl "${remotelocation}" + fn_script_log_fatal "Validating server: ${remotelocation}: FAIL" else - fn_print_ok_nl "Validating server: SteamCMD" - fn_script_log_pass "Validating server: SteamCMD: OK" + fn_print_ok_nl "${remotelocation}" + fn_script_log_pass "Validating server: ${remotelocation}: OK" fi core_exit.sh } @@ -76,9 +77,12 @@ fn_stop_warning(){ fn_print_warn_nl "Validating server: SteamCMD: ${selfname} will be stopped during validation" } -fn_print_dots "Validating server" -fn_print_dots "Validating server: SteamCMD" +# The location where the builds are checked and downloaded. +remotelocation="SteamCMD" check.sh + +fn_print_dots "${remotelocation}" + if [ "${status}" != "0" ]; then fn_stop_warning exitbypass=1 diff --git a/lgsm/functions/install_server_files.sh b/lgsm/functions/install_server_files.sh index ec5c60989..5be4d5f8c 100644 --- a/lgsm/functions/install_server_files.sh +++ b/lgsm/functions/install_server_files.sh @@ -69,12 +69,18 @@ fn_install_server_files(){ } fn_install_server_files_steamcmd(){ + if [ -d "${steamcmddir}" ]; then + cd "${steamcmddir}" || exit + fi + + if [ "$(command -v unbuffer)" ]; then + unbuffer="unbuffer" + fi + counter="0" while [ "${counter}" == "0" ]||[ "${exitcode}" != "0" ]; do counter=$((counter+1)) - if [ -d "${steamcmddir}" ]; then - cd "${steamcmddir}" || exit - fi + if [ "${counter}" -le "10" ]; then # Attempt 1-4: Standard attempt. # Attempt 5-6: Validate attempt. @@ -96,12 +102,6 @@ fn_install_server_files_steamcmd(){ check_steamcmd.sh fi - # Detects if unbuffer command is available for 32 bit distributions only. - info_distro.sh - if [ "$(command -v stdbuf 2>/dev/null)" ]&&[ "${arch}" != "x86_64" ]; then - unbuffer="stdbuf -i0 -o0 -e0" - fi - if [ "${counter}" -le "4" ]; then # If GoldSrc (appid 90) servers. GoldSrc (appid 90) require extra commands. if [ "${appid}" == "90" ]; then diff --git a/lgsm/functions/update_steamcmd.sh b/lgsm/functions/update_steamcmd.sh index 8a089c7f7..65cdfc602 100644 --- a/lgsm/functions/update_steamcmd.sh +++ b/lgsm/functions/update_steamcmd.sh @@ -7,35 +7,91 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" fn_update_steamcmd_dl(){ - info_config.sh - # Detects if unbuffer command is available for 32 bit distributions only. + fn_print_start_nl "${remotelocation}" + fn_script_log_info "Updating server: ${remotelocation}" info_distro.sh - if [ "$(command -v stdbuf)" ]&&[ "${arch}" != "x86_64" ]; then - unbuffer="stdbuf -i0 -o0 -e0" - fi if [ -d "${steamcmddir}" ]; then cd "${steamcmddir}" || exit fi - # If GoldSrc (appid 90) servers. GoldSrc (appid 90) require extra commands. - if [ "${appid}" == "90" ]; then - # If using a specific branch. - if [ -n "${branch}" ]; then - ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" -beta "${branch}" +quit | tee -a "${lgsmlog}" + # Unbuffer will allow the output of steamcmd not buffer allowing a smooth output + # unbuffer us part of the except package + if [ "$(command -v unbuffer)" ]; then + unbuffer="unbuffer" + fi + + # Validate will be added as a parameter if required. + if [ "${commandname}" == "VALIDATE" ]||[ "${commandname}" == "INSTALL" ]; then + validate="validate" + fi + + # To do error checking for SteamCMD the output of steamcmd will be saved to a log + steamcmdlog="${lgsmlogdir}/${selfname}-steamcmd.log" + + counter=0 + while [ "${exitcode}" != "0" ]; do + counter=$((counter+1)) + # Select SteamCMD parameters + # If GoldSrc (appid 90) servers. GoldSrc (appid 90) require extra commands. + if [ "${appid}" == "90" ]; then + # If using a specific branch. + if [ -n "${branch}" ]; then + ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" "${branch}" +app_update "${appid}" -beta "${branch}" ${validate} +quit | tee -a "${lgsmlog}" "${steamcmdlog}" + else + ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" "${branch}" +app_update "${appid}" ${validate} +quit | tee -a "${lgsmlog}" "${steamcmdlog}" + fi + # Force Windows Platform type + elif [ "${shortname}" == "ac" ]; then + if [ -n "${branch}" ]; then + ${unbuffer} ${steamcmdcommand} +@sSteamCmdForcePlatformType windows +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" -beta "${branch}" ${validate} +quit | tee -a "${lgsmlog}" "${steamcmdlog}" + else + ${unbuffer} ${steamcmdcommand} +@sSteamCmdForcePlatformType windows +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" ${validate} +quit | tee -a "${lgsmlog}" "${steamcmdlog}" + fi + # All other servers. else - ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" +quit | tee -a "${lgsmlog}" + if [ -n "${branch}" ]; then + ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" -beta "${branch}" ${validate} +quit | tee -a "${lgsmlog}" "${steamcmdlog}" + else + ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" ${validate} +quit | tee -a "${lgsmlog}" "${steamcmdlog}" + fi fi - elif [ "${shortname}" == "ac" ]; then - ${unbuffer} ${steamcmdcommand} +@sSteamCmdForcePlatformType windows +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" +quit - # All other servers. - else - if [ -n "${branch}" ]; then - ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" -beta "${branch}" +quit | tee -a "${lgsmlog}" + + # Error checking for SteamCMD. Some errors will loop to try again and some will just exit + exitcode=$? + fn_print_dots "${remotelocation}" + if [ -n "$(grep "Error!" "${steamcmdlog}" | tail -1)" ]; then + # Not enough space + if [ -n "$(grep "0x202" "${steamcmdlog}" | tail -1)" ]; then + fn_print_fail_nl "${remotelocation}: Not enough space to download game" + fn_script_log_fatal "${remotelocation}: Not enough space to download game" + core_exit.sh + # Need tp purchase game + elif [ -n "$(grep "No subscription" "${steamcmdlog}" | tail -1)" ]; then + fn_print_fail_nl "${remotelocation}: Game not owned by any authorised accounts" + fn_script_log_fatal "${remotelocation}: Game not owned by any authorised accounts" + core_exit.sh + # Update did not finish + elif [ -n "$(grep "0x402" "${steamcmdlog}" | tail -1)" ]||[ -n "$(grep "0x602" "${steamcmdlog}" | tail -1)" ]; then + fn_print_error_nl "${remotelocation}: Update required but not completed - check network" + fn_script_log_error "${remotelocation}: Update required but not completed - check network" + else + fn_print_error_nl "${remotelocation}: Unknown error occured" + fn_script_log_error "${remotelocation}: Unknown error occured" + fi + elif [ "${exitcode}" != "0" ]; then + fn_print_error_nl "${remotelocation}" + fn_script_log_error "${remotelocation}: ERROR" else - ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" +quit | tee -a "${lgsmlog}" + fn_print_ok_nl "${remotelocation}" + fn_script_log_pass "${remotelocation}: OK" fi - fi - fix.sh + + if [ "${counter}" -gt "10" ]; then + fn_print_failure_nl "SteamCMD did not complete the download, too many retrys" + fn_script_log_fatal "SteamCMD did not complete the download, too many retrys" + core_exit.sh + fi + done } fn_update_steamcmd_localbuild(){ @@ -222,15 +278,17 @@ fn_stop_warning(){ # The location where the builds are checked and downloaded. remotelocation="SteamCMD" -check_steamcmd.sh +check.sh + +fn_print_dots "${remotelocation}" if [ "${forceupdate}" == "1" ]; then # forceupdate bypasses update checks. - check_status.sh if [ "${status}" != "0" ]; then fn_stop_warning exitbypass=1 command_stop.sh + fn_commandname fn_update_steamcmd_dl date +%s > "${lockdir}/lastupdate.lock" exitbypass=1 @@ -240,8 +298,6 @@ if [ "${forceupdate}" == "1" ]; then date +%s > "${lockdir}/lastupdate.lock" fi else - fn_print_dots "Checking for update" - fn_print_dots "Checking for update: ${remotelocation}" fn_update_steamcmd_localbuild fn_update_steamcmd_remotebuild fn_update_steamcmd_compare