Browse Source

mcb

pull/4146/head
Daniel Gibbs 3 years ago
parent
commit
f4f3f8d62a
  1. 2
      lgsm/functions/update_minecraft.sh
  2. 95
      lgsm/functions/update_minecraft_bedrock.sh

2
lgsm/functions/update_minecraft.sh

@ -3,7 +3,7 @@
# Author: Daniel Gibbs
# Contributors: http://linuxgsm.com/contrib
# Website: https://linuxgsm.com
# Description: Handles updating of Minecraft servers.
# Description: Handles updating of Minecraft: Java Edition servers.
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

95
lgsm/functions/update_minecraft_bedrock.sh

@ -10,29 +10,30 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
#random number for userAgent
randnum=$((1 + RANDOM % 5000))
fn_update_minecraft_dl() {
fn_fetch_file "https://minecraft.azureedge.net/bin-linux/bedrock-server-${remotebuild}.zip" "" "" "" "${tmpdir}" "bedrock_server.${remotebuild}.zip"
fn_update_dl() {
fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "bedrock_server.${remotebuildversion}.zip"
echo -e "Extracting to ${serverfiles}...\c"
if [ "${firstcommandname}" == "INSTALL" ]; then
unzip -oq "${tmpdir}/bedrock_server.${remotebuild}.zip" -x "server.properties" -d "${serverfiles}"
unzip -oq "${tmpdir}/bedrock_server.${remotebuildversion}.zip" -x "server.properties" -d "${serverfiles}"
else
unzip -oq "${tmpdir}/bedrock_server.${remotebuild}.zip" -x "permissions.json" "server.properties" "allowlist.json" -d "${serverfiles}"
unzip -oq "${tmpdir}/bedrock_server.${remotebuildversion}.zip" -x "permissions.json" "server.properties" "allowlist.json" -d "${serverfiles}"
fi
local exitcode=$?
if [ "${exitcode}" == "0" ]; then
fn_print_ok_eol_nl
fn_script_log_pass "Extracting to ${serverfiles}"
chmod u+x "${serverfiles}/bedrock_server"
fn_clear_tmp
else
if [ "${exitcode}" != 0 ]; then
fn_print_fail_eol_nl
fn_script_log_fatal "Extracting to ${serverfiles}"
fn_clear_tmp
fn_script_log_fatal "Extracting ${local_filename}"
if [ -f "${lgsmlog}" ]; then
echo -e "${extractcmd}" >> "${lgsmlog}"
fi
echo -e "${extractcmd}"
core_exit.sh
else
fn_print_ok_eol_nl
fn_script_log_pass "Extracting ${local_filename}"
fi
}
fn_update_minecraft_localbuild() {
fn_update_localbuild() {
# Gets local build info.
fn_print_dots "Checking local build: ${remotelocation}"
# Uses log file to get local build.
@ -48,18 +49,19 @@ fn_update_minecraft_localbuild() {
fi
}
fn_update_minecraft_remotebuild() {
fn_update_remotebuild() {
# 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]")
remotebuildversion=$(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
remotebuild="${mcversion}"
remotebuildversion="${mcversion}"
fi
remotebuildurl="https://minecraft.azureedge.net/bin-linux/bedrock-server-${remotebuildversion}.zip"
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
@ -69,7 +71,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
@ -77,27 +79,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
@ -114,7 +128,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
@ -131,11 +145,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
}
@ -143,13 +170,13 @@ fn_update_minecraft_compare() {
remotelocation="minecraft.net"
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

Loading…
Cancel
Save