From fe4e9a535f38e65a1a48e58fca5f9c4f5645da19 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 8 Mar 2023 20:54:50 +0000 Subject: [PATCH] non-steam update refactor --- lgsm/functions/alert.sh | 4 +- lgsm/functions/command_check_update.sh | 28 ++++--- lgsm/functions/core_getopt.sh | 6 +- lgsm/functions/update_factorio.sh | 70 +++++++++-------- lgsm/functions/update_jediknight2.sh | 86 ++++++++------------- lgsm/functions/update_minecraft.sh | 65 ++++++++-------- lgsm/functions/update_minecraft_bedrock.sh | 87 ++++++++-------------- lgsm/functions/update_mta.sh | 67 ++--------------- lgsm/functions/update_papermc.sh | 83 +++++++++++---------- lgsm/functions/update_ts3.sh | 66 ++-------------- lgsm/functions/update_ut99.sh | 36 +++++---- lgsm/functions/update_vintagestory.sh | 17 +++-- 12 files changed, 239 insertions(+), 376 deletions(-) diff --git a/lgsm/functions/alert.sh b/lgsm/functions/alert.sh index 8460209c4..24ffdc8c4 100755 --- a/lgsm/functions/alert.sh +++ b/lgsm/functions/alert.sh @@ -60,7 +60,7 @@ fn_alert_update() { alertemoji="🎮" alertsound="1" alerturl="not enabled" - alertbody="${gamename} received update" + alertbody="${gamename} received update: ${remotebuild}" } fn_alert_check_update() { @@ -69,7 +69,7 @@ fn_alert_check_update() { alertemoji="🎮" alertsound="1" alerturl="not enabled" - alertbody="${gamename} update available" + alertbody="${gamename} update available: ${remotebuild}" } fn_alert_permissions() { diff --git a/lgsm/functions/command_check_update.sh b/lgsm/functions/command_check_update.sh index 59b29d6e9..3753c72c6 100755 --- a/lgsm/functions/command_check_update.sh +++ b/lgsm/functions/command_check_update.sh @@ -14,16 +14,26 @@ fn_print_dots "" check.sh core_logs.sh -if [ "${appid}" ]; then - core_steamcmd.sh - - check_steamcmd.sh - - fn_update_steamcmd_localbuild - fn_update_steamcmd_remotebuild - fn_update_steamcmd_compare -elif [ "${shortname}" == "ts3" ]; then +if [ "${shortname}" == "ts3" ]; then update_ts3.sh +elif [ "${shortname}" == "mc" ]; then + update_minecraft.sh +elif [ "${shortname}" == "mcb" ]; then + update_minecraft_bedrock.sh +elif [ "${shortname}" == "pmc" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then + update_papermc.sh +elif [ "${shortname}" == "fctr" ]; then + update_factorio.sh +elif [ "${shortname}" == "mta" ]; then + update_mta.sh +elif [ "${shortname}" == "jk2" ]; then + update_jediknight2.sh +elif [ "${shortname}" == "vints" ]; then + update_vintagestory.sh +elif [ "${shortname}" == "ut99" ]; then + update_ut99.sh +else + update_steamcmd.sh fi core_exit.sh diff --git a/lgsm/functions/core_getopt.sh b/lgsm/functions/core_getopt.sh index 0c51b1caf..808fe2e2a 100755 --- a/lgsm/functions/core_getopt.sh +++ b/lgsm/functions/core_getopt.sh @@ -66,7 +66,7 @@ currentopt+=("${cmd_update_linuxgsm[@]}") # Exclude noupdate games here. if [ "${shortname}" == "jk2" ] || [ "${engine}" != "idtech3" ]; then if [ "${shortname}" != "bf1942" ] && [ "${shortname}" != "bfv" ] && [ "${engine}" != "idtech2" ] && [ "${engine}" != "iw2.0" ] && [ "${engine}" != "iw3.0" ] && [ "${engine}" != "quake" ] && [ "${shortname}" != "samp" ] && [ "${shortname}" != "ut2k4" ]; then - currentopt+=("${cmd_update[@]}") + currentopt+=("${cmd_update[@]}" "${cmd_check_update[@]}") # force update for SteamCMD or Multi Theft Auto only. if [ "${appid}" ] || [ "${shortname}" == "mta" ]; then currentopt+=("${cmd_force_update[@]}") @@ -75,8 +75,8 @@ if [ "${shortname}" == "jk2" ] || [ "${engine}" != "idtech3" ]; then fi # Validate and check-update command. -if [ "${appid}" ] || [ "${shortname}" == "ts3" ]; then - currentopt+=("${cmd_validate[@]}" "${cmd_check_update[@]}") +if [ "${appid}" ]; then + currentopt+=("${cmd_validate[@]}") fi # Backup. diff --git a/lgsm/functions/update_factorio.sh b/lgsm/functions/update_factorio.sh index 2c8bf0d01..0eef7c6da 100644 --- a/lgsm/functions/update_factorio.sh +++ b/lgsm/functions/update_factorio.sh @@ -28,16 +28,17 @@ fn_update_factorio_dl() { fn_update_factorio_localbuild() { # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" - # Uses executable to find local build. + # Uses executable to get local build. cd "${executabledir}" || exit - if [ -f "${executable}" ]; then - localbuild=$(${executable} --version | grep "Version:" | awk '{print $2}') - fn_print_ok "Checking for update: ${remotelocation}: checking local build" - fn_script_log_pass "Checking local build" - else + localbuild=$(${executable} --version > /dev/null/ 2>&1 | grep "Version:" | awk '{print $2}') + if [ -z "${localbuild}" ]; then + fn_print_error "Checking local build: ${remotelocation}: missing local build info" + fn_script_log_error "Missing local build info" + fn_script_log_error "Set localbuild to 0" localbuild="0" - fn_print_error "Checking for update: ${remotelocation}: checking local build" - fn_script_log_error "Checking local build" + else + fn_print_ok "Checking local build: ${remotelocation}" + fn_script_log_pass "Checking local build" fi } @@ -68,7 +69,6 @@ fn_update_factorio_remotebuild() { fn_update_factorio_compare() { fn_print_dots "Checking for update: ${remotelocation}" # Removes dots so if statement can compare version numbers. - fn_print_dots "Checking for update: ${remotelocation}" localbuilddigit=$(echo -e "${localbuild}" | tr -cd '[:digit:]') remotebuilddigit=$(echo -e "${remotebuild}" | tr -cd '[:digit:]') if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ] || [ "${forceupdate}" == "1" ]; then @@ -84,40 +84,44 @@ fn_update_factorio_compare() { fn_script_log_info "Update available" fn_script_log_info "Local build: ${localbuild} ${factorioarch}" fn_script_log_info "Remote build: ${remotebuild} ${factorioarch}" - if [ -v "${branch}" ]; then + if [ -n "${branch}" ]; then fn_script_log_info "Branch: ${branch}" fi fn_script_log_info "${localbuild} > ${remotebuild}" - unset updateonstart - check_status.sh - # If server stopped. - if [ "${status}" == "0" ]; then - exitbypass=1 - fn_update_factorio_dl - if [ "${requirerestart}" == "1" ]; then + if [ "${commandname}" == "UPDATE" ]; then + unset updateonstart + check_status.sh + # If server stopped. + if [ "${status}" == "0" ]; then exitbypass=1 - command_start.sh - fn_firstcommand_reset + fn_update_factorio_dl + if [ "${localbuild}" == "0" ]; then + exitbypass=1 + command_start.sh + fn_firstcommand_reset + exitbypass=1 + command_stop.sh + fn_firstcommand_reset + fi + # If server started. + else + fn_print_restart_warning exitbypass=1 command_stop.sh fn_firstcommand_reset + exitbypass=1 + fn_update_factorio_dl + exitbypass=1 + command_start.sh + fn_firstcommand_reset fi - # If server started. - else - fn_print_restart_warning - exitbypass=1 - command_stop.sh - fn_firstcommand_reset - exitbypass=1 - fn_update_factorio_dl - exitbypass=1 - command_start.sh - fn_firstcommand_reset + unset exitbypass + date +%s > "${lockdir}/lastupdate.lock" + alert="update" + elif [ "${commandname}" == "CHECK-UPDATE" ]; then + alert="check-update" fi - unset exitbypass - date +%s > "${lockdir}/lastupdate.lock" - alert="update" alert.sh else fn_print_ok_nl "Checking for update: ${remotelocation}" diff --git a/lgsm/functions/update_jediknight2.sh b/lgsm/functions/update_jediknight2.sh index 421bc543f..ba52d51a6 100644 --- a/lgsm/functions/update_jediknight2.sh +++ b/lgsm/functions/update_jediknight2.sh @@ -27,44 +27,13 @@ fn_update_jk2_dl() { fn_update_jk2_localbuild() { # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" - # Uses log file to gather info. - # Log is generated and cleared on startup but filled on shutdown. - requirerestart=1 + # Uses log file to get local build. localbuild=$(grep "\"version\"" "${consolelogdir}"/* 2> /dev/null | sed 's/.*://' | awk '{print $1}' | head -n 1) if [ -z "${localbuild}" ]; then - fn_print_error "Checking local build: ${remotelocation}" - fn_print_error_nl "Checking local build: ${remotelocation}: no log files containing version info" - fn_print_info_nl "Checking local build: ${remotelocation}: forcing server restart" - fn_script_log_error "No log files containing version info" - fn_script_log_info "Forcing server restart" - - check_status.sh - # If server stopped. - if [ "${status}" == "0" ]; then - exitbypass=1 - command_start.sh - fn_firstcommand_reset - sleep 3 - exitbypass=1 - command_stop.sh - fn_firstcommand_reset - # If server started. - else - exitbypass=1 - command_stop.sh - fn_firstcommand_reset - fi - fi - - if [ -z "${localbuild}" ]; then - localbuild=$(grep Version "$(ls -tr "${consolelogdir}"/* 2> /dev/null)" | tail -1 | sed 's/.*Version //') - fi - - if [ -z "${localbuild}" ]; then - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info" + fn_print_error "Checking local build: ${remotelocation}: missing local build info" fn_script_log_error "Missing local build info" fn_script_log_error "Set localbuild to 0" + localbuild="0" else fn_print_ok "Checking local build: ${remotelocation}" fn_script_log_pass "Checking local build" @@ -112,34 +81,39 @@ fn_update_jk2_compare() { fn_script_log_info "Remote build: ${remotebuild} ${jk2arch}" fn_script_log_info "${localbuild} > ${remotebuild}" - unset updateonstart - check_status.sh - # If server stopped. - if [ "${status}" == "0" ]; then - exitbypass=1 - fn_update_jk2_dl - if [ "${requirerestart}" == "1" ]; then + if [ "${commandname}" == "UPDATE" ]; then + unset updateonstart + check_status.sh + # If server stopped. + if [ "${status}" == "0" ]; then exitbypass=1 - command_start.sh - fn_firstcommand_reset + fn_update_jk2_dl + if [ "${localbuild}" == "0" ]; then + exitbypass=1 + command_start.sh + fn_firstcommand_reset + exitbypass=1 + command_stop.sh + fn_firstcommand_reset + fi + # If server started. + else + fn_print_restart_warning exitbypass=1 command_stop.sh fn_firstcommand_reset + exitbypass=1 + fn_update_jk2_dl + exitbypass=1 + command_start.sh + fn_firstcommand_reset fi - # If server started. - else - fn_print_restart_warning - exitbypass=1 - command_stop.sh - fn_firstcommand_reset - exitbypass=1 - fn_update_jk2_dl - exitbypass=1 - command_start.sh - fn_firstcommand_reset + unset exitbypass + date +%s > "${lockdir}/lastupdate.lock" + alert="update" + elif [ "${commandname}" == "CHECK-UPDATE" ]; then + alert="check-update" fi - date +%s > "${lockdir}/lastupdate.lock" - alert="update" alert.sh else fn_print_ok_nl "Checking for update: ${remotelocation}" diff --git a/lgsm/functions/update_minecraft.sh b/lgsm/functions/update_minecraft.sh index d20b98ef4..28fdcaf06 100644 --- a/lgsm/functions/update_minecraft.sh +++ b/lgsm/functions/update_minecraft.sh @@ -33,16 +33,17 @@ fn_update_minecraft_dl() { fn_update_minecraft_localbuild() { # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" - # Uses executable to find local build. + # Uses executable to get local build. cd "${executabledir}" || exit - if [ -f "minecraft_server.jar" ]; then - localbuild=$(unzip -p "minecraft_server.jar" version.json | jq -r '.id') + localbuild=$(unzip -p "minecraft_server.jar" version.json | jq -r '.id') + if [ -z "${localbuild}" ]; then + fn_print_error "Checking local build: ${remotelocation}: missing local build info" + fn_script_log_error "Missing local build info" + fn_script_log_error "Set localbuild to 0" + localbuild="0" + else fn_print_ok "Checking local build: ${remotelocation}" fn_script_log_pass "Checking local build" - else - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}" - fn_script_log_error "Checking local build" fi } @@ -98,35 +99,39 @@ fn_update_minecraft_compare() { fn_script_log_info "Remote build: ${remotebuild}" fn_script_log_info "${localbuild} > ${remotebuild}" - unset updateonstart - check_status.sh - # If server stopped. - if [ "${status}" == "0" ]; then - exitbypass=1 - fn_update_minecraft_dl - if [ "${requirerestart}" == "1" ]; then + if [ "${commandname}" == "UPDATE" ]; then + unset updateonstart + check_status.sh + # If server stopped. + if [ "${status}" == "0" ]; then exitbypass=1 - command_start.sh - fn_firstcommand_reset + fn_update_minecraft_dl + if [ "${localbuild}" == "0" ]; then + exitbypass=1 + command_start.sh + fn_firstcommand_reset + exitbypass=1 + command_stop.sh + fn_firstcommand_reset + fi + # If server started. + else + fn_print_restart_warning exitbypass=1 command_stop.sh fn_firstcommand_reset + exitbypass=1 + fn_update_minecraft_dl + exitbypass=1 + command_start.sh + fn_firstcommand_reset fi - # If server started. - else - fn_print_restart_warning - exitbypass=1 - command_stop.sh - fn_firstcommand_reset - exitbypass=1 - fn_update_minecraft_dl - exitbypass=1 - command_start.sh - fn_firstcommand_reset + unset exitbypass + date +%s > "${lockdir}/lastupdate.lock" + alert="update" + elif [ "${commandname}" == "CHECK-UPDATE" ]; then + alert="check-update" fi - unset exitbypass - date +%s > "${lockdir}/lastupdate.lock" - alert="update" alert.sh else fn_print_ok_nl "Checking for update: ${remotelocation}" diff --git a/lgsm/functions/update_minecraft_bedrock.sh b/lgsm/functions/update_minecraft_bedrock.sh index 163e076aa..e4422dc15 100644 --- a/lgsm/functions/update_minecraft_bedrock.sh +++ b/lgsm/functions/update_minecraft_bedrock.sh @@ -35,44 +35,13 @@ fn_update_minecraft_dl() { fn_update_minecraft_localbuild() { # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" - # Uses log file to gather info. - # Log is generated and cleared on startup but filled on shutdown. - requirerestart=1 + # Uses log file to get local build. localbuild=$(grep Version "${consolelogdir}"/* 2> /dev/null | tail -1 | sed 's/.*Version //') if [ -z "${localbuild}" ]; then - fn_print_error "Checking local build: ${remotelocation}" - fn_print_error_nl "Checking local build: ${remotelocation}: no log files containing version info" - fn_print_info_nl "Checking local build: ${remotelocation}: forcing server restart" - fn_script_log_error "No log files containing version info" - fn_script_log_info "Forcing server restart" - - check_status.sh - # If server stopped. - if [ "${status}" == "0" ]; then - exitbypass=1 - command_start.sh - fn_firstcommand_reset - sleep 3 - exitbypass=1 - command_stop.sh - fn_firstcommand_reset - # If server started. - else - exitbypass=1 - command_stop.sh - fn_firstcommand_reset - fi - fi - - if [ -z "${localbuild}" ]; then - localbuild=$(grep Version "$(ls -tr "${consolelogdir}"/* 2> /dev/null)" | tail -1 | sed 's/.*Version //') - fi - - if [ -z "${localbuild}" ]; then - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info" + fn_print_error "Checking local build: ${remotelocation}: missing local build info" fn_script_log_error "Missing local build info" fn_script_log_error "Set localbuild to 0" + localbuild="0" else fn_print_ok "Checking local build: ${remotelocation}" fn_script_log_pass "Checking local build" @@ -125,35 +94,39 @@ fn_update_minecraft_compare() { fn_script_log_info "Remote build: ${remotebuild}" fn_script_log_info "${localbuild} > ${remotebuild}" - unset updateonstart - check_status.sh - # If server stopped. - if [ "${status}" == "0" ]; then - exitbypass=1 - fn_update_minecraft_dl - if [ "${requirerestart}" == "1" ]; then + if [ "${commandname}" == "UPDATE" ]; then + unset updateonstart + check_status.sh + # If server stopped. + if [ "${status}" == "0" ]; then exitbypass=1 - command_start.sh - fn_firstcommand_reset + fn_update_minecraft_dl + if [ "${localbuild}" == "0" ]; then + exitbypass=1 + command_start.sh + fn_firstcommand_reset + exitbypass=1 + command_stop.sh + fn_firstcommand_reset + fi + # If server started. + else + fn_print_restart_warning exitbypass=1 command_stop.sh fn_firstcommand_reset + exitbypass=1 + fn_update_minecraft_dl + exitbypass=1 + command_start.sh + fn_firstcommand_reset fi - # If server started. - else - fn_print_restart_warning - exitbypass=1 - command_stop.sh - fn_firstcommand_reset - exitbypass=1 - fn_update_minecraft_dl - exitbypass=1 - command_start.sh - fn_firstcommand_reset + unset exitbypass + date +%s > "${lockdir}/lastupdate.lock" + alert="update" + elif [ "${commandname}" == "CHECK-UPDATE" ]; then + alert="check-update" fi - unset exitbypass - date +%s > "${lockdir}/lastupdate.lock" - alert="update" alert.sh else fn_print_ok_nl "Checking for update: ${remotelocation}" diff --git a/lgsm/functions/update_mta.sh b/lgsm/functions/update_mta.sh index 61216b809..cfb45e8b6 100644 --- a/lgsm/functions/update_mta.sh +++ b/lgsm/functions/update_mta.sh @@ -29,68 +29,13 @@ fn_update_mta_dl() { fn_update_mta_localbuild() { # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" - # Uses log file to gather info. - # Gives time for log file to generate. - requirerestart=1 - if [ ! -f "${serverfiles}/mods/deathmatch/logs/server.log" ]; then - fn_print_error "Checking local build: ${remotelocation}" - fn_print_error_nl "Checking local build: ${remotelocation}: no log files containing version info" - fn_print_info_nl "Checking local build: ${remotelocation}: forcing server restart" - fn_script_log_error "No log files containing version info" - fn_script_log_info "Forcing server restart" - exitbypass=1 - command_stop.sh - exitbypass=1 - command_start.sh - fn_firstcommand_reset - totalseconds=0 - # Check again, allow time to generate logs. - while [ ! -f "${serverfiles}/mods/deathmatch/logs/server.log" ]; do - sleep 1 - fn_print_info "Checking local build: ${remotelocation}: waiting for log file: ${totalseconds}" - if [ -v "${loopignore}" ]; then - loopignore=1 - fn_script_log_info "Waiting for log file to generate" - fi - - if [ "${totalseconds}" -gt "120" ]; then - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}: waiting for log file: missing log file" - fn_script_log_error "Missing log file" - fn_script_log_error "Set localbuild to 0" - fi - - totalseconds=$((totalseconds + 1)) - done - fi - - if [ -z "${localbuild}" ]; then - localbuild=$(grep "= Multi Theft Auto: San Andreas v" "${serverfiles}/mods/deathmatch/logs/server.log" | awk '{ print $7 }' | sed -r 's/^.{1}//' | tail -1) - fi - + # Uses log file to get local build. + localbuild=$(grep "= Multi Theft Auto: San Andreas v" "${serverfiles}/mods/deathmatch/logs/server.log" | awk '{ print $7 }' | sed -r 's/^.{1}//' | tail -1) if [ -z "${localbuild}" ]; then - # Gives time for var to generate. - totalseconds=0 - for seconds in {1..120}; do - fn_print_info "Checking local build: ${remotelocation}: waiting for local build: ${totalseconds}" - if [ -z "${loopignore}" ]; then - loopignore=1 - fn_script_log_info "Waiting for local build to generate" - fi - localbuild=$(grep "= Multi Theft Auto: San Andreas v" "${serverfiles}/mods/deathmatch/logs/server.log" | awk '{ print $7 }' | sed -r 's/^.{1}//' | tail -1) - if [ "${localbuild}" ]; then - break - fi - sleep 1 - totalseconds=$((totalseconds + 1)) - done - fi - - if [ -z "${localbuild}" ]; then - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info" + fn_print_error "Checking local build: ${remotelocation}: missing local build info" fn_script_log_error "Missing local build info" fn_script_log_error "Set localbuild to 0" + localbuild="0" else fn_print_ok "Checking local build: ${remotelocation}" fn_script_log_pass "Checking local build" @@ -127,13 +72,13 @@ fn_update_mta_compare() { localbuilddigit=$(echo -e "${localbuild}" | tr -cd '[:digit:]') remotebuilddigit=$(echo -e "${remotebuild}" | tr -cd '[:digit:]') if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ] || [ "${forceupdate}" == "1" ]; then - fn_print_ok_nl "Checking for update: ${remotelocation}" if [ "${forceupdate}" == "1" ]; then # forceupdate bypasses checks, useful for small build changes mtaupdatestatus="forced" else mtaupdatestatus="available" fi + fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update ${mtaupdatestatus}:" echo -e "* Local build: ${red}${localbuild}${default}" @@ -150,7 +95,7 @@ fn_update_mta_compare() { if [ "${status}" == "0" ]; then exitbypass=1 fn_update_mta_dl - if [ "${requirerestart}" == "1" ]; then + if [ "${localbuild}" == "0" ]; then exitbypass=1 command_start.sh fn_firstcommand_reset diff --git a/lgsm/functions/update_papermc.sh b/lgsm/functions/update_papermc.sh index 302e0baac..d1bff85f4 100644 --- a/lgsm/functions/update_papermc.sh +++ b/lgsm/functions/update_papermc.sh @@ -24,7 +24,7 @@ fn_update_papermc_dl() { fn_print_ok_eol_nl fn_script_log_pass "Copying to ${serverfiles}" chmod u+x "${serverfiles}/${executable#./}" - echo "${remotebuild}" > "${localversionfile}" + echo "${remotebuild}" > "${localbuildfile}" fn_clear_tmp else fn_print_fail_eol_nl @@ -35,74 +35,86 @@ fn_update_papermc_dl() { fn_update_papermc_localbuild() { # Gets local build info. - fn_print_dots "Checking for update: ${remotelocation}: checking local build" - sleep 0.5 - - if [ ! -f "${localversionfile}" ]; then - fn_print_error_nl "Checking for update: ${remotelocation}: checking local build: no local build files" - fn_script_log_error "No local build file found" - else - localbuild=$(head -n 1 "${localversionfile}") - fi - + fn_print_dots "Checking local build: ${remotelocation}" + # Uses version file to get local build. + localbuild=$(head -n 1 "${localbuildfile}" > /dev/null 2>&1) if [ -z "${localbuild}" ]; then + fn_print_error "Checking local build: ${remotelocation}: missing local build info" + fn_script_log_error "Missing local build info" + fn_script_log_error "Set localbuild to 0" localbuild="0" - fn_print_error "Checking for update: ${remotelocation}: waiting for local build: missing local build info" - fn_script_log_error "Missing local build info, Set localbuild to 0" else - fn_print_ok "Checking for update: ${remotelocation}: checking local build" + fn_print_ok "Checking local build: ${remotelocation}" fn_script_log_pass "Checking local build" fi - sleep 0.5 } fn_update_papermc_remotebuild() { # Gets remote build info. remotebuild=$(curl -s "https://${remotelocation}/api/v2/projects/${paperproject}/versions/${paperversion}" | jq -r '.builds[-1]') - - # Checks if remotebuild variable has been set. - if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then - fn_print_failure "Unable to get remote build" - fn_script_log_fatal "Unable to get remote build" - core_exit.sh + if [ "${firstcommandname}" != "INSTALL" ]; then + fn_print_dots "Checking remote build: ${remotelocation}" + # Checks if remotebuild variable has been set. + if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then + fn_print_fail "Checking remote build: ${remotelocation}" + fn_script_log_fatal "Checking remote build" + core_exit.sh + else + fn_print_ok "Checking remote build: ${remotelocation}" + fn_script_log_pass "Checking remote build" + fi else - fn_print_ok "Got build for version ${paperversion}" - fn_script_log "Got build for version ${paperversion}" + # Checks if remotebuild variable has been set. + if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then + fn_print_failure "Unable to get remote build" + fn_script_log_fatal "Unable to get remote build" + core_exit.sh + fi fi } fn_update_papermc_compare() { fn_print_dots "Checking for update: ${remotelocation}" - sleep 0.5 if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" - echo -e "Update available for version ${paperversion}" + echo -e "Update available" echo -e "* Local build: ${red}${localbuild}${default}" echo -e "* Remote build: ${green}${remotebuild}${default}" - fn_script_log_info "Update available for version ${paperversion}" + echo -en "\n" + fn_script_log_info "Update available" fn_script_log_info "Local build: ${localbuild}" fn_script_log_info "Remote build: ${remotebuild}" fn_script_log_info "${localbuild} > ${remotebuild}" - echo -en "\n" - echo -en "applying update.\r" - echo -en "\n" unset updateonstart - check_status.sh # If server stopped. if [ "${status}" == "0" ]; then - fn_update_papermc_dl + exitbypass=1 + fn_update_ut99_dl + if [ "${localbuild}" == "0" ]; then + exitbypass=1 + command_start.sh + fn_firstcommand_reset + exitbypass=1 + command_stop.sh + fn_firstcommand_reset + fi # If server started. else + fn_print_restart_warning exitbypass=1 command_stop.sh + fn_firstcommand_reset exitbypass=1 - fn_update_papermc_dl + fn_update_ut99_dl exitbypass=1 command_start.sh + fn_firstcommand_reset fi + unset exitbypass + date +%s > "${lockdir}/lastupdate.lock" alert="update" alert.sh else @@ -128,12 +140,7 @@ elif [ "${shortname}" == "wmc" ]; then paperproject="waterfall" fi -localversionfile="${datadir}/${paperproject}-version" - -# check if datadir was created, if not create it -if [ ! -d "${datadir}" ]; then - mkdir -p "${datadir}" -fi +localbuildfile="${serverfiles}/version.txt" # check version if the user did set one and check it if [ "${mcversion}" == "latest" ]; then diff --git a/lgsm/functions/update_ts3.sh b/lgsm/functions/update_ts3.sh index be5c9e06f..8ae22e369 100644 --- a/lgsm/functions/update_ts3.sh +++ b/lgsm/functions/update_ts3.sh @@ -37,68 +37,13 @@ fn_update_ts3_dl() { fn_update_ts3_localbuild() { # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" - # Uses log file to gather info. - # Gives time for log file to generate. - requirerestart=1 - if [ ! -d "${serverfiles}/logs" ] || [ -z "$(find "${serverfiles}/logs/"* -name 'ts3server*_0.log' 2> /dev/null)" ]; then - fn_print_error "Checking local build: ${remotelocation}" - fn_print_error_nl "Checking local build: ${remotelocation}: no log files containing version info" - fn_print_info_nl "Checking local build: ${remotelocation}: forcing server restart" - fn_script_log_error "No log files containing version info" - fn_script_log_info "Forcing server restart" - exitbypass=1 - command_stop.sh - exitbypass=1 - command_start.sh - fn_firstcommand_reset - totalseconds=0 - # Check again, allow time to generate logs. - while [ ! -d "${serverfiles}/logs" ] || [ -z "$(find "${serverfiles}/logs/"* -name 'ts3server*_0.log' 2> /dev/null)" ]; do - sleep 1 - fn_print_info "Checking local build: ${remotelocation}: waiting for log file: ${totalseconds}" - if [ -v "${loopignore}" ]; then - loopignore=1 - fn_script_log_info "Waiting for log file to generate" - fi - - if [ "${totalseconds}" -gt "120" ]; then - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}: waiting for log file: missing log file" - fn_script_log_error "Missing log file" - fn_script_log_error "Set localbuild to 0" - fi - - totalseconds=$((totalseconds + 1)) - done - fi - - if [ -z "${localbuild}" ]; then - localbuild=$(cat "$(find ./* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | tail -1) - fi - + # Uses log file to get local build. + localbuild=$(cat "$(find ./* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | tail -1) if [ -z "${localbuild}" ]; then - # Gives time for var to generate. - totalseconds=0 - for seconds in {1..120}; do - fn_print_info "Checking local build: ${remotelocation}: waiting for local build: ${totalseconds}" - if [ -z "${loopignore}" ]; then - loopignore=1 - fn_script_log_info "Waiting for local build to generate" - fi - localbuild=$(cat "$(find ./* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | tail -1) - if [ "${localbuild}" ] || [ "${seconds}" == "120" ]; then - break - fi - sleep 1 - totalseconds=$((totalseconds + 1)) - done - fi - - if [ -z "${localbuild}" ]; then - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info" + fn_print_error "Checking local build: ${remotelocation}: missing local build info" fn_script_log_error "Missing local build info" fn_script_log_error "Set localbuild to 0" + localbuild="0" else fn_print_ok "Checking local build: ${remotelocation}" fn_script_log_pass "Checking local build" @@ -113,6 +58,7 @@ fn_update_ts3_remotebuild() { elif [ "${ts3arch}" == "x86" ]; then remotebuild=$(echo -e "${ts3latestdata}" | jq -r '.x86.version') fi + if [ "${firstcommandname}" != "INSTALL" ]; then fn_print_dots "Checking remote build: ${remotelocation}" # Checks if remotebuild variable has been set. @@ -157,7 +103,7 @@ fn_update_ts3_compare() { if [ "${status}" == "0" ]; then exitbypass=1 fn_update_ts3_dl - if [ "${requirerestart}" == "1" ]; then + if [ "${localbuild}" == "0" ]; then exitbypass=1 command_start.sh fn_firstcommand_reset diff --git a/lgsm/functions/update_ut99.sh b/lgsm/functions/update_ut99.sh index 8ac771e04..242bead7d 100644 --- a/lgsm/functions/update_ut99.sh +++ b/lgsm/functions/update_ut99.sh @@ -12,7 +12,7 @@ fn_update_ut99_dl() { remotebuildfilename=$(curl --connect-timeout 10 -sL "https://api.github.com/repos/OldUnreal/UnrealTournamentPatches/releases/latest" | jq -r '.assets[]|select(.browser_download_url | contains("Linux-amd64")) | .name') fn_fetch_file "${remotebuildlink}" "${tmpdir}" "${remotebuildfilename}" "" "norun" "noforce" "nohash" - fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}/${remotebuildfilename%.tar.bz2}" + fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}" local exitcode=$? if [ "${exitcode}" == "0" ]; then fn_print_ok_eol_nl @@ -30,15 +30,13 @@ fn_update_ut99_dl() { fn_update_ut99_localbuild() { # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" - # Uses log file to gather info. - # Log is generated and cleared on startup but filled on shutdown. - requirerestart=1 - localbuild=$(cat "${serverfiles}/version.txt" 2> /dev/null) + # Uses version file to get local build. + localbuild=$(head -n 1 "${localbuildfile}" > /dev/null 2>&1) if [ -z "${localbuild}" ]; then - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info" + fn_print_error "Checking local build: ${remotelocation}: missing local build info" fn_script_log_error "Missing local build info" fn_script_log_error "Set localbuild to 0" + localbuild="0" else fn_print_ok "Checking local build: ${remotelocation}" fn_script_log_pass "Checking local build" @@ -47,7 +45,7 @@ fn_update_ut99_localbuild() { fn_update_ut99_remotebuild() { # Gets remote build info. - remotebuild=$(curl --connect-timeout 10 -sL "https://api.github.com/repos/OldUnreal/UnrealTournamentPatches/releases/latest" | jq -r '.tag_name') + remotebuild=$(curl -s "https://api.github.com/repos/OldUnreal/UnrealTournamentPatches/releases/latest" | jq -r '.tag_name') if [ "${firstcommandname}" != "INSTALL" ]; then fn_print_dots "Checking remote build: ${remotelocation}" # Checks if remotebuild variable has been set. @@ -78,12 +76,12 @@ fn_update_ut99_compare() { fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" - echo -e "* Local build: ${red}${localbuild} ${ut99arch}${default}" - echo -e "* Remote build: ${green}${remotebuild} ${ut99arch}${default}" + echo -e "* Local build: ${red}${localbuild}${default}" + echo -e "* Remote build: ${green}${remotebuild}${default}" echo -en "\n" fn_script_log_info "Update available" - fn_script_log_info "Local build: ${localbuild} ${ut99arch}" - fn_script_log_info "Remote build: ${remotebuild} ${ut99arch}" + fn_script_log_info "Local build: ${localbuild}" + fn_script_log_info "Remote build: ${remotebuild}" fn_script_log_info "${localbuild} > ${remotebuild}" unset updateonstart @@ -92,7 +90,7 @@ fn_update_ut99_compare() { if [ "${status}" == "0" ]; then exitbypass=1 fn_update_ut99_dl - if [ "${requirerestart}" == "1" ]; then + if [ "${localbuild}" == "0" ]; then exitbypass=1 command_start.sh fn_firstcommand_reset @@ -112,6 +110,7 @@ fn_update_ut99_compare() { command_start.sh fn_firstcommand_reset fi + unset exitbypass date +%s > "${lockdir}/lastupdate.lock" alert="update" alert.sh @@ -119,20 +118,19 @@ fn_update_ut99_compare() { fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "No update available" - echo -e "* Local build: ${green}${localbuild} ${ut99arch}${default}" - echo -e "* Remote build: ${green}${remotebuild} ${ut99arch}${default}" + echo -e "* Local build: ${green}${localbuild}${default}" + echo -e "* Remote build: ${green}${remotebuild}${default}" echo -en "\n" fn_script_log_info "No update available" - fn_script_log_info "Local build: ${localbuild} ${ut99arch}" - fn_script_log_info "Remote build: ${remotebuild} ${ut99arch}" + fn_script_log_info "Local build: ${localbuild}" + fn_script_log_info "Remote build: ${remotebuild}" fi } # The location where the builds are checked and downloaded. remotelocation="github.com" -# Game server architecture. -ut99arch="x64" +localbuildfile="${serverfiles}/version.txt" if [ "${firstcommandname}" == "INSTALL" ]; then fn_update_ut99_remotebuild diff --git a/lgsm/functions/update_vintagestory.sh b/lgsm/functions/update_vintagestory.sh index 905384922..eb5d3fadd 100755 --- a/lgsm/functions/update_vintagestory.sh +++ b/lgsm/functions/update_vintagestory.sh @@ -23,16 +23,17 @@ fn_update_vs_dl() { fn_update_vs_localbuild() { # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" - # Uses executable to find local build. + # Uses executable to get local build. cd "${executabledir}" || exit - if [ -f "${executable}" ]; then - localbuild="$(${preexecutable} ${executable} --version | sed '/^[[:space:]]*$/d')" + localbuild="$(${preexecutable} ${executable} --version | sed '/^[[:space:]]*$/d')" + if [ -z "${localbuild}" ]; then + fn_print_error "Checking local build: ${remotelocation}: missing local build info" + fn_script_log_error "Missing local build info" + fn_script_log_error "Set localbuild to 0" + localbuild="0" + else fn_print_ok "Checking local build: ${remotelocation}" fn_script_log_pass "Checking local build" - else - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}" - fn_script_log_error "Checking local build" fi } @@ -88,7 +89,7 @@ fn_update_vs_compare() { if [ "${status}" == "0" ]; then exitbypass=1 fn_update_vs_dl - if [ "${requirerestart}" == "1" ]; then + if [ "${localbuild}" == "0" ]; then exitbypass=1 command_start.sh fn_firstcommand_reset