Created
August 6, 2023 16:13
-
-
Save thelabcorner/53e968ab9945956088bb90e2d0c3b96c to your computer and use it in GitHub Desktop.
An automatic server updater that I wrote because I got tired of updating paper all the time. There's other ones out there. I really just wanted to test my abilities and mess around with a different language than the norm. Meant for Windows. JVM Args are hardcoded; modify them as you need. Depends on JQ [https://jqlang.github.io/jq/download/] Unl…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
cls | |
echo. | |
echo. | |
echo ----------------------------------------------------------------------------------------------- | |
echo - | |
echo - | |
echo - - THEDABCORNER - PAPER AUTO UPDATER SCRIPT | |
echo - ------------------------------------------ | |
echo - | |
echo - - This script will keep your server running in the event of a crash or restart, as well | |
echo - as it will automatically update the paper.jar if it is out-of-date. | |
echo - | |
echo - https://github.com/thelabcorner | |
echo ----------------------------------------------------------------------------------------------- | |
echo. | |
:: Use this to change the paper server version branch you want to use | |
set VERSION_BRANCH=1.20.1 | |
:: Use this to change the window title | |
title Development Server - WatchDog - %VERSION_BRANCH% | |
:: Begin Loop for Checking Version & Updating | |
:loop | |
:: Fetching the latest build number using the API | |
echo. | |
echo Fetching the latest build number... from API: https://api.papermc.io/v2/projects/paper/versions/%VERSION_BRANCH%/builds | |
echo. | |
for /f %%i in ('curl -s "https://api.papermc.io/v2/projects/paper/versions/1.20.1/builds" ^| jq ".builds[-1].build"') do set LATEST_BUILD=%%i | |
:: Check if build number was fetched | |
if "%LATEST_BUILD%"=="" ( | |
echo. | |
echo Failed to fetch the latest build number. Exiting... | |
echo. | |
exit /b | |
) | |
echo. | |
echo Latest build number is: %LATEST_BUILD% | |
echo. | |
:: Constructing the download URL and filename | |
set DOWNLOAD_URL=https://api.papermc.io/v2/projects/paper/versions/%VERSION_BRANCH%/builds/%LATEST_BUILD%/downloads/paper-%VERSION_BRANCH%-%LATEST_BUILD%.jar | |
set JAR_FILE=paper-%VERSION_BRANCH%-%LATEST_BUILD%.jar | |
:: Check if the jarBackups folder exists. If not, create it | |
if not exist jarBackups mkdir jarBackups | |
:: If the new JAR version doesn't exist, then we might need to move the old version and download the new one | |
if not exist "%JAR_FILE%" ( | |
:: Move any existing paper-1.20.1-*.jar files to the jarBackups folder | |
move paper-%VERSION_BRANCH%-*.jar jarBackups >nul 2>&1 | |
echo New version detected! Downloading... | |
curl -s -X GET -o "%JAR_FILE%" "%DOWNLOAD_URL%" | |
if not exist "%JAR_FILE%" ( | |
echo. | |
echo Failed to download the latest paper.jar. Exiting task... | |
echo. | |
exit /b | |
) | |
echo Downloaded %JAR_FILE% successfully! | |
) else ( | |
echo. | |
echo No new version detected! | |
echo Using existing JAR: %JAR_FILE% | |
echo. | |
) | |
echo. | |
echo Starting Server with %JAR_FILE%... | |
echo. | |
echo. | |
echo ----------------------------------------------------------------------------------------------- | |
echo. | |
java -Xmx10G -jar "%JAR_FILE%" -nogui -o true | |
echo (%time%) Server closed/crashed... restarting! | |
echo Waiting 1 seconds before restarting... | |
ping -n 1 127.0.0.1 > nul | |
goto loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment