11@ echo off
22title Checking dependencies...
3- set scriptversion = 1.1 .0
3+ set scriptVersion = v1.2 .0
44
55REM Set restart counter variables
66set " restartCount = 0"
@@ -16,26 +16,43 @@ REM Check if script config file exists, if not, go to create it.
1616if not exist .\config\StartupScript.conf (
1717 goto initialSetup
1818) else (
19- goto initiateServer
19+ goto scriptUpdater
2020)
2121
22-
23-
24- :initiateServer
25- title Initiating server...
22+ :scriptUpdater
23+ title Checking for updates...
2624
2725REM Check for updates to this script.
2826for /f " delims=" %%a in ('powershell -Command " (Invoke-WebRequest -Uri 'https://api.github.com/repos/GarnServo/mc-startup-script/releases/latest').Content | ConvertFrom-Json | Select -ExpandProperty tag_name" ') do set latestVersion = %%a
2927echo Current script version: %scriptVersion%
3028echo Latest version from GitHub: %latestVersion%
3129REM Check if the script version is greater than the latest version
32- if " %latestVersion% " LSS " v %scriptVersion% " (
30+ if " %latestVersion% " LSS " %scriptVersion% " (
3331 echo You have the latest version of the script.
32+ goto initiateServer
3433) else (
35- echo An update is available for the script ^ (version " %latest_version% " ^ ). Please visit the GitHub page for more details:
36- echo https://github.com/GarnServo/mc-startup-script/releases/latest
34+ echo An update is available for the script ^ (version " %latestVersion% " ^ ).
35+ echo Do you want to update? (Y/N)
36+ choice /C YN /M " Update script (Y/N): "
37+ if errorlevel 2 goto initiateServer
38+ if errorlevel 1 (
39+ echo @echo off > UpdateStartupScript.bat
40+ echo title Updating startup script... > UpdateStartupScript.bat
41+ echo powershell -Command " (Invoke-WebRequest -Uri 'https://github.com/GarnServo/mc-startup-script/releases/latest/download/START.bat' -OutFile 'START.bat')" >> UpdateStartupScript.bat
42+ echo start START.bat >> UpdateStartupScript.bat
43+ echo exit >> UpdateStartupScript.bat
44+ start UpdateStartupScript.bat
45+ exit
46+ )
3747)
3848
49+
50+
51+ :initiateServer
52+ title Initiating server...
53+ REM Cleanup updater
54+ if exist UpdateStartupScript.bat del UpdateStartupScript.bat
55+
3956REM Check EULA exists, if not, go to create it (and accept it)
4057if not exist " eula.txt" (
4158 goto eula
@@ -90,7 +107,7 @@ set /A restartCount+=1
90107set " restartTime = %TIME% , %DATE% "
91108echo Server has closed or crashed...restarting now...
92109echo Server has restarted %restartCount% times. Last restart: %restartTime%
93- goto initiateServer
110+ goto scriptUpdater
94111
95112:runNoRestart
96113title %Title%
99116echo .
100117echo Server has closed or crashed.
101118CHOICE /N /C YN /M " Do you want to restart the server? (Y/N): "
102- if %errorlevel% == 1 goto initiateServer
119+ if %errorlevel% == 1 goto scriptUpdater
103120if %errorlevel% == 2 (
104121 echo You chose not to restart the server.
105122 echo Press any key to exit.
@@ -235,4 +252,4 @@ echo #Auto-accepted EULA with startup script made by Garn Servo. >> eula.txt
235252echo eula=true>> eula.txt
236253echo [32mEULA created and accepted.[0m
237254cls
238- goto initiateServer
255+ goto scriptUpdater
0 commit comments