Skip to content

Commit 2b4ce12

Browse files
committed
🆕 Added an auto-updater for this script
1 parent c8382b5 commit 2b4ce12

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

START.bat

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@echo off
22
title Checking dependencies...
3-
set scriptversion=1.1.0
3+
set scriptVersion=v1.2.0
44

55
REM Set restart counter variables
66
set "restartCount=0"
@@ -16,26 +16,43 @@ REM Check if script config file exists, if not, go to create it.
1616
if 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

2725
REM Check for updates to this script.
2826
for /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
2927
echo Current script version: %scriptVersion%
3028
echo Latest version from GitHub: %latestVersion%
3129
REM 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+
3956
REM Check EULA exists, if not, go to create it (and accept it)
4057
if not exist "eula.txt" (
4158
goto eula
@@ -90,7 +107,7 @@ set /A restartCount+=1
90107
set "restartTime=%TIME%, %DATE%"
91108
echo Server has closed or crashed...restarting now...
92109
echo Server has restarted %restartCount% times. Last restart: %restartTime%
93-
goto initiateServer
110+
goto scriptUpdater
94111

95112
:runNoRestart
96113
title %Title%
@@ -99,7 +116,7 @@ echo.
99116
echo.
100117
echo Server has closed or crashed.
101118
CHOICE /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
103120
if %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
235252
echo eula=true>> eula.txt
236253
echo EULA created and accepted.
237254
cls
238-
goto initiateServer
255+
goto scriptUpdater

0 commit comments

Comments
 (0)