From b6f2a6f46c8d8cec18cc04e61865c65b9e14aeac Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Mon, 20 Mar 2023 22:49:52 +0000 Subject: [PATCH] streamline mcserver --- lgsm/functions/core_steamcmd.sh | 2 +- lgsm/functions/update_factorio.sh | 2 +- lgsm/functions/update_jediknight2.sh | 2 +- lgsm/functions/update_minecraft.sh | 94 +++++++++++----------- lgsm/functions/update_minecraft_bedrock.sh | 2 +- lgsm/functions/update_mta.sh | 2 +- lgsm/functions/update_papermc.sh | 8 +- 7 files changed, 57 insertions(+), 55 deletions(-) diff --git a/lgsm/functions/core_steamcmd.sh b/lgsm/functions/core_steamcmd.sh index 9d54cfde1..89746c4c0 100755 --- a/lgsm/functions/core_steamcmd.sh +++ b/lgsm/functions/core_steamcmd.sh @@ -168,7 +168,7 @@ fn_update_steamcmd_localbuild() { } fn_update_steamcmd_remotebuild() { - # Gets remote build info. + # Get remote build info. if [ -d "${steamcmddir}" ]; then cd "${steamcmddir}" || exit fi diff --git a/lgsm/functions/update_factorio.sh b/lgsm/functions/update_factorio.sh index d47fad086..981718f3f 100644 --- a/lgsm/functions/update_factorio.sh +++ b/lgsm/functions/update_factorio.sh @@ -32,7 +32,7 @@ fn_update_localbuild() { } fn_update_remotebuild() { - # Gets remote build info. + # Get remote build info. apiurl="https://factorio.com/get-download/${branch}/headless/${factorioarch}" remotebuildresponse=$(curl -s "${apiurl}") remotebuildversion=$(echo "${remotebuildresponse}" | grep -o '[0-9]\.[0-9]\{1,\}\.[0-9]\{1,\}' | head -1) diff --git a/lgsm/functions/update_jediknight2.sh b/lgsm/functions/update_jediknight2.sh index 31314d5c5..f58b5cea1 100644 --- a/lgsm/functions/update_jediknight2.sh +++ b/lgsm/functions/update_jediknight2.sh @@ -41,7 +41,7 @@ fn_update_jk2_localbuild() { } fn_update_jk2_remotebuild() { - # Gets remote build info. + # Get remote build info. remotebuild=$(curl -s "https://api.github.com/repos/mvdevs/jk2mv/releases/latest" | grep dedicated.zip | tail -1 | awk -F"/" '{ print $8 }') if [ "${firstcommandname}" != "INSTALL" ]; then fn_print_dots "Checking remote build: ${remotelocation}" diff --git a/lgsm/functions/update_minecraft.sh b/lgsm/functions/update_minecraft.sh index b87215a26..67b6383fd 100644 --- a/lgsm/functions/update_minecraft.sh +++ b/lgsm/functions/update_minecraft.sh @@ -7,30 +7,12 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -fn_update_minecraft_dl() { - # Generate link to version manifest json. - remotebuildurl=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r --arg branch ${branch} --arg mcversion ${remotebuild} '.versions | .[] | select(.type==$branch and .id==$mcversion) | .url') - # Generate link to server.jar - remotebuildurl=$(curl -s "${remotebuildurl}" | jq -r '.downloads.server.url') - - fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "minecraft_server.${remotebuild}.jar" "" "norun" "noforce" "nohash" - echo -e "copying to ${serverfiles}...\c" - cp "${tmpdir}/minecraft_server.${remotebuild}.jar" "${serverfiles}/minecraft_server.jar" - local exitcode=$? - if [ "${exitcode}" == "0" ]; then - fn_print_ok_eol_nl - fn_script_log_pass "Copying to ${serverfiles}" - chmod u+x "${serverfiles}/minecraft_server.jar" - fn_clear_tmp - else - fn_print_fail_eol_nl - fn_script_log_fatal "Copying to ${serverfiles}" - fn_clear_tmp - core_exit.sh - fi +fn_update_dl() { + # Download and extract files to serverfiles + fn_fetch_file "${remotebuildurl}" "" "" "" "${serverfiles}" "minecraft_server.jar" "chmodx" "norun" "noforce" "nohash" } -fn_update_minecraft_localbuild() { +fn_update_localbuild() { # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" # Uses executable to get local build. @@ -47,23 +29,29 @@ fn_update_minecraft_localbuild() { fi } -fn_update_minecraft_remotebuild() { - # Gets remote build info. +fn_update_remotebuild() { + # Get remote build info. + apiurl="https://launchermeta.mojang.com/mc/game/version_manifest.json" + remotebuildresponse=$(curl -s "${apiurl}") # Latest release. if [ "${branch}" == "release" ] && [ "${mcversion}" == "latest" ]; then - remotebuild=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r '.latest.release') + remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '.latest.release') # Latest snapshot. elif [ "${branch}" == "snapshot" ] && [ "${mcversion}" == "latest" ]; then - remotebuild=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r '.latest.snapshot') + remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '.latest.snapshot') # Specific release/snapshot. else - remotebuild=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r --arg branch ${branch} --arg mcversion ${mcversion} '.versions | .[] | select(.type==$branch and .id==$mcversion) | .id') + remotebuildversion=$(echo "${remotebuildresponse}" | jq -r --arg branch ${branch} --arg mcversion ${mcversion} '.versions | .[] | select(.type==$branch and .id==$mcversion) | .id') fi + # Generate link to version manifest json. + remotebuildmanifest=$(echo "${remotebuildresponse}" | jq -r --arg branch ${branch} --arg mcversion ${remotebuildversion} '.versions | .[] | select(.type==$branch and .id==$mcversion) | .url') + # Generate link to server.jar + remotebuildurl=$(curl -s "${remotebuildmanifest}" | jq -r '.downloads.server.url') if [ "${firstcommandname}" != "INSTALL" ]; then fn_print_dots "Checking remote build: ${remotelocation}" - # Checks if remotebuild variable has been set. - if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then + # Checks if remotebuildversion variable has been set. + if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then fn_print_fail "Checking remote build: ${remotelocation}" fn_script_log_fatal "Checking remote build" core_exit.sh @@ -73,7 +61,7 @@ fn_update_minecraft_remotebuild() { fi else # Checks if remotebuild variable has been set. - if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then + if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then fn_print_failure "Unable to get remote build" fn_script_log_fatal "Unable to get remote build" core_exit.sh @@ -81,30 +69,39 @@ fn_update_minecraft_remotebuild() { fi } -fn_update_minecraft_compare() { +fn_update_compare() { fn_print_dots "Checking for update: ${remotelocation}" - if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then + if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" echo -e "* Local build: ${red}${localbuild}${default}" - echo -e "* Remote build: ${green}${remotebuild}${default}" + echo -e "* Remote build: ${green}${remotebuildversion}${default}" if [ -n "${branch}" ]; then echo -e "* Branch: ${branch}" fi + if [ -f "${rootdir}/.dev-debug" ]; then + echo -e "Remote build info" + echo -e "* apiurl: ${apiurl}" + echo -e "* remotebuildfilename: ${remotebuildfilename}" + echo -e "* remotebuildurl: ${remotebuildurl}" + echo -e "* remotebuildversion: ${remotebuildversion}" + fi 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}" + fn_script_log_info "Remote build: ${remotebuildversion}" + if [ -n "${branch}" ]; then + fn_script_log_info "Branch: ${branch}" + fi + fn_script_log_info "${localbuild} > ${remotebuildversion}" if [ "${commandname}" == "UPDATE" ]; then unset updateonstart check_status.sh # If server stopped. if [ "${status}" == "0" ]; then - exitbypass=1 - fn_update_minecraft_dl + fn_update_dl if [ "${localbuild}" == "0" ]; then exitbypass=1 command_start.sh @@ -121,7 +118,7 @@ fn_update_minecraft_compare() { command_stop.sh fn_firstcommand_reset exitbypass=1 - fn_update_minecraft_dl + fn_update_dl exitbypass=1 command_start.sh fn_firstcommand_reset @@ -138,17 +135,24 @@ fn_update_minecraft_compare() { echo -en "\n" echo -e "No update available" echo -e "* Local build: ${green}${localbuild}${default}" - echo -e "* Remote build: ${green}${remotebuild}${default}" + echo -e "* Remote build: ${green}${remotebuildversion}${default}" if [ -n "${branch}" ]; then echo -e "* Branch: ${branch}" fi echo -en "\n" fn_script_log_info "No update available" fn_script_log_info "Local build: ${localbuild}" - fn_script_log_info "Remote build: ${remotebuild}" + fn_script_log_info "Remote build: ${remotebuildversion}" if [ -n "${branch}" ]; then fn_script_log_info "Branch: ${branch}" fi + if [ -f "${rootdir}/.dev-debug" ]; then + echo -e "Remote build info" + echo -e "* apiurl: ${apiurl}" + echo -e "* remotebuildfilename: ${remotebuildfilename}" + echo -e "* remotebuildurl: ${remotebuildurl}" + echo -e "* remotebuildversion: ${remotebuildversion}" + fi fi } @@ -156,13 +160,13 @@ fn_update_minecraft_compare() { remotelocation="mojang.com" if [ "${firstcommandname}" == "INSTALL" ]; then - fn_update_minecraft_remotebuild - fn_update_minecraft_dl + fn_update_remotebuild + fn_update_dl else fn_print_dots "Checking for update" fn_print_dots "Checking for update: ${remotelocation}" fn_script_log_info "Checking for update: ${remotelocation}" - fn_update_minecraft_localbuild - fn_update_minecraft_remotebuild - fn_update_minecraft_compare + fn_update_localbuild + fn_update_remotebuild + fn_update_compare fi diff --git a/lgsm/functions/update_minecraft_bedrock.sh b/lgsm/functions/update_minecraft_bedrock.sh index cdd0a01e4..481af0ab7 100644 --- a/lgsm/functions/update_minecraft_bedrock.sh +++ b/lgsm/functions/update_minecraft_bedrock.sh @@ -49,7 +49,7 @@ fn_update_minecraft_localbuild() { } fn_update_minecraft_remotebuild() { - # Gets remote build info. + # Get remote build info. if [ "${mcversion}" == "latest" ]; then remotebuild=$(curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -Ls -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.${randnum}.212 Safari/537.36" "https://www.minecraft.net/en-us/download/server/bedrock/" | grep -o 'https://minecraft.azureedge.net/bin-linux/[^"]*' | sed 's/.*\///' | grep -Eo "[.0-9]+[0-9]") else diff --git a/lgsm/functions/update_mta.sh b/lgsm/functions/update_mta.sh index 7d16a29f8..5252c1328 100644 --- a/lgsm/functions/update_mta.sh +++ b/lgsm/functions/update_mta.sh @@ -30,7 +30,7 @@ fn_update_localbuild() { } fn_update_remotebuild() { - # Gets remote build info. + # Get remote build info. apiurl="https://api.github.com/repos/multitheftauto/mtasa-blue/releases/latest" remotebuildresponse=$(curl -s "${apiurl}") remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("Linux-amd64")) | .name') diff --git a/lgsm/functions/update_papermc.sh b/lgsm/functions/update_papermc.sh index f4726c470..f48a66e39 100644 --- a/lgsm/functions/update_papermc.sh +++ b/lgsm/functions/update_papermc.sh @@ -8,11 +8,9 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" fn_update_dl() { - # Download and extract files to tmpdir. - fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}" - mv "${tmpdir}/${remotebuildfilename}" "${serverfiles}/${executable#./}" + # Download and extract files to serverfiles + fn_fetch_file "${remotebuildurl}" "" "" "" "${serverfiles}" "${executable#./}" "chmodx" "norun" "force" "${remotebuildhash}" echo "${remotebuildversion}" > "${serverfiles}/build.txt" - fn_clear_tmp } fn_update_localbuild() { @@ -32,7 +30,7 @@ fn_update_localbuild() { } fn_update_remotebuild() { - # Gets remote build info. + # Get remote build info. apiurl="https://papermc.io/api/v2/projects/" # Get list of projects. remotebuildresponse=$(curl -s "${apiurl}")